commit 045b55f1d02c76247b813c497d5796bd4a192262
parent d804059d4ceec67d320bb51fe3d1fd171d765770
Author: Agastya Chandrakant <acagastya@outlook.com>
Date: Fri, 22 Sep 2017 00:37:55 +0530
new file
Diffstat:
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/s3/oops/complex.cpp b/s3/oops/complex.cpp
@@ -0,0 +1,48 @@
+#include <iostream>
+
+class complex_num {
+ float Re;
+ float Im;
+ public:
+ void read(void);
+ void show(void);
+ void add(void);
+ void add(complex_num, complex_num);
+ void add(int, complex_num);
+};
+
+void complex_num::add(int a, complex_num k) {
+ Im = k.Im;
+ Re = k.Re + a;
+}
+
+void complex_num::add(complex_num a, complex_num b) {
+ Im = b.Im + a.Im;
+ Re = b.Re + a.Re;
+}
+
+void complex_num::read(void) {
+ std::cout << "Enter the real and imaginary parts of the complex number" << std::endl;
+ std::cin >> Re >> Im;
+}
+
+void complex_num::show(void) {
+ std::cout << "The sum resulted in: " << Re << " +i" << Im << std::endl;
+}
+
+int main() {
+ complex_num zeta1, zeta2, sigma1, sigma2;
+ int adder;
+
+ zeta1.read();
+ zeta2.read();
+ sigma1.add(zeta1, zeta2);
+ sigma1.show();
+
+ std::cout << "Enter an integer: ";
+ std::cin >> adder;
+
+ sigma2.add(adder, zeta1);
+ sigma2.show();
+ return 0;
+}