Week:5 Quiz Answers(Jan 2020-Apr2020) An Introduction to Programming through C++ NPTEL 2020

  

               An Introduction To Programming Through C++


IIT Bombay.





Week 5- QUIZ ASSIGNMENT:


-------------------------------------------------------------------------------------------------------------------------
1.Which of the following is true?
 a)The terms "argument" and "parameter" mean the same thing in the context of functions.
 b)"Argument" denotes the value passed to a function whereas "parameter" denotes the name by     which the value is referred to in the body of the function.
 c)"Parameter" denotes the value passed to a function whereas "argument" denotes the name by which the value is referred to in the body of the function.
 d)"Argument" and "parameter" are completely unrelated.
-------------------------------------------------------------------------------------------------------------------------
The "signature" of a function is the first line which gives the return type, the name of the function and the parameters with their types.  Thus the signature of the gcd function is

int gcd(int m, int n)


You are given a function whose signature is as follows

void multiprint(char c, int count)

You are told that the function will print count copies of the character c.

The following figure is printed by the code below it

*********
*********
*********
   ***
   ***
   ***

repeat(3){
  multiprint(blankE,blankF); cout << endl;
}
repeat(3){
  multiprint(blankG,blankH);
  multiprint(blankI,blankJ); cout << endl;
}

2.What is the value of blankE?
Ans:'*'

3.What is the value of blankF?
Ans:9

4.What is the value of blankG?
Ans:" "

5.What is the value of blankH?
Ans:3

6.What is the value of blankI?
Ans:'*'

7.What is the value of blankJ?
Ans:3
-------------------------------------------------------------------------------------------------------------------------
Given below is a partial implementation of multiprint.  It is based on the idea that printing something n times is the same as printing it once and then printing it n-1 times.

void multiprint(char c, count n){
  if(n == blanka) return;
  else{
    cout << c;
    multiprint(blankb, blankc);
  }
}

Answer the following questions regarding the contents of the blanks.  Do not put any spaces in your solutions.

8.What is blanka?
Ans:0

9.What is blankb?
Ans:'c'

10.What is blankc?
Ans:n-1
-------------------------------------------------------------------------------------------------------------------------
Four numbers are printed when the following program executes.

int f(int a, int &b, int *c){
  a = a*2; b=b+10; (*c)++;
  return a+b+*c;
}

main_program{
  int a=1,b=3,c=8;
  cout <<f(b,a,&c)<<' ';
  cout <<a<<' '<<b<<' '<<c<<endl;
}

11.What is the first number printed?
Ans:26

12.What is the second number printed?
Ans:11

13.What is the third number printed?
Ans:3

14.What is the fourth number printed?
Ans:9

15.The function below replaces the argument with its square.

void square(double *x){
blankK
return;
}
 a)x = x*x;
 b)x = *x * x;
 c)*x = *x * *x;
 d)*x = x*x;
-------------------------------------------------------------------------------------------------------------------------
As discussed in the lectures, when recursive gcd is called as gcd(205,123), the maximum number of activation frames present at any time is 4.

16.What is the maximum number of activation frames that might be present for the call f(3,5), where f is defined as follows?  (Include the activation from the main_program in both cases in the count).

int f(int a, int b){
  if(b == 0) return a;
  else return f(a+1,b-1);
}
Ans:7

17.What does the call f(3,5) return?
Ans:8

18.What will happen as a result of the call f(10,-20)?
 a)-10 will be returned.
 b)10 will be returned.
 c)There will be a compiler error.
 d)The recursion in the program will not terminate.

19.What will the following program do?

void S(int s, int n){
  if(s == n) return;
  forward(s*10);
  right(90);
  S(s+1,n);
}

main_program{

  turtleSim();
  S(1,15);
  getClick();

}

 a)It will draw a single straight line of length 10+20+...140.
 b)It will draw a single straight line of length 10+20+...150.
 c)It will draw a sequence of straight lines of length 10,20,...,140.
 d)It will draw a sequence of straight lines of length 10,20,...,150.

Consider the function below

int f(int n){  // Precondition n >= 0, n is even.
               // f(n) should return n
  if(n == 0) return 0;
  else return 2 + f(n-2);
}

We had given a checklist to decide if a recursive function is correct.  State whether each of the following criteria in the checklist is true or false.

20.The function has one or more base cases.
Ans:True

21.The level 1 recursive calls satisfy the preconditions.
Ans:True

22.The problem size, n, reduces in each call but cannot reduce indefinitely.
Ans:True

23.The correct answer is returned if level 1 calls return the correct answer.
Ans:True

Consider the problem in the previous question on recursion. However, now we are dropping the precondition "n is even". For recursion, we had given a checklist to decide if a recursive function is correct.  State whether each of the following criteria in the checklist is true or false.

Now specify ALL the critera (a) through (d) of the previous question here

24)The function has one or more base cases.
 Ans:False

25)The level 1 recursive calls satisfy the preconditions.
 Ans:True

26)The problem size, n, reduces in each call but cannot reduce indefinitely.
 Ans:True

27)The correct answer is returned if level 1 calls return the correct answer.
 Ans:False
WEEK-5 :PROGRAMMING ASSIGNMENT 2  AND QUIZ 5
CLICK ON BELOW LINK.
<<CLICK HERE FOR  WEEK 5:PROGRAMMING -01>>

<<CLICK HERE FOR  WEEK 5: 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.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages