0

WAP to overload + operator for add two no.

15th Jun 2020, 3:57 PM
unnati priya
unnati priya - avatar
6 Answers
+ 11
Show your attempt first
15th Jun 2020, 4:01 PM
ÃKR
ÃKR - avatar
+ 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 (); }
17th Jun 2020, 9:07 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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 😅
17th Jun 2020, 9:06 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 5
Don't copy others code . Try by self else you cannot learn anything .
17th Jun 2020, 8:59 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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(); }
15th Jun 2020, 4:24 PM
unnati priya
unnati priya - avatar
+ 1
thanks for your suggestion
17th Jun 2020, 9:49 AM
unnati priya
unnati priya - avatar