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

  

               An Introduction To Programming Through C++


IIT Bombay.

Week 8- QUIZ ASSIGNMENT:

1)Consider the following code.
char buffer[80];
cin >> buffer;
cout << buffer;
Assume the user types "Sachin Tendulkar" without the quotes as the input. What will be printed?
Ans: Sachin

2)Consider the following code.
char buffer[80];
cin.getline (buffer,80);
cout << buffer;
Assume the user types "Sachin Tendulkar" without the quotes as the input. What will be printed?
Ans: Sachin Tendulkar

Consider the following program
int main(int argc, char *argv[]){
for (int i=0; i<argc; i++)
   cout << argv[i] << endl;
}
Suppose it is invoked from the command line as:
./a.out On Education

3)What will the value of 'argc' be?
Ans: 7

4)What will the value of 'argv[1][1]' be?  Write without placing quotes etc. Do not write additional spaces in the answer.
Ans:

Given below is the code for binary search from the lecture, with small modifications; a couple of original lines are commented out & new lines have been added in their place".
//bool Bsearch(int A[], int S, int L, int x){
int Bsearch(int A[], int S, int L, int x){
//  if(L == 1) return A[S] == x;
  if(L == 1) return S;
  int H = L/2;
  if(x < A[S+H])
    return Bsearch(A, S,   H,   x);
  else
    return Bsearch(A, S+H, L-H, x);
}

5)Suppose we do binary search (as in the lecture) on an array of size 100000. The number of array elements that x will be compared with will be about
 10
 17
 20
 1000000

6)Tn=2Tn/2+nandT1=0.WhatisthevalueofT64?
Ans: 384

7)The function merge discussed in the lecture does 2 kinds of comparison: inter key (i.e. between U[uf] and V[vf]) and inter indices (i.e. between uf,vf,Lu,Lv). For which of the cases below will the number of inter key comparisons be largest?
 U={1,2,3}, V={4,5,6}
 U={1,5,6}, V={2,3,4}
 U={1,3,6}, V={2,4,5}
 U={1,2,5}, V={3,4,6}

A two dimensional array is useful for storing image.  If we have a black and white image with m rows each having n pixels, this is easily represented using a bool array A[m][n], where true indicates black colour and false indicates white. The following code counts the number of vertical lines in a picture. A vertical line is a
contiguous sequence of black pixels, one below the other, of any positive length, terminated on either end by a white pixel or by the end of the picture. A vertical line can even be just one pixel in length.
  int found=0;
  for(int i=0; i<m; i++)
    for(int j=0; j<n; j++)
      //beginning of inner iteration
      if(A[i][j]){
        found++;
        for(int k=i; k<m; k++){
          if(A[k][j]) A[k][j] = false;
          else break;
        }
      }
  cout << found << endl;

8)Suppose that originally the image A contained 5 vertical lines. Consider the point in time when control reaches the beginning of the inner iteration, and i=25, j=16, and found = 2. 

Which of the following is true?
 A[10][40] must be false.   (not confirm)
 A[10][40] must be true.
 A[10][40] may be true or false, we do not know which based on what is given.

9)Which of the following is true?
 A[25][40] must be false.
 A[25][40] must be true.
 A[25][40] may be true or false, we do not know which based on what is given.  (not confirm)

10)How many vertical lines will be present in the image at this point?
Ans: 2

WEEK-8 :PROGRAMMING ASSIGNMENT 1 AND 2 CLICK ON BELOW LINK.
<<CLICK HERE FOR  WEEK 8:PROGRAMMING -01>>
<<CLICK HERE FOR  WEEK 8: 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.

2 comments:

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages