This set of MCQ(multiple choice questions) focuses on the Programming in Modern C++ NPTEL 2023 Week 1 Assignment Solutions.
Programming in C++ is so fundamental that all companies dealing with systems as well as application development (including web, IoT, embedded systems) have a need for the same. These include – Microsoft, Samsung, Xerox, Yahoo, Oracle, Google, IBM, TCS, Infosys, Amazon, Flipkart, etc. This course would help industry developers to be up-to-date with the advances in C++ so that they can remain at the state-of-the-art.
Course layout (Answers link)
Answers COMING SOON! Kindly Wait!
Week 0: Assignment answers
Week 1:Â Programming in C++ is Fun
Week 2: C++ as Better C.
Week 3: OOP in C++.
Week 4: OOP in C++.Â
Week 5:Â Inheritance.
Week 6: Polymorphism.Â
Week 7:Â Type Casting.
Week 8:Â Exceptions and Templates.
Week 9:Â Streams and STL
Week 10:Â Modern C++
Week 11: Lambda and Concurrency.
Week 12: Move, Rvalue and STL Containers.
NOTE: You can check your answer immediately by clicking show answer button. Programming in Modern C++ NPTEL 2023 Week 1 Assignment Solution” contains 09 questions.
Now, start attempting the quiz.
Programming in Modern C++ NPTEL 2023 Week 1 Assignment Solutions
Q1. Consider the following program.
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
bool compare(char c1, char c2){
return tolower(c1) > tolower(c2); //LINE-1
}
int main(){
char arr1[20] = "C++ Program", arr2[20] = "C Program";
cout << lexicographical_compare(arr1, arr1+strlen(arr1), arr2, arr2 + strlen(arr2), compare);
return 0;
}
What will be the output/error?
a) 1
b) 0
c) -1
d) Compilation Error: function is not defined
Answer: a) 1
Q2. Consider the following code segment.
#include<iostream>
#inlcude<algorithm>
using namespace std;
bool compare(int i, int j){
return (i < j);
}
int main() {
int data[] = {1, 2, 3, 4, 5};
int key = 5;
if(binary_search(_ _ _ _ _ _ _ _)) //LINE-1
cout << "found";
else
cout << "not found";
return 0;
}
Fill in the blank at LINE-1 so that the program will print “not found”?
a) &data[0], &arr[5], key
b) data, data+5, key
c) &data[0], &data[4], key
d) data+1, data+4, key
Answer: C), d)
Q3. Consider the following code segment.
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int data[] = {50, 30, 40, 10, 20};
sort (&data[1], &data[4]);
for(int i=0; i<5; i++)
cout << data[i] << " ";
return 0;
}
What will be the output?
a) 10 20 30 40 50
b) 10 30 40 50 20
c) 50 10 30 40 20
d) 50 10 20 30 40
Answer: c) 50 10 30 40 20
Q4. Consider the following code segment.
#include<iostream>
#include<stack>
using namespace std;
int main() {
int element[5];
for(int i=1; i<=5; i++){
*(element + i - 1) = i * 5;
rotate(element, element + 4, element + 5);
rotate(element, element + 1, element + 4);
for(int i=0; i<5; ++i)
cout << element[i] << " ";
return 0;
}
What will be the output?
a) 5 10 15 20 25
b) 5 10 15 25 20
c) 20 10 15 25 5
d) 25 5 10 15 20
Answer: b) 5 10 15 25 20
Q5. Consider the following code segment.
What will be the output?
a) A A A B C Z Z Z
b) A A B B C Z Z Z
c) A A A B C Z Z
d) A A A B C Z Z Z Z
Answer: a)Â A A A B C Z Z Z
Q6. Consider the following code segment.
#include<iostream>
#include<string>
using namespace std;
int main(void) {
string s1 = "C++ ";
string s2 = "Program";
_ _ _ __ _ _ _ ; //LINE-1
cout << s1;
return 0;
}
Choose the appropriate option to fill in the blank at LINE-1, such that the output of the code would be: C++ Program.
a) s1 += s2
b) strcat(s1, s2)
c) s1.append(s2)
d) s1.insert(s2)
Answer: a), c)
Q7. Consider the following code segment.
Fill in the blank at LINE-1 such that the output is
5 2 3 4 5
a) data + 4 – i
b) data + 5 – i
c) data + i -4
d) data + i – 5
Answer: a) data + 4 – i
Q8. Consider the following code segment.
What will be the output?
a) 1234987654
b) 123498765
c) 1234897654
d) 123459876
Answer: c) 1234897654
Q9. Consider the following code segment.
Which statement/statements is/are correct?
a) STMT-1
b) STMT-2
c) STMT-3
d) STMT-4
Answer: b) STMT-2
Programming in Modern C++ NPTEL 2022 Week 1 Assignment Solutions
Q1. Consider the following program.
#include<iostream>
#include<string>
using namespace std;
int main() {
string greet = "Hello Student";
_ _ _ _ _ _ _ _ _ _ _; // LINE-1
cout << greet;
return 0;
}
Fill in the blank at LINE-1 such that the output is Hello.
a) greet.resize(5)
b) greet.shrink_to_fit()
c) greet.copy(“Hello”, 5, 0)
d) strcpy(greet, “Hello”)
Answer: a) greet.resize(5)
Q2. Consider the following code segment.
#include<iostream>
#inlcude<algorithm>
using namespace std;
bool compare(int i, int j){
return (i < j);
}
int main() {
int arr[] = {4, 2, 6, 1, 7, 5};
sort(_ _ _ _ _ _ _ _ _); // LINE-1
for(int i=0; i<6; i++)
cout << arr[i] << " ";
return 0;
}
Identify the appropriate option(s) to fill in the blank at LINE-1, such that the output is:
1 2 4 6 7 5
a) &arr[0], &arr[0]+4, compare
b) &arr[0], &arr[0]+3, compare
c) arr, arr+4, compare
d) &arr, &arr+4, compare
Answer: a), c)
Q3. Consider the following code segment.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int i;
vector<int> arr;
for(i=1; i<=9; i++)
arr.push_back(i);
rotate(arr.begin(), arr.begin()+3, arr.begin()+5);
for(int i=0; i<arr.size(); i++)
cout << arr[i] << " ";
return 0;
}
What will be the output?
a) 3 2 1 4 5 6 7 8 9
b) 4 5 1 2 3 6 7 8 9
c) 5 6 7 1 2 3 4 8 9
d) 9 8 7 1 2 3 4 5 6
Answer: b) 4 5 1 2 3 6 7 8 9
Q4. Consider the following code segment.
#include<iostream>
#include<stack>
using namespace std;
int main() {
int i;
int arr[5] = {5, 7, 3, 6, 4};
stack<int> s;
for(i=0; i<5; i++){
while(!s.empty()){
if(s.top() < arr[i]){
cout << s.top() << " ";
break;
}
else
s.pop();
}
if(s.empty())
cout << -1 << " ";
s.push(arr[i]);
}
return 0;
}
What will be the output/error?
a) -1 5 7 3 6
b) -1 5 5 3 3
c) -1 5 -1 3 3
d) Compilation Error: wrong template argument before s
Answer: c) -1 5 -1 3 3
Q5. Consider the following code segment.
#include<iostream>
using namespace std;
int reverse(_ _ _ _ _ _, int r, int c) { // LINE-1
// code to reverse all the strings present in the matrix
// and return it
int main() {
int str[10][20]; // array of 10 strings
reverse(str, 10, 20);
return 0;
}
Choose the correct parameter-list for function header at LINE-1.
a) int str[][]
b) int str[][20]
c) int str[10][]
d) int str[10][20]
Answer: b), d)
Q6. Consider the following code segment.
#include<iostream>
using namespace std;
int main() {
bool i = true;
bool j = false;
bool k = false;
cout << (i || j && k);
return 0;
}
What will be the output?
a) 0
b) 1
c) false
d) true
Answer: b) 1
Q7. Consider the following code segment.
#include<iostream>
#include<string>
using namespace std;
int main() {
string word1 = "Star ";
string word2 = "Wars ";
_ _ _ _ _ _ // LINE-1
cout << str;
return 0;
}
Choose the appropriate option(s) such that the output of the code segment would be
Start Wars
a) string str = strcat(word1, word2);
b) string str = word1 + word2;
c) string str = word1.insert(word2);
d) string str = word1.append(word2);
Answer: b), d)
Q8. Consider the following code segment.
#include<iostream>
#include<algorithm>
int main() {
int idata[] = {10, 20, 30, 40, 50}, k = 50;
if(_ _ _ _ _ _ _ _ _ _ _ _ _ _) // LINE-1
std::cout << "key found";
else
std::cout << "key not found";
return 0;
}
Choose the appropriate option to fill in the blank at LINE-1, such that the output of the code would be: key found
a) binary_search(idata, idata+4, k)
b) std::binary_search(idata, idata+4, k)
c) binary_search(idata, idata+5, k)
d) std::binary_search(idata, idata+5, k)
Answer: d) std::binary_search(idata, idata+5, k)
Q9. Consider the following code segment.
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int idata[] = {1, 2, 2, 3, 4, 4, 5};
replace(idata, idata+7, 2, 4);
remove(idata, idata+7, 4);
for(int i = 0; i < 3; ++i)
cout << idata[i] << " ";
return 0;
}
What will be the output?
a) 1 3 5
b) 1 2 2
c) 1 3 4
d) 1 2 4
Answer: a) 1 3 5
<< Prev- Programming in Modern C++ Week 0 Assignment Solutions
>> Next- Programming in Modern C++ Week 2 Assignment 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.
NPTEL answers: Principles of Management
NPTEL answers: Problem solving through programming in C
Programming in Java NPTEL week 1 quiz answers
NPTEL – Python for Data Science assignment solutions
Nptel – Deep Learning assignment solutions
The above question set contains all the correct answers. But in any case, you find any typographical, grammatical or any other error in our site then kindly inform us. Don’t forget to provide the appropriate URL along with error description. So that we can easily correct it.
Thanks in advance.
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.