nie-ii-year

lab stuff from undergrad second year.
git clone http://git.hanabi.in/repos/nie-ii-year.git
Log | Files | Refs | LICENSE

complex.cpp (914B)


      1 #include <iostream>
      2 
      3 class complex_num {
      4     float Re;
      5     float Im;
      6   public:
      7     void read(void);
      8     void show(void);
      9     void add(void);
     10     void add(complex_num, complex_num);
     11     void add(int, complex_num);
     12 };
     13 
     14 void complex_num::add(int a, complex_num k) {
     15   Im = k.Im;
     16   Re = k.Re + a;
     17 }
     18 
     19 void complex_num::add(complex_num a, complex_num b) {
     20   Im = b.Im + a.Im;
     21   Re = b.Re + a.Re;
     22 }
     23 
     24 void complex_num::read(void) {
     25   std::cout << "Enter the real and imaginary parts of the complex number" << std::endl;
     26   std::cin >> Re >> Im;
     27 }
     28 
     29 void complex_num::show(void) {
     30   std::cout << "The sum resulted in: " << Re << " +i" << Im << std::endl;
     31 }
     32 
     33 int main() {
     34   complex_num zeta1, zeta2, sigma1, sigma2;
     35   int adder;
     36 
     37   zeta1.read();
     38   zeta2.read();
     39   sigma1.add(zeta1, zeta2);
     40   sigma1.show();
     41 
     42   std::cout << "Enter an integer: ";
     43   std::cin >> adder;
     44 
     45   sigma2.add(adder, zeta1);
     46   sigma2.show();
     47   return 0;
     48 }