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
- Create a program that uses at least two functions that will be called from your main. This program is a number game program that asks for parts of your phone and after manipulati
requiredrequiredrequiredrequiredrequiredrequiredrequiredrequired
#pebblemerchant.h
Pure Virtual Functions An abstract class is one, which is used just for deriving some other classes. No object of this class is declared and used in the program. Likewise, ther
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.
A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci
boardcoloring with minimum color of 4
Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality. Th
Inline Functions Imagine a c program, which reads disk records having employee information. If this is a payroll application each employee record data is probably processed by
Inheritance is the process of forming new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class,
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: +1-415-670-9521
Phone: +1-415-670-9521
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd