Are you looking for some help in nptel an introduction to programming through C++ assignment 6 answers? So, in this article, we have provided you hint of both quiz and programming questions.

Table of Contents

## NPTEL An Introduction To Programming Through C++ Assignment 6 Answers (Week 6)

**Q1. What is V(6), the number of poetic meters of total duration 6?**

**Answer:** 13

**Follow Sikshapath’s Telegram Channel for instant notifications of further updates.**

Suppose I have a supply of red blocks (R) all of height 1 and blue blocks (B) all of height 3. I can stack the blocks one above the other to build a tower. For example, if I stack in the order RBR or BRR from bottom to top I will get towers of height 5. Let T(n) denote the number of towers possible of height n. Clearly T(1) is 1 because the only order possible is R.T(2) is 1 because the only possible order is RR.T(3) is 2, because the possible orders are RRR or B.

BR RB RRRR

**Q2. What is T(4)?**

**Answer:** 3

**Q3. What is T(5)?**

**Answer:** 4

**Q4.** **Using the same logic as in the lecture, you could say that the bottom most block can either be red or it can be blue. Following this logic, what is T(n) equal to?**

a. T(n-1) + T(n-2)

b. T(n-1) + T(n-2) + T(n-3)

c. T(n-1) + T(n-3)

d. T(n-2) + T(n-3)

**Answer:** c. T(n-1) + T(n-3)

**Q5. What does the call f(100) return, if f is defined as follows?**

**Int f(n){if (n == 0) return 0;else return f(n–1) + 2;}**

**Answer:** 200

Answer True or False for each of the questions below based on the files mentioned in your assignment.

**Q6. I will get an error if I execute s++ f1.cpp**

a. True

b. False

**Answer:** a. True

**Q7. I will get an error if I execute s++ -c f2.cpp**

a. True

b. False

**Answer:** b. False

**Q8. I will get an error if I execute s++ f1.cpp f3.cpp**

a. True

b. False

**Answer:** a. True

**Q9. What is the result of executing the following program, if the input given is 3?**

```
#include <simplecpp>
#include <functional>
double ssum(function<double(int)> f, int n){
double sum = 0;
for(int i=0; i<n; i++)
sum=sum+f(i);
return sum;
}
int main(){
int n; cin >> n;
cout << ssum([](int i){return i*i;}, n)<<endl;
}
```

**Answer:** 5

Consider the following program.

#include<simplecpp>

int f(int a, int b, int c=10, int d=20){return a+b+c+d;}

int main(){

cout<<f(5,6,7,8)<<‘,'<<f(5,6,7)<<‘,'<<f(5,6);

}

**Q10. What is the first number printed?**

**Answer:** 26

**Q11. What is the second number printed?**

**Answer:** 38

**Q12. What is the third number printed?**

**Answer:** 41

### NPTEL An Introduction To Programming Through C++ Assignment 6 Programming Answers

**Q1. Suppose there are two types of blocks: Red blocks (R) of height 1 and Blue blocks (B) of height 4. These blocks can be stacked one above the other to build a tower. You have to write a program that counts the number of distinct towers of a given height n that can be built using these 2 types of blocks.**

**Note:** 2 towers of the same height are called distinct if the order in which R and B blocks occur in them is different.

Write a recursive program that takes n and returns the number of distinct towers of height n.

Code:

```
long int tower_count (int x) {
if(x <= 3)
return 1;
return tower_count(x-4) + tower_count(x-1);
}
main_program {
int n;
cin >> n;
cout << tower_count(n) << endl;
}
```

**Q2. Given below is a main program with calls to a function inches. Given a distance measured in yards, feet and inches, the function is supposed to return the equivalent number of inches. In particular, given y, f, i as the values of the parameters yards, feet, inches, the function should returny36+f12+i. However, it is acceptable to call the function with just two arguments y, f, in which case they should be interpreted as yards and feet, and the value returned should be y36+f12. The function might also be called with a single argument y, in which case it should return y*36. You have to write the code for the function inches. Your code may implement inches using default values for the parameters or by overloading it. You do not need to give the main program. It will be added automatically. The main program is given below for your reference.**

**Note:** You don’t need to write/copy the main program. You just need to write the inches function, without the main_program or any of the header files. Ensure that the function is correctly named as inches.

main_program{

int y,f,i; cin >> y >> f >> i;

cout << inches(y,f,i) <<“,”<<inches(y,f) <<“,”<<inches(y) << endl;

}

Code:

```
int inches(int y, int f = 0, int i = 0) {
int inch;
inch = y * 36 + f * 12 + i;
return inch;
}
```

**Disclaimer:** These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.

**Also Available:**

Joy of Computing Using Python NPTEL Assignment Answers Week 6

An Introduction to Programming through C++ Week 7 NPTEL Assignment Answers