60 622
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #69760 in C++ for Urvashi

Question #69760
Implement a class complex no.which has two int nos.as private variables,ine for real part and other one for complex part.define input(),display()and constructor to initialize the object .include a member function to add two complex nos.
Expert's answer
class complex {
int re; // real part
int im; // complex part
public:
complex(int r, int c) {
re = r;
im = c;
}

void input() {
std::cout << "Enter real part: ";
std::cin >> re;
std::cout << "Enter complex part: ";
std::cin >> im;
}

void display() const {
std::cout << re;
if (im>0)
std::cout << " + ";
else if (im<0)
std::cout << " - ";

if (im!=0) {
std::cout << " i * " << abs(im);
}
}

void add(const complex& c) {
re += c.re;
im += c.im;
}
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions