Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
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
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;
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
Multidimensional Arrays - Every dimension is specified in separate brackets e.g. int arr[4][3]; This is a two-dimensional array with 4 as row dimension and 3 as
Define Automatic storage classes - computer programming? The Variables declared within function bodies are automatic by default and automatic variables are declared inside a fu
smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send
Recently social media has been flooded by fb posts, tweets, news articles about only thing demonetization.A great debate is ongoing over it. Most of the people discussing in social
#Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. #include float start_poi
What data structure would you mostly likely see in a nonrecursive implementation of a recursive algorithm?Minimum 100 words accepted#
3. Write a program to encrypt and decrypt strings of characters using the following ciphers: a) Caesar cipher b) Vigenere cipher c) Matrix transposition cipher Your program shoul
Virtual Base Classes This ambiguity can be resolved if the class derived have only one copy of the class base. This can be done by making the base class a virtual class. This k
Array types An array is a collection of objects of a one data type. The individual objects are accessed by their position in the array. This way of accessing is known as indexi
When you are designing a generic class to have or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or
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!
whatsapp: +91-977-207-8620
Phone: +91-977-207-8620
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd