Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

CODE

#include <iostream>

#include <string>

using namespace std;

class polygon

private:

float length;

float *width;

public:

polygon(float l, float w)

length = l;
width = new float;

*width = w;

void display()

cout << "before length : " << length << endl;

cout << "before width: " << *width << endl;

void setvalue()

*width = 22.9;

float get_length()

{
return length;

float get_width()

return *width;

};

int main()

polygon obj1(24.4, 55.8);

polygon obj2 = obj1;

cout << "1:" << endl;

obj1.display();

cout << "2:" << endl;


obj2.display();

cout << endl << endl;

cout << " AFTER MODIFING:" << endl;

obj1.setvalue();

cout << obj1.get_length() << endl;

cout << obj1.get_width() << endl;

cout << endl;

cout << obj2.get_length() << endl;

cout << obj2.get_width() << endl;

cout << endl;

system("pause");

OUTPUT

You might also like