C program to add two complex numbers , C/C++ Programming

Assignment Help:

Aim: To implement a program to add two complex numbers using constructors.

Code:                      

class complex

{

            int real;

            int img;

 

            public:

            complex(int r=0, int i=0);

            complex(complex c1, complex c2);

            void display();

};

 

complex :: complex(int r,int i)

{

 

            real=r;

            img=i;

}

complex :: complex(complex c1,complex c2)

{

            real=c1.real+c2.real;

            img=c1.img+c2.img;

}

void complex :: display()

{

            cout<

}

void main()

{

            int r1,r2,i1,i2;

            clrscr();

            cout<<"\nEnter first complex no:\nReal:";

            cin>>r1;

            cout<<"Imaginary:";

            cin>>i1;

            cout<<"\nEnter second complex no:\nReal:";

            cin>>r2;

            cout<<"Imaginary:";

            cin>>i2;

            complex c1(r1,i1);

            cout<<"\nFirst:\t\t";

            c1.display();

            cout<<"\nSecond:\t\t";

            complex c2(r2,i2);

            c2.display();

            complex c3(c1,c2);

            cout<<"\n----------------------\nAddition:\t";

            c3.display();

            getch();

}

Output:

Enter first complex no:

Real:25

Imaginary:3

Enter second complex no:

Real:12

Imaginary:71

 

First:          25+3i

Second:         12+71i

----------------------

Addition:       37+74i


Related Discussions:- C program to add two complex numbers

Least coast method, Find out initial basic feasible solution for the given ...

Find out initial basic feasible solution for the given transportation problem using Least Cost Method (LCM).

Visual c++, i want write visuaL c++ FOR MY ALGORITHM

i want write visuaL c++ FOR MY ALGORITHM

Program to display stock containing item code, THIS PROGRAM IS TO DISPLAY A...

THIS PROGRAM IS TO DISPLAY A STOCK CONTAINING ITEM CODE,ITEM NAME,PRICE AND ANOTHER STOCK WITH CODE & QUANTITY AND DISPLAY COMPLETE INFORMATION #include #include #include

Output, #include void func(int num, b=5) { auto int total=0; static ...

#include void func(int num, b=5) { auto int total=0; static int sum=0; for ( int i=num; i>0 ; i--) total+=i; sum+=total; cout

Described the scope resolution operator?, A: It allows a program to referen...

A: It allows a program to reference an identifier in global scope which has been hidden by another identifier along with the same name in the local scope.

Define the assignment operators in c language, Define the Assignment Operat...

Define the Assignment Operators in c language? The assignment operators can be used to assign a value to the variable and is represented by equal to (=) sign. The Assignment ex

How to double to int, char P[100]; double X=533.8*22500; sprintf(P...

char P[100]; double X=533.8*22500; sprintf(P,"%f %u",X,(unsigned int)X); MessageBox(P,"SSS"); //12010500.000 12010499

Program for hangman game problem, Program for Hangman Problem   #inclu...

Program for Hangman Problem   #include   #include   #include   #include   #include   static void playGame();   static void printMistakes(int n);   st

Prepare an ipad application clash of clans like game, Prepare an iPad appli...

Prepare an iPad application Clash of Clans like game I would like to prepare a free city building app with the in app purchase possibility. An example game could be Clash of Cla

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd