File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed
Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ using namespace std ;
3+
4+ class CN
5+ {
6+ private:
7+ int realpart; // /accessible within class
8+ int imgpart;
9+ public:
10+ void Inputrealpart (int a){
11+ realpart=a;
12+ }
13+
14+ void Inputimgpart (int a){
15+ imgpart=a;
16+ }
17+
18+ void PrintingCN (){
19+ cout<<realpart;
20+ if (imgpart>=0 ) cout<<" +" ;
21+ cout<<imgpart<<" i" <<endl;
22+ }
23+
24+ void Add (CN cn)// /parameter is cn
25+ {
26+ realpart=realpart+cn.realpart ; // /realpart of left side and argument is right side
27+ imgpart=imgpart+cn.imgpart ;
28+ }
29+
30+ CN operator +(CN input)// /argument is output
31+ {
32+ CN output;
33+ output.realpart =realpart+input.realpart ; // / left hand side cn1(realpart)(input)
34+ output.imgpart =imgpart+input.imgpart ;
35+ return output;
36+ }
37+ };
38+
39+ int main ()
40+ {
41+
42+ CN cn1,cn2,cn;
43+
44+ cn1.Inputrealpart (10 );
45+ cn1.Inputimgpart (20 );
46+
47+ cn2.Inputrealpart (-5 );
48+ cn2.Inputimgpart (-80 );
49+
50+ cn1.PrintingCN ();
51+ cn2.PrintingCN ();
52+
53+ cn1.Add (cn2);
54+ cn1.PrintingCN (); // / cn1 is updated
55+ cn2.PrintingCN (); // /unchanged because value added in cn1
56+
57+
58+ cout <<endl;
59+
60+ cn=cn1+cn2;
61+ cn1.PrintingCN ();
62+ cn2.PrintingCN ();
63+ cn.PrintingCN ();
64+
65+
66+ }
You can’t perform that action at this time.
0 commit comments