Are you looking for the Answers to NPTEL Programming in Modern C++ Assignment 4? This article will help you with the answer to the National Programme on Technology Enhanced Learning (NPTEL) Course ” Programming in Modern C++ Assignment 4 “
What is 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.
CRITERIA TO GET A CERTIFICATE
Average assignment score = 25% of the 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 THE 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.
Below you can find the answers for NPTEL Programming in Modern C++ Assignment 4
NPTEL Programming in Modern C++ Assignment 4 Answers:-
Q1. Consider the following program. Fill in the blanks as per the instructions given below:
- at LINE-1 with appropriate declaration so that global operator function can access private data of class Complex,
- at LINE-2 with appropriate operator function header,
- at LINE-3 with appropriate return statement,
Code:-
#include<iostream>
#include<cstring>
using namespace std;
class Complex{
int re, im;
public:
Complex(int r, int i) : re(r), im(i){}
void print(){
cout << re << " + j" << im;
}
friend Complex operator+(const Complex &e, int n); //LINE-1
};
Complex operator+(const Complex &e, int n){ //LINE-2
return Complex(e.re+n,e.im); //LINE-3
}
Q2. Consider the following program. Fill in the blanks as per the instructions given below:
- at LINE-1 with appropriate keyword to declare the Database pointer variable,
- at LINE-2 to complete the header for function getInstance(int i),
- at LINE-3 with appropriate keyword to complete ins variable initialization
Code:-
#include<iostream>
using namespace std;
class Database{
int data;
static Database *ins; //LINE-1
Database(int i) : data(i) {}
public:
int get(){ return data; }
static Database* getInstance(int i){ //LINE-2
if(!ins)
ins = new Database(i);
return ins;
}
};
Database* Database::ins = 0; // LINE-3
???? Next Week Answers: Assignment 05 ????
Q3. Consider the following program. Fill in the blanks as per the instructions given below:
- at LINE-1 with appropriate statement so that global operator function can access private members,
- at LINE-2 with appropriate operator function header,
- at LINE-3 with appropriate operator function header,
- at LINE-4 with appropriate operator function header
Code:-
friend istream& operator>>(istream& is, Point& p); //LINE-1
Point& operator++(){ //LINE-2
++x;
return *this;
}
Point operator++(int){ //LINE-3
Point p(x,y);
++y;
return p;
}
}; // End of class Point
istream& operator>>(istream& is, Point& p){ //LINE-4
is >> p.x >> p.y;
return is;
}
For other courses answers:- Visit
For Internship and job updates:- Visit