An Introduction To Programming Through C++
IIT Bombay.
Week 6- QUIZ ASSIGNMENT:
Ans: 13
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Suppose I have a red block (R) of height 1, a blue block (B) of height 2, and a green block (G) of height 3. I can stack the blocks one above the other to build a tower. For example, I can stack in the order RBG and I would get a tower of height 6. I wish to compute how many different towers of a given height n can be built if you are given ample blocks of each color.
Let T(n) denote the number of towers of height n.
2)What is T(1)?
Ans: 1
3)What is T(2)?
Ans: 2
3)What is T(3)?
Ans: 4
Suppose n > 3. What is the number of ways in which I can build a tower of height n such that the bottom block is red? An expression involving T(...), n, and integers is expected, to be written without any blanks.
Suppose n > 3. What is the number of ways in which I can build a tower of height n such that the bottom block is blue? An expression involving T(...), n, and integers is expected, to be written without any blanks.
Suppose n > 3. What is the number of ways in which I can build a tower of height n such that the bottom block is green? An expression involving T(...), n, and integers is expected, to be written without any blanks.
-------------------------------------------------------------------------------------------------------------------------------------------------------------
8)Suppose I want to write a function drawV which draws the recursion tree and also recursively calculates the Dth Virahanka number V(D). Which of the following do you think can possibly be its signatures? There may be more than one correct answer.
void drawV(int D, double rx, double ry, double W, double H);
int drawV(int D, double rx, double ry, double W, double H);
void drawV(int D, double rx, double ry, double W, double H, int returnval);
void drawV(int D, double rx, double ry, double W, double H, int &returnval);
-------------------------------------------------------------------------------------------------------------------------------------------------------------
9)The contents of some files are given below.
//File f1.cpp
int main(){}
//File f2.cpp
int main(){ f(10); }
//File f3.cpp
void f(int);
int main(){ f(10); }
//File f4.cpp
void f(int x){return;}
The following questions are about compiling these files. Note first that in every file every function being called must be declared before the call. Second, if you are compiling a set of files that do not together contain every function referred to in them, then the compilation can only produce object modules, and for this the -c option must be used.
For which of the following will I get an error message?
s++ f1.cpp
s++ f2.cpp
s++ -c f2.cpp
s++ -c f3.cpp
s++ f2.cpp f4.cpp
s++ f3.cpp f4.cpp
-------------------------------------------------------------------------------------------------------------------------------------------------------------
10)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*i;}, n)<<endl;
}
Ans: 36
-------------------------------------------------------------------------------------------------------------------------------------------------------------
11)What value is printed when the following executes?
cout << [](double x, double y){return sqrt(x*x + y*y);}(3,4)<<endl;
Ans: 5
-------------------------------------------------------------------------------------------------------------------------------------------------------------
12)What will be printed by the following program?
#include <simplecpp>
int f(int a, int b, int c=1, int d=2){return a+b+c+d;}
int main(){
cout<<f(5,6,7,8)<<' '<<f(5,6,7)<<' '<<f(5,6);
}
Write numbers separated with single space without any leading or trailing space.
Ans: 26,20,14
CLICK ON BELOW LINK.
<<CLICK HERE FOR WEEK6:PROGRAMMING -01>>
<<CLICK HERE FOR WEEK 6: PROGRAMMING-02>> FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
No comments:
Post a Comment
If you have any problems related to solutions or any concept please let me know.