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

#Include #Include Using Namespace STD Class Calc

The document contains C++ code that defines three classes - calc, calc, and comp. The calc class defines a square method that squares an integer. The second calc class overloads the square method to return a calc object with the squared value. The comp class defines a complex number with real and imaginary parts, along with an add method to sum two complex numbers. The main function demonstrates using the square and add methods to square an integer and sum two complex numbers respectively.
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)
36 views

#Include #Include Using Namespace STD Class Calc

The document contains C++ code that defines three classes - calc, calc, and comp. The calc class defines a square method that squares an integer. The second calc class overloads the square method to return a calc object with the squared value. The comp class defines a complex number with real and imaginary parts, along with an add method to sum two complex numbers. The main function demonstrates using the square and add methods to square an integer and sum two complex numbers respectively.
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/ 4

/*#include<iostream>

#include<math.h>

using namespace std;

class calc

public:

int n;

void square(int p)

cout<<p*p;

};

int main()

calc c;

c.n=5;

c.square(c.n);

return 0;

*/

/*

#include<iostream>
using namespace std;

class calc

public:

int n;

calc square(calc p)

calc r;

r.n=p.n*p.n;

return r;

};

int main()

calc c;

int a;

cin>>c.n;

c=c.square(c);

cout<<c.n;

return 0;

*/

#include<iostream>

using namespace std;


class comp

public:

int real,img;

void complex()

cout<<"enter real no and img no= ";

cin>>real>>img;

comp add(comp c,comp d)

comp a;

a.real=c.real+d.real;

a.img=c.img+d.img;

return a;

};

int main()

comp a,b,c;

a.complex();

b.complex();

c=c.add(a,b);

cout<<" sum of two complex no is = "<<c.real<<" + "<<c.img<<" i";

return 0;
}

You might also like