Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

Programming in Modern C++ | Week 3 : Programming Assignments | Jan-2022 | NPTEL

 Programming in Modern C++

Due on 2022-02-17, 23:59 IST
----------------------------------------------------------------------------------------------------

Week 3 : Programming Assignment 1

---------------------------------------------------------------------------------------------------- #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 }; ----------------------------------------------------------------------------------------------------

Week 3 : Programming Assignment 2

---------------------------------------------------------------------------------------------------- #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;                                        // Don't forget to write this statement ----------------------------------------------------------------------------------------------------

Week 3 : Programming Assignment 3

---------------------------------------------------------------------------------------------------- #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; } ----------------The End---------------------

4 comments:

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.