Develop a class called Complex that represents a complex number. An example of a complex number is 5 + 10 i (5 is the real part and 10 is the imaginary part of a complex number). Use public integer values to represent the real and imaginary parts of a complex number.
#include <iostream>
class complex
{
public:
int re, im;
complex() { re = 0; im = 0; }
complex(int r, int i) { re = r; im = i; }
void display()
{
std::cout<<"Real Number: "<<re<<", imaginary number: "<< im<<std::endl;
}
};
int main()
{
complex c({5, 10});
c.display();
return 0;
}
Comments
Leave a comment