-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path14_complex.cpp
72 lines (58 loc) · 1.37 KB
/
14_complex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// // Create a class ComplexNumber with instance member variables for the real and imaginary parts. Implement multiple constructors, including one default constructor and another that takes the real and imaginary parts separately.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Complex
class Complex
{
private:
// // instance member variables
double a;
double b;
public:
// // constructors
Complex()
{
a = b = 0;
}
Complex(double r)
{
a = b = r;
}
Complex(double r, double i)
{
a = r;
b = i;
}
// // instance member function to set compelx number
void setData(double r, double i)
{
a = r;
b = i;
}
// // instance member function to display compelx number
void showData()
{
cout << "\n"
<< a << " + " << b << "i" << endl;
}
};
// // Main Function Start
int main()
{
double real, imag;
// // Get complex number
cout << "\nEnter Real Part => ";
cin >> real;
cout << "\nEnter Imaginary Part => ";
cin >> imag;
Complex c1(real, imag); // create objects of Complex
// // display complex number
cout << "\n>>>>>>>> Complex Number <<<<<<<<<\n";
c1.showData();
cout << endl; // Add new line
cin.ignore();
return 0;
}
// // Main Function End