Programming In Modern C++ Assignment 1 Answers 2023

In this post, We have provided answers of NPTEL Programming In Modern C++ Assignment 1. We provided answers here only for reference. Plz, do your assignment at your own knowledge.

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

1. Consider the code segment given below.

#include <iostream> 
#include<cmath> 
int main() { 
            int n = 4; 
            _________     //LINE-1 
            return 0;
        }

Fill in the blank at LINE-1 such that the output is 16 2.
a) std:: cout << std::pow(n, 2) <‹ ” ” <‹ std: :sqrt (n)
b) cout <‹ pow(n,2) <‹ ” ” <‹ sqrt (n)
c) std:: cout << std::pow(n) « ” ” << std: :sqrt (n)
d) cout << pow(n) << ” ” << sqrt (n)

Answer :- a) std::cout << std::pow(n, 2) << " " << std::sqrt(n)

2. Consider the code segment given below.

#include <iostream> 
#include‹vector> 
using namespace std; 
int main(){ 
___________;      //LINE-1 

       arr.resize (10); 
      for (int i=0;i<10;i++) 
            arr [i] = i+1; 
return 0; 
} 

Fill in the blank at LINE-1 such that the program will run successfully.

a) vector<int> arr
b) vector<int> arr (3)
c) vector<int> arr [3]
d) int arr [3]

Answer :- a) vector<int> arr

3. Consider the following code segment.

#include ‹iostream> 
#include<cstring> 
using namespace std; 

int main() { 
string S = S "programming in modern C++"; 
cout << s. size() ; //LINE-1 
cout << strlen(s); //LINE-2 
cout << s. length(); //LINE-3 
cout << strlen(s.c_str()); //LINE-4 
return 0; 
} 

Which line/ will give compilation error/s?

a) LINE-1
b) LINE-2
c) LINE-3
d) LINE-4

Answer :- Click Here

4. Consider the code segment given below.

#include <iostream> 
#include <algorithm> 
using namespace std; 
int main () {
      int data[] = {50, 30, 40, 10, 20}; 
      sort (&data [2], &data [5]); 
      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 30 10 20 40
d) 50 10 20 30 40

Answer :- Click Here

5. Consider the code segment given below.

#include <iostream> 
#include <string> 
using namespace std;
int main(void) { 
string stri = "Welcome ";
string str2 = "students"; 
_________            //LINE-1
cout << stri; 
return 0;    
}

Choose the appropriate option to fill in the blank at LINE1, such that the output of the code would be: Welcome students.

a) stri += str2
b) strcat (stri, str2)
c) str1. append(str2)
d) str1.insert (str2)

Answer :- Click Here

6. Consider the code segment given below.

Programming In Modern C++ Assignment 1 Answers 2023
Answer :- Click Here

7. Consider the Code segment below.

Programming In Modern C++ Assignment 1 Answers 2023
Answer :- Click Here

8. Consider the code segment given below.

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

plz ignore code typo mistake.

What will be the output?

a) 40 10 10 20
b) 50 40 50 20
C) 50 50 40 20
d) 40 10 40 20

Answer :- Click Here

9. Consider the code segment given below.

#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+5, compare) ; 
return 0; 
} 

plz ignore code typo mistake.

What will be the output?

a) 1
b) 0
c) -1
d) Compilation Error: function is not defined

Answer :- Click Here

NPTEL Programming In Modern C++ Assignment 1 Answers 2022

1. Consider the following program.

What will be the output?

a) COMPUTER
b) RETUPMOC
c) UTERCOMP
d) COMPRETU

#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
int main){
char str[10] COMPUTER";
stack<char> sl, s2;
int
for (i 0; i < strlen (str) /2; itt)
s1.push (str [i]) ;
for(; i < strlen(str); itt)
s2.push (str [i]);
while (!s1.cmpty ()) t
s2.push (s1. top()); s1.pop ();
while (Is2.ompty ())
cout s2.top (); s2.pop);
roturn 0;
Answer:- d

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

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

Answer:- c

Answers will be Uploaded Shortly and it will be Notified on Telegram, So JOIN NOW

Programming In Modern C++ Assignment 1 Answers 2023

3. Consider the following code segment.

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

a) &data [01, kdata[5], key
b) dala, data+5, key
c) data, key, data+5
d) &data [O1, &key, &data [5]

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

4. 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 51

Answer:- b

5. 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

Answer:- a

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

a) remove (kiarr [0], &iarr [61, 50)
b) remove(&iarr [0], &iarr [51, 50)
c) remove (iarr, iarr + 6, 50
d) remove (iarr, iarr + 6, iarr [5])

Answer:- a, c

👇For Week 02 Assignment Answers👇

Programming In Modern C++ Assignment 1 Answers 2023

7. What will be the output?

a) 3 2 1 2 3
b) 1 2 3 21
c) 5 4 3 4 5
d) 5 4 3 21

Answer:- d

8. Choose the appropriate option to fill in the blank at LINE-1, such that the output of the code would be: Modern C+t.

a) stri + str2
b) strcat (str1, str2)
c) stri.append (str2)
d) str1. insert (str2)

Answer:- a, c

9. 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

For More NPTEL Answers:- CLICK HERE

Join Our Telegram:- CLICK HERE

About Programming In Modern C++

There has been a continual debate on which programming language/s to learn, to use. As the latest TIOBE Programming Community Index for August 2021 indicates – C (13%), Python (12%), C++ (7%), Java (10%), and C#(5%) together control nearly half the programming activities worldwide. Further, C Programming Language Family (C, C++, C#, Objective C etc.) dominate more than 25% of activities. Hence, learning C++ is important as one learns about the entire family, about Object-Oriented Programming and gets a solid foundation to also migrate to Java and Python as needed. C++ is the mother of most general purpose of languages. It is multi-paradigm encompassing procedural, object-oriented, generic, and even functional programming. C++ has primarily been the systems language till C++03 which punches efficiency of the code with the efficacy of OOP.

Then, why should I learn it if my primary focus is on applications? This is where the recent updates of C++, namely, C++11 and several later offer excellent depths and flexibility for C++ that no language can match. These extensions attempt to alleviate some of the long-standing shortcomings for C++ including porous resource management, error-prone pointer handling, expression semantics, and better readability. The present course builds up on the knowledge of C programming and basic data structure (array, list, stack, queue etc.) to create a strong familiarity with C++98 / C++03. Besides the constructs, syntax and semantics of C++ (over C), we also focus on various idioms of C++ and attempt to go to depth with every C++ feature justifying and illustrating them with several examples and assignment problems. On the way, we illustrate various OOP concepts. The course also covers important advances in C++11 and later released features.

COURSE LAYOUT

  • 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.

CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of average of best 8 assignments out of the total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

Leave a Comment