Define a class complex with real and imaginary as two data member with default & parameterized constructors ,function to initialize display data of class .It should overload the '+' operator to add two complex objects. Write a program to demonstrate use of complex class.
Code :
#include<iostream.h>
#include<conio.h>
class complex
{
public:
float x,y;
complex()
{
x=0;
y=0;
}
complex(float real,float image)
{
x=real;
y=image;
}
void display(complex c)
{
cout<<"Real: "<<c.x<<" + "<<"Img: "<<c.y<<endl;
}
};
complex sum(complex c1,complex c2)
{
complex c3;
c3.x=c1.x+c2.x;
c3.y=c1.y+c2.y;
return c3;
}
void main()
{
clrscr();
complex A(1.1,2.1),B(1.2,2.2),C;
C=sum(A,B);
cout<<"For A:\n";
A.display(A);
cout<<"\nFor B:\n";
B.display(B);
cout<<"\nFor A+B:\n";
C.display(C);
getch();
}
Output :

Online Business Analyst Classes
ReplyDeleteLearn requirements elicitation, stakeholder management, and process modeling. Build job-ready BA skills with real case studies and UAT practice.
Enhance your data visualization skills with our tableau online training
ReplyDeletedesigned for beginners and professionals alike. Learn to create interactive dashboards, analyze data effectively, and boost your career opportunities with hands-on exercises.
Unlock the full potential of your data with our power bi live training
ReplyDeletedesigned to provide hands-on, real-time learning experiences. Gain practical skills and master interactive dashboards through expert-led Power BI live training sessions.
Boost your career with our sfdc admin course
ReplyDeletedesigned to equip you with hands-on Salesforce administration skills. Learn to manage users, data, and workflows efficiently in this comprehensive training.
Enhance your career with our sfdc developer course
ReplyDeletedesigned to teach Salesforce development from basics to advanced concepts. Gain hands-on experience in Apex, Visualforce, and Lightning components to become a proficient Salesforce developer.