-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01_complex.cpp
56 lines (45 loc) · 1.33 KB
/
01_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
// // Define a class Complex to represent a complex number. Declare instance member variables to store real and imaginary part of a complex number, also define instance member functions to set values of complex number and display values of complex number.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Complex
class Complex
{
private:
// // instance member variables
double real;
double imag;
public:
// // instance member function to set compelx number
void setComplex(double r, double i)
{
real = r;
imag = i;
}
// // instance member function to display compelx number
void displayComplex()
{
cout << "\n"
<< real << " + " << imag << "i" << endl;
}
};
// // Main Function Start
int main()
{
Complex c1; // create object of Complex
double real, imag;
// // Get Complex number
cout << "\n>>>>>>>> Enter A Complex Number <<<<<<<<<\n";
cout << "\nEnter Real Part => ";
cin >> real;
cout << "\nEnter Imaginary Part => ";
cin >> imag;
c1.setComplex(real, imag); // set complex number
cout << "\n>>>>>>>> Entered Complex Number <<<<<<<<<";
c1.displayComplex(); // display complex number
cout << endl; // Add new line
cin.ignore();
return 0;
}
// // Main Function End