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

       

               An Introduction To Programming Through C++


IIT Bombay.
Week 3 Quiz:

YOU CAN SEE THIS VIDEO:

--------------------------------------------------------------------------------------------------------------------------
A manufacturer sells an item for Rs. 100 each.  For the first 100
items there is no discount.  If you order between 101 and 200 items
there is a 10 % discount on each item other than the first 100. If you
order more than 200 items, then for the first 100 there is no
discount; for the next 100 there is a 10 % discount, and for each item
above 200 there is a 20 % discount. Thus if you order 30, the cost is
Rs 3000. If you order 130, the cost is Rs. 12700. If you order 230,
then the cost is Rs. 10000+9000+2400 = 21400. The following program
fragment is supposed to calculates the cost.

int quantity; cin >> quantity;
int cost = 0; // newly added
if(quantity <= 100) cost = blankA1 + quantity * blankA2;
else if(quantity <= 200) cost = blankB1 + quantity * blankB2;
else cost = blankC1 + quantity * blankC2;
cout << cost;

In the above, all the blanks are to be filled using just numbers (no
expressions or variables allowed).  Also, if multiple values are asked
give them comma separated. Do not use any spaces or tabs.

1.What is the value of blankA1?
Ans:

2.What is the value of blankA2?
Ans:

3.What is the value of blankB1?
Ans:

4.What is the value of blankB2?
Ans:

5.What is the value of blankC1?
Ans:

6.What is the value of blankC2?
Ans:
--------------------------------------------------------------------------------------------------------------------------
The following program fragment is supposed to count the number of 'a's
read until the character '.' is encountered. For example, if the input
is "kangaroos are fantastic.", the output should be 5.

int aCount=0;
while(true){
  char c; cin >> c;
  if(blankD) blankE = blankF;
}
cout << aCount << endl;

Do not use any spaces in the answers to the following questions,
i.e. if you want to write p+q, do not put spaces before or after the
+.

7.What is the value of blankD?
a) c==1
b) c=='a'
c) c<5
d) 'a'==c
Ans:

8.What is the value of blankE? Do not specify spaces or tabs while writing the answer
Ans:

9.What is the value of blankF? Choose all the answers that you think are correct.
a) aCount+1
b) aCount--
c) 1+aCount
d) aCount-'a'
--------------------------------------------------------------------------------------------------------------------------
10.The following program is a slight modification of the first program we saw for determining whether a number is prime.

main_program{
  int n, divisor=2; cin >> n;
  bool divisorFound = false;
  repeat(n-2){
    if(n % divisor == 0){
      divisorFound = true;
      blankJ;
    }
    divisor = divisor + 1;
  }
  if(!divisorFound) cout <<"Prime.\n";
  else cout <<"Composite.\n";
}

What should blankJ be replaced by so that this program will correctly determine whether n is prime?
Ans:
--------------------------------------------------------------------------------------------------------------------------
11.What does the following program print?

int n=235;
for( ; n>0; n = n/10)
  cout << n % 10 << endl;
}

Give the values printed, separated by commas. Do not give any spaces or tabs.
Ans:
--------------------------------------------------------------------------------------------------------------------------
12.If the program in the previous question is modified to read 'n' from keyboard
(instead of assigning a constant inside the program). In general, what does such
a modified program print?


a)The program prints digits of n, from the most significant to least significant, for all positive integers n.

b)The program prints digits of n, from the least significant to most significant, for all positive integers n.

c)The program prints digits of n, from the most significant to least significant, for all non-negative integers n.
d)The program prints digits of n, from the least significant to most significant, for all non-negative integers n.
--------------------------------------------------------------------------------------------------------------------------
13.What will the following program fragment print?
int d = 0;
for(int i=1; i<100; i=i*2) d = d + i;
cout << d;
Ans:

SOON THERE WILL BE ANSWERS  OR YOU CAN COMMENT.

WEEK :3 PROGRAMMING ASSIGNMENT 1 SOLUTION
CLICK ON BELOW LINK.
<<CLICK HERE FOR PROGRAMMING ASSIGNMENT  1 WEEK 3>>
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