This set of MCQ(multiple choice questions) focuses on the An Introduction to Programming Through C++ NPTEL 2022 Week 8 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 8 Assignment Answers” contains 12 questions.
Now, start attempting the quiz.
An Introduction to Programming Through C++ NPTEL 2022 Week 8 Assignment Answers
Consider the following code. Assume the user types “abc” without the quotes as the input.
char buffer[8];
cin >> buffer;
cout << buffer[2]; // A
cout << buffer[6]; // B
Q1. What will get printed due to the line labeled A above?
a) The letter ‘a’
b) The letter ‘b’
c) The letter ‘c’
d) It is not possible to predict what will be printed
Answer: c)
Q2. What will get printed due to the line labeled B above?
a) The letter ‘a’
b) The letter ‘b’
c) The letter ‘c’
d) It is not possible to predict what will be printed
Answer: d)
Q3. In the same code, suppose the user typed “abcdefghijkl”. Which of the following are true?
a) C++ will change the array size so that what the user types will be accommodated.
b) What the user types will potentially be stored in regions of memory not allocated for the variable buffer.
c) There is a different way in C++ to read data into char arrays so that no other variables get affected.
Answer: b), c)
Consider the following programint
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 National Education Policy
Q4. What will the value of argc be?
Answer: 4
Q5. What will the value of argv[2][2] be? Write without placing quotes etc.
Answer: u
Q6. Suppose the binary search function BSearch is called using an array of size 128. How many calls will there be including the initital?
Answer: 8
Consider the following code fragment.
int S={5,4,3,2,1};
mergesort(S,5);
Answer the following questions about the execution of the top level call.
Q7. What will be the size of the array U declared in it?
Answer: 2
Q8. After mergesort has been called on U, V, what will V[0] equal?
Answer: 1
Q9. Select the correct statements among those given below. Assume that the sequence considered for sorting contains distinct elements.
a) During the execution of mergesort, the smallest element will always be compared with the second smallest.
b) During the execution of mergesort, the smallest element will always be compared with the third smallest.
c) During the execution of selectionsort, the smallest element will always be compared with the second smallest.
d) During the execution of selectionsort, the smallest element will always be compared with the third smallest.
Answer: a)
Q10. Consider the merge function called to merge two sorted sequences of lengths m, n respectively. Suppose m < n. What is the minimum number of comparisons (between the elements of the sorted sequence)that the merge function must perform, no matter what the values of the elements?
a) m
b) n
c) m+n
d) None of the above
Answer: a)
Q11. What is L?
Answer: 16
Q12. Which will the first line print?
a) Nothing
b) 1
c) 4
d) 7
e) 9
f) 1 4 7 9
Answer: a)
Q13. What will the last line print?
a) Nothing
b) 1
c) 4
d) 7
e) 9
f) 1 4 7 9
Answer: f)
An Introduction to Programming Through C++ NPTEL Week 8 Programming Assignment Answers
Programming Assignment 8.1
Write a program which takes the following as input: an integer N, an integer A, a sequence of N words which should be names of countries, a sequence of A words each of which is an attribute of a country (e.g. population, area, GDP), followed by a sequence of N*A real numbers (use double) where the iA+j th number gives the value of the jth attribute of the ith country, where 0<=j<A, 0<=i<N, followed by a sequence of pairs of words. The first word in each pair must be the name of a country, and the second an attribute. The program must then print the respective attribute of the respective country (e.g. population of India, GDP of China).
CODE:
#include<iostream>
using namespace std;
int main() {
int n,a;
cin>>n>>a;
string country[n];
for(int i=0; i<n; i++) {
cin>>country[i];
}
string str[a];
for(int i=0; i<a; i++) {
cin>>str[i];
}
int b = n*a;
float valArray[b];
for(int i=0; i<b; i++) {
cin>>valArray[i];
}
float res[20];
int count = 0;
while(!cin.eof()) {
string cntr, attr;
cin>>cntr;
cin>>attr;
int ind = 0;
while(ind<n) {
if(country[ind]==cntr)
break;
ind++;
}
int strInd = 0;
while(strInd<n) {
if(str[strInd]==attr)
break;
strInd++;
}
float result = valArray[(3*ind)+strInd];
res[count] = result;
count++;
}
for(int i=0; i<count-1; i++) {
cout<<res[i]<<endl;
}
return 0;
}
Programming Assignment 8.2
You are to write a function makeT that takes as input a set S of integers, and a target value T, and determines if any subset of the numbers in Sadds up to T. The function should be a modification of the function given in the quiz for printing all subsets of a set. The function should have thefollowing signature:
bool makeT(int S[], bool selected[], int i, int n, int T);
It should return true if any subset of the elements of S add up to T, when called as makeT(S, selected, 0, n,T), and false otherwise.
CODE:
bool makeT(int S[], bool selected[], int i, int n, int T) {
if(T==0)
return true;
if(n<0)
return false;
bool include = makeT(S, selected, i, n-1, T-S[n]);
bool exclude = makeT(S, selected, i, n-1, T);
return include || exclude;
}
<< Prev- An Introduction to Programming Through C++ Week 7 Solutions
>> Next- An Introduction to Programming Through C++ Week 9 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.
sir we also need week-8 programming assignment answers of an introduction to c++
I have just uploaded programming assignment. Check it out now.