Sign Up

Sign In

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Sorry, you do not have permission to ask a question, You must login to ask a question.

SIKSHAPATH Latest Articles

NPTEL Programming In Modern C++ Week 1 Assignment Answers 2022

A banner to programming in modern c++ nptel course answer july 2022

Are you looking for help in Programming In Modern C++ NPTEL Week 1 Assignment Answers? So, here in this article, we have provided Programming In Modern C++ week 1 Assignment Answer’s hint.

NPTEL Programming In Modern C++ Week 1 Assignment Answers

Q1. Consider the following program.

#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
int main()
{
char str[10] = "COMPUTER";
stack<char> s1, s2;
int i;
for (i=0; i < strlen(str)/2; i++) s1.push(str[i]);
for(; i < strlen(str); i++)
s2.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. RETUPMOC
c. UTERCOMP
d. COMPRETU

Answer: d. COMPRETU

For instant notification of future updates, Join us on telegram.


Q2. Which of the following is NOT a container adapter?

a. stack
b. queue
c. deque
d. priority-queue

Answer: c. deque


Q3. Consider the following code segment.

#include <iostream>
#include <algorithm>
using namespace std; 
int main() {
char data[]={'a', 'b', 'c', 'd', 'e'}; 
char key = 'd'; 
if (binary_search (_________)) //LINE-1
cout << "found";
else
cout<<"not found";
return 0;
}

Identify the appropriate option/s to fill in the blank LINE-1 such that output becomes found.

a. &data[0], &data [5], key

b. data, data+5, key

c. data, key, data+5

d. &data[0], &key, &data[5]

Answer: a. &data[0], &data [5], key
b. data, data+5, key


Q4. Consider the following code segment.

#include <iostream> 
#include <algorithm>
using namespace std;
void modify (int *arr) {
rotate(arr, arr + 3, arr + 5);
rotate(arr, arr + 2, arr + 4);
}
int main() {
int iarr [5];
for (int i = 0; i < 5; i++)
*(iarr + i) = i + 1;
modify (iarr);
for (int i = 0; i < 5; ++i) 
cout << *(iarr + i) << " ";
return 0;
}

What will be the output?

a. 1 2 3 4 5

b. 1 2 4 5 3

c. 4 5 1 2 3

d. 2 3 4 5 1

Answer: b. 1 2 4 5 3


Q5. Consider the following code segment.

#include <iostream>
#include <vector>
int main() {
std::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 < 3; i++)
cVec.push_back((i + 1)*20);
for(int i = 0; i < cVec.size(); i++) 
std::cout << cVec[i] << " ";
return 0;
}

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

Answer: a. 10 20 30 20 40 60


Q6. Consider the following code segment.

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int iarr[]= {10, 20, 50, 40, 10, 50}; 
____________________, &iarr[6]); 
remove (iarr, iarr + 6, iarr [5]); //LINE-1
for(int i=0; i < 4; ++i) 
cout << iarr[i] << " ";
return 0;
}

Fill in the blank at LINE-1 with appropriate option/s such that the output is: 40 10 10 20

a. remove(&iarr[0], &iarr [6], 50)

b. remove(&iarr[0], &iarr [5], 50)

c. remove (iarr, iarr + 6, 50)

d. remove (iarr, iarr + 6, iarr [5])

Answer: a. remove(&iarr[0], &iarr [6], 50)
c. remove (iarr, iarr + 6, 50)


Q7. 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);
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 2 1

c. 5 4 3 4 5

d.  5 4 3 2 1

Answer: d.  5 4 3 2 1


Q8. Consider the following code segment.

#include <iostream>
#include <string>
using namespace std;
int main(void) {
string str1= "Modern ";
string str2 = "C++";
 ____________; //LINE-1
cout << str1;
return 0;
}

Choose the appropriate option to fill in the blank at LINE-1, 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)

Answer: a. str1 += str2
c. str1.append(str2)


Q9. Consider the following code segment.

#include <iostream> 
#include <algorithm> 
using namespace std;
int main() {
int iArr[]= {40, 50, 10, 30, 20};
sort (iArr, iArr + 4);
for(int i = 0; i < 5; i++) 
cout << *(iArr + i) << " "; 
return 0;
}

What will be the output?

a. 10 20 30 40 50
b. 10 30 40 50 20
c. 50 40 30 20 10
d. 50 40 30 10 20

Answer: b. 10 30 40 50 20


TELEGRAM FOR NOTIFICATIONClick Here
Follow on Google News (in one click)Click Here

Disclaimer: These answers are provided only for the purpose of helping students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.


Also Available:

Programming in Modern C++ NPTEL Assignment Week 2

Related Posts