This set of MCQ(multiple choice questions) focuses on the An Introduction to Programming Through C++ NPTEL 2022 Week 6 Answers.
Course layout
Answers COMING SOON! Kindly Wait!
Week 0: Assignment answers
Week 1: Introduction to computers using graphics.
Programming Assignment
Week 2: Basic data types.
Programming Assignment
Week 3: Statements of C++ for conditional execution and looping.
Programming Assignment
Week 4: Statements of C++ for conditional execution and looping.
Programming Assignment
Week 5:Â Functions.
Programming Assignment
Week 6: Recursive algorithms and recursive drawings.
Programming Assignment
Week 7:Â Arrays.
Programming Assignment
Week 8:Â Multidimensional arrays.
Programming Assignment
Week 9:Â Structures. Pointers with structures.
Programming Assignment
Week 10:Â Dynamic memory allocation.
Week 11: Use of the standard library in designing programs.
NOTE: You can check your answer immediately by clicking show answer button. An Introduction to Programming Through C++ NPTEL 2022 Week 6 Assignment Answers” contains 12 questions.
Now, start attempting the quiz.
An Introduction to Programming Through C++ NPTEL 2022 Week 6 Assignment Answers
Q1. What is V(6), the number of poetic meters of total duration 6?
Answer: 13
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
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?
Answer: 5
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
An Introduction to Programming Through C++ NPTEL Week 6 Programming Assignment Answers
Programming Assignment 6.1
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;
}
Programming Assignment 6.2
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 toreturn the equivalent number of inches. In particular, given y, f, i as the values of the parameters yards, feet, inches, the function should returny*36+f*12+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 y*36+f*12. The function might also be called with a single argument y, in which case it should return y*36. Youhave to write the code for the function inches. Your code may implement inches using default values for the parameters or by overloading it. Youdo 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 theheader 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;
}
<< Prev- An Introduction to Programming Through C++ Week 5 Solutions
>> Next- An Introduction to Programming Through C++ Week 7 Solutions
DISCLAIMER: Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.
For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.