0
WAP to overload + operator for add two no.
6 Respuestas
+ 11
Show your attempt first
+ 7
This is your fixed program
#include <iostream>
using namespace std;
class complex
{
private:
int a,b;
public:
void setdata(int x,int y)
{a=x; b=y;}
void showdata()
{cout<<"\na="<<a<<endl<<"b"<<b;}
complex add (complex c)
{
complex temp;
temp.a=a+c.a;
temp.b=b+c.b;
return(temp);
}
};
int main() {
complex c1,c2,c3;
c1.setdata(4,5);
c2.setdata (6,7);
c3=c1.add(c2);
c3.showdata ();
}
+ 6
The program which u posted it have 1 error . First thing in sololearn conio.h header not supporting so u should remove conio header file and getch also. Then in main function write int main instead in place of void main its not your mistakes its a playground error .
Your mistake is in line 17 where you where u write void setdata(int x ,int y) give some space between int x and int y .
Hope you understood
Thanks 😅
+ 5
Don't copy others code . Try by self else you cannot learn anything .
+ 1
#include <iostream>
#include<conio.h>
using namespace std;
class complex
{
private:
int a,b;
public:
void setdata(intx,inty)
{a=x; b=y;}
void showdata()
{cout<<"\na="<<a<<"b"<<b;}
complex add (complex c)
{
complex temp;
temp.a=a+c.a;
temp.b=b+c.b;
return(temp);
}
};
void main() {
complex c1,c2,c3;
c1.setdata(4,5);
c2.setdata (6,7);
c3=c1.add(c2);
c3.showdata ();
getch();
}
+ 1
thanks for your suggestion