NPTEL Programming in Modern C++ Assignment 3 Answers 2022

NPTEL Programming in Modern C++ Assignment 3

Are you looking for the Answers to NPTEL Programming in Modern C++ Assignment 3? This article will help you with the answer to the National Programme on Technology Enhanced Learning (NPTEL) Course Programming in Modern C++ Assignment 3

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 3

NPTEL Programming in Modern C++ Assignment 3 Answers:-

Q1. Consider the following program. Fill in the blanks as per the instructions given below:

  • at LINE-1 with appropriate initialization block to initialize the data members,
  • at LINE-2 with appropriate definition of the destructor to free the memory allocated for
  • the data members,
  • at LINE-3 and LINE-4 with appropriate definition of the functions getX() and getY(),

such that it will satisfy the given test cases.

#include<iostream>
using namespace std;

class point {
    const int *px, *py;
    public:
        point(int x, int y) : px(new int (x)),py(new int(y)){}    // LINE-1
        ~point() { delete px;delete py; }    // LINE-2
        int getX() { return *px; }    // LINE-3
        int getY() { return *py; }    // LINE-4
};

Q2. Consider the following program. Fill in the blanks as per the instructions given below:

  • at LINE-1 with appropriate declaration of data member z, and
  • at LINE-2 and LINE-3 with appropriate header of the functions calulateZ() and print(),
#include<iostream>
using namespace std;

class myClass {
    int x, y;
    static int z;                                      // LINE-1

    public:
        myClass(int x_, int y_) : x(x_ * x_), y(y_ * y_) { }
        void calulateZ() const{ z = x + y; };       // LINE-2

        void print() const {                     // LINE-3 
            cout << "x = " << x << ", y = " << y << ", z = " << z; 
        }
};

int myClass::z=0; 

???? Next Week Answers: Assignment 04 ????

quizxp telegram

Q3. Consider the following program. Fill in the blanks as per the instructions given below:

  • at LINE-1 with appropriate header for the copy constructor,
  • at LINE-2 with appropriate header for the copy assignment operator,
  • at LINE-3 with appropriate condition
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;

class employee {
    int eid;
    char *name;
    public:
        employee(int eid_, const char *name_) : eid(eid_), name(strdup(name_)) { }
        employee(const employee &e) : eid(e.eid), name(strdup(e.name)) { }   // LINE-1
        employee& operator= (const employee &e){    // LINE-2 
            if (this != &e) {              // LINE-3 
                free(name);
                eid = e.eid;
                name = strdup(e.name);				
            }
            return *this;
        }

For other courses answers:- Visit

For Internship and job updates:- Visit