20011598-136.. Quiz 02 Oop
20011598-136.. Quiz 02 Oop
BSSE SEC-2C
Question
Write a program by concluding and elaborating the concept of
operator overloading, you have studied.
Code
#include<iostream>
#include<stdio.h> using
complex
{ int real;
float image;
public:
void getdata()
};
complex temp;
temp.real=real+c1.real;
temp.image=image+c1.image; if
(temp.image>=0)
cout<<temp.real<<"+"<<temp.image<<"i\n";
else
cout<<temp.real<<temp.image<<"i\n";
}
= real-c1.image; temp.image=
image-c1.image; if
(temp.image>=0)
cout<<"\n temp.real"<<"+"<<temp.image<<"i\n";
else
cout<<temp.real<<temp.image<<"i\n";
int main()
{
complex c1, c2;
int n;
do
choice :: ";
cin>>n;
switch(n)
case 1:
c1.getdata();
c2.getdata();
break;
case
2:
c1+c2;
break;
case
3: c1-
c2;
break;
case
4:
exit(1);
break;
} while (n!=4);
return 0;