You must login to ask a question.

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

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.

## 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?

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)?

Q3. What is T(5)?

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(n1) + 2;
}

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

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

a. True
b. False

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

a. True
b. False

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;
}

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?

Q11. What is the second number printed?

Q12. What is the third number printed?

### 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;
}

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