Classes Functions and Constructors Complex Game

QUESTION DESCRIPTION 

Rahul and Kuldeep plays a mathematical game with each other.

The game is all about complex numbers.Where they have to ask for real and imaginary part of two complex numbers, and display the real and imaginary parts of their sum.

Mandatory:

1.Create a class "Complex"

2.Create the following datamembers:
a)name
b)roll number,
c)book code and
d)counter

3.Create a CONSTRUCTOR to get the values of real and imaginary part of complex number.

4.Create a member function addcomplex() to add the real and imaginary values of complex number.

5.Create a member function displaycomplex() to display the result after addition.

6.Create two objects obj for the class Complex. Call the member function addcomplex() and displaycomplex() from the main function.

Refer sample testcases..

Note:

Programming Language need to be used:C++




TEST CASE 1 

INPUT
10 5
5 3
OUTPUT
10+5i
5+3i
15+8i

TEST CASE 2 

INPUT
11 4
5 6
OUTPUT
11+4i
5+6i
16+10i





#include <iostream>
using namespace std;
class complex
{
  int a,b,c,d;
  int e,f;
  public:
  complex()
  {
  cin>>a>>b>>c>>d;
  }
  void addcomplex()
  {
    e=a+c;
    f=b+d;
  }
  void displaycomplex()
  {
    printf("%d+%di\n%d+%di\n%d+%di",a,b,c,d,e,f);
  }
};
int main() 
{
  complex obj;
 obj.addcomplex();
  obj.displaycomplex();

 return 0;
}

Comments

Popular Posts