Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- class ComplexNumber {
- private:
- double real;
- double imaginary;
- public:
- ComplexNumber(void) {
- real = 0.0;
- imaginary = 0.0;
- }
- ComplexNumber(double re, double img) {
- real = re;
- imaginary = img;
- }
- void setnumber(void) {
- cout << "Enter the real part\n";
- cin >> real;
- cout << "Enter the imaginary part\n";
- cin >> imaginary;
- printnumber();
- }
- void printnumber(void) {
- if (imaginary > 0.0) {
- cout << "The number is: " << real << " + " << imaginary << "i" << endl;
- }
- else {
- cout << "The number is: " << real << " " << imaginary << "i" << endl;
- }
- }
- double absolute_value(void) {
- double ab_val = sqrt(real*real + imaginary*imaginary);
- return ab_val;
- }
- void addition(double re, double img) {
- cout << "The number is: " << real + re << " " << imaginary + img << "i" << endl;
- }
- };
- int main(void) {
- ComplexNumber c1(2, -2);
- c1.printnumber();
- c1.addition(-2, 2);
- cout << c1.absolute_value();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement