0% found this document useful (0 votes)
5 views

11.Parameterized constructor

The document presents a C++ program that defines a class 'number' with a parameterized constructor and overloaded operators for addition, subtraction, multiplication, and division. It demonstrates the usage of these operators by creating instances of the 'number' class and performing various arithmetic operations. The results are displayed using the 'show' method.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

11.Parameterized constructor

The document presents a C++ program that defines a class 'number' with a parameterized constructor and overloaded operators for addition, subtraction, multiplication, and division. It demonstrates the usage of these operators by creating instances of the 'number' class and performing various arithmetic operations. The results are displayed using the 'show' method.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

11.

Parameterized constructor

#include<iostream.h>

#include<conio.h>

#include<math.h>

class number

public:

float x,y;

number()

{}

number(float a, float b)

x=a;

y=b;

number operator+(number d)

number num;

num.x=x+d.x;

num.y=y+d.y;

return num;

number operator-(number d)

number num;

num.x=x-d.x;
num.y=y-d.y;

return num;

number operator *(number d)

number num;

num.x=x*d.x;

num.y=y*d.y;

return num;

number operator /(number d)

number num;

num.x=x/d.x;

num.y=y/d.y;

return num;

void show()

cout<<"\n \t x value is : "<<x;

cout<<"\n \t y value is : "<<y;

};

void main()

clrscr();

number n1(5,5),n2(4,4),c;
cout<<"\n \n \t Addition:";

c=n1+n2;c.show();

cout<<"\n\t Subtraction :";

c=n1-n2;c.show();

cout<<"\n \t Multiplication:";

c=n1*n2;c.show();

cout<<"\n \t Divison :";

c=n1/n2;c.show();

getch();

You might also like