Programming in Modern C++
Due on 2022-02-17, 23:59 IST
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
#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
};
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
#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
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
#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---------------------
Thanks bro❤❤
ReplyDeleteThank you bro god bless you.
ReplyDeleteAssignment ka lia thanku
ReplyDeleteLove you bhaiii
ReplyDelete