Programming in Modern C++ Week 1 Assignment Answers
Are you looking for Nptel Programming in Modern C++ Week 1 Assignment Answers ? You are here at right place for Week 1 assignment answers
Table of Contents
Programming in Modern C++ Week 1 Assignment Answers (Jan-Apr 2025)
Course Link: Click Here
Que. 1) Consider the following program:
#include <iostream>
#include <stack>
using namespace std;
char str[] = "COMPUTER";
stack<char> s1, s2;
int i;
for (i = 0; i < strlen(str); i++)
s1.push(str[i]);
while (!s1.empty()) {
s2.push(s1.top());
s1.pop();
}
while (!s2.empty()) {
cout << s2.top();
s2.pop();
}
return 0;
a) COMPUTER
b) REIUPHDC
c) UTERCOHP
d) CINPRETU
Que. 2) Which of the following is a container adapter?
a) stack
b) queue
c) deque
d) priority-queue
Que. 3) Consider the following code segment:
#include <iostream>
using namespace std;
int main() {
char data[] = "2453";
char key = '5';
if (binary_search(data, data+5, key)) {
cout << "found";
} else {
cout << "not found";
}
return 0;
}
Identify the appropriate option to fill in the blank such that the output is “found.”
a) key
b) data, data+5, key
c) data, key, data+5
d) &key, &data[5]
Que. 4) Consider the following code:
#include <iostream>
#include <algorithm>
using namespace std;
void modify(int* arr) {
rotate(arr, arr+3, arr+2);
rotate(arr+4, arr+3, arr+5);
}
int main() {
int arr[5];
for (int i = 0; i < 5; ++i) {
cin >> arr[i];
}
modify(arr);
for (int i = 0; i < 5; ++i) {
cout << arr[i];
}
return 0;
}
What will be the output?
a) 1 2 3 4 5
b) 5 4 3 2 1
c) 4 5 1 2 3
d) 1 5 4 3 2
Que. 5) Consider the following code segment:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> cVec(3, -1);
for (int i = 0; i < 3; i++) {
cVec[i] = (i + 1) * 10;
}
cVec.resize(3);
cVec.resize(3, 110);
for (int i = 0; i < cVec.size(); i++) {
cout << cVec[i] << " ";
}
return 0;
}
What will be the output?
a) 10 20 30 20 40 60
b) -1 -1 -1 10 20 30 20 40 60
c) -1 -1 -1 10 20 30 0 0 0 20 40 60
d) 10 20 30
Que. 6) Consider the following code segment:
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int iarr[] = {10, 50, 40, 10, 50};
rotate(iarr, iarr+6, 50);
for (int i = 0; i < 4; ++i)
cout << iarr[i] << " ";
return 0;
}
Fill in the blank such that the output is 40 10 10 50.
a) rotate(iarr, iarr+6, 50)
b) rotate(iarr, iarr+6, iarr[5])
c) rotate(iarr, iarr+6, iarr[4])
d) rotate(iarr, iarr+5, 50)
Que. 7) Consider the following code segment:
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int idata[] = {1, 2, 3, 4, 5};
int n = sizeof(idata) / sizeof(idata[0]);
for (int i = 0; i < n / 2; i++) {
int temp = idata[i];
replace(idata, idata + 5, temp, *(idata + n - i - 1));
replace(idata + i + 1, idata + 5, idata[n - i - 1], temp);
}
for (int i = 0; i < 5; ++i) {
cout << idata[i] << " ";
}
return 0;
}
What will be the output?
a) 3 2 1 2 3
b) 1 2 3 4 5
c) 5 4 3 2 1
d) 5 4 3 4 5
Que. 8) Consider the following code segment:
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string str1 = "Modern ";
string str2 = "C++";
str1.append(str2);
cout << str1;
return 0;
}
What is the appropriate option to fill in the blank at LINE-I, such that the output of the code would be “Modern C++”?
a) str1 + str2
b) strcat(str1, str2)
c) str1.append(str2)
d) str1.insert(str2)
Que. 9) Consider the following code segment:
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int iArr[] = {40, 50, 10, 30, 20};
rotate(iArr, iArr+4, iArr+6);
for (int i = 0; i < 5; i++) {
cout << iArr[i] << " ";
}
return 0;
}
What will be the output?
a) 10 30 40 50 20
b) 50 40 30 20 10
c) 10 20 30 40 50
d) 30 20 10 40 50
Programming in Modern C++ Week 1 Assignment Answers (Jul-Dec 2024)
Course Link: Click Here
Q1.Consider the following program
Fill in the blank at LINE-1 such that the output is Good Morning.
a) message.resize(12)
b) message.clear()
c) message.replace(0, 12, “Good Morning”)
d) strcpy(message, “Good Morning”)
Answer: a) message.resize(12)
Q2.Consider the following code segment.
Identify the appropriate option(s) to fill in the blank at LINE-1, such that the output is:
2 4 9 8 6 3 1
a) &arr[0], &arr[0] + 3, compare
b) arr, arr + 3, compare
c) &arr[0], &arr[0] + 2, compare
d) arr, arr+ 2, compare
Answer: a) &arr[0], &arr[0] + 3, compare
b) arr, arr + 3, compare
For answers or latest updates join our telegram channel: Click here to join
Q3. Consider the following code segment.
What will be the output?
a) 60 15 25 35 45
b) 60 25 15 35 45
c) 60 25 35 45 15
d) 60 25 35 15 45
Answer: a) 60 15 25 35 45
These are Programming in Modern C++ Week 1 Assignment Answers
Q4.Consider the following code segment.
What will be the output?
a) 10 20 30 40 50 60
b) 10 20 60 30 40 50
c) 60 30 40 50 10 20
d) 20 30 40 60 10 50
Answer: d) 20 30 40 60 10 50
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 1 Assignment Answers
Q5. Consider the following code segment .
What will be the output?
a) 5 5 5 5 101 102 103 99 99 99
b) 5 5 5 5 100 101 102 103 99 99
c) 5 5 5 5 101 102 103 99 99
d) 5 5 5 5 100 101 102 103 99 99 99 99
Answer: a) 5 5 5 5 101 102 103 99 99 99
Q6. Consider the following code segment .
What will be the output?
a) ProABXYZing
b) ProABgXYZramming
c) ProABXYZmming
d) ProXYZABgramming
Answer: a) ProABXYZing
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 1 Assignment Answers
Q7. Consider the following code segment .
Fill in the blank at LINE-1 such that the output is 50 20 30 40 50
a) array + 4 i
b) array + 5 i
c) arrayi-4
d) array + i 5
Answer: a) array + 4 i
Q8. Consider the following code segment.
What will be the output?
a) ABCDEKJIHGFE
b) ABCDEKJIHG
c) ABCDEJIHGF
d) ABCDEFGHIJK
Answer: a) ABCDEKJIHGFE
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 1 Assignment Answers
Q9. Consider the following code segment
Identify the appropriate option/s to fill in the blank at LINE-1 such that output becomes lval 20 rval 20.
Which statement/statements is/are correct?
a) STMT-1
b) STMT-2
c) STMT-3
d) STMT-4
Answer: b) STMT-2
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 1 Assignment Answers
Programming Questions
W1_Programming-Qs.1
Consider the program below.
• Fill in the blank at LINE-1 to declare a stack variable st.
• Fill in the blank at LINE-2 to push values into the stack.
• Fill in the blank at LINE-3 with the appropriate statement.
The program must satisfy the given test cases.
Solution:
Update Soon
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 1 Assignment Answers
W1_Programming-Qs.2
Consider the following program.
• Fill in the blank at LINE-1 with the appropriate if statement,
• Fill in the blank at LINE-2 and LINE-3 with the appropriate return statements.
The program must satisfy the sample input and output.
Solution:
Update Soon
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 1 Assignment Answers
W1_Programming-Qs.3
Consider the program below.
• Fill in the blank at LINE-1 to include the appropriate header file to utilize the abs () function.
• Fill in the blank at LINE-2 to compute the Manhattan distance between two points pt1 and pt2 as pt1.ypt2.y+pt1.x pt2.r
The program must satisfy the given test cases.
Solution:
Update Soon
For answers or latest updates join our telegram channel: Click here to join
These are Programming in Modern C++ Week 1 Assignment Answers
More Solutions of Programming in Modern C++: Click Here
More Nptel Courses: https://progiez.com/nptel-assignment-answers