# Programming In Modern C++ Assignment 2 Answers 2022

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

## NPTEL Programming In Modern C++ Assignment 2 Answers 2022

Q1. Consider the following function prototypes of function add ().
P1: int add (int ni 0, int n2)
P2: int add (int 0, int – 0);
P3: double add (double = 0, double d 0.0);
P4: double add(int = 0, double d 0.0);
P5: double add (int ni = 0, int n2, double n3 0);

Which of the following sets consists of all valid prototypes of function add()?

a) {P1, P3)
b) {P2, P3, P4}
c) {P1, P2, P3, P4}
d) {P2, P3, P5}

`Answer:- b`

2. Consider the following function prototypes of function add ().

Which of the above pairs of the prototypes is ambiguous and illegal as per the rule of function overloading?

a) P1, P2
b) P2, P3
c) P3, P4
a) P2, P5

`Answer:- d`

3. Consider the following statement in C.

What will be the output/error?

a) 30
b) 130
c) 300

`Answer:- d`

4. Consider the following statement in C.

What will be the output?

a) 40 60
b) 30 60
c) 30 40
d) 20 30

`Answer:- b`

5. Consider the following statement in C.

Choose the correct option to fill in the blank at LINE-1 such that the output is 11 11 20 20.

a) int incr (int i)
b) int incr (int& i)
c) int& incr (const int& i)
d) int& incr (intk i)

`Answer:- d`

6. Consider the following statement in C.

`Answer:- a`

7. Consider the following statement in C.

`Answer:- d`

8. Consider the following statement in C.

`Answer:- a, c`

9. Consider the following statement in C.

`Answer:- b, c`

Q1. Consider the program below which defines a type point and overloads operator + such that the x and y coordinates of a given point can be added with an integer.
Complete the program with the following instructions.

Code:-

Q2. Consider the following program. Fill in the blanks at LINE-1 and LINE-2 with appropriate headers of overloaded function product. The program must satisfy the sample input and output.

Code:-

Q3. Consider the following program. Fill in the blank at LINE-1 with an appropriate function header for the function update_and_sum( ) such that it satisfies the sample input and output.

Code:-

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