Thanks for your response.
The discussion thread was closed, so I have Start this new discussion.
As in the following program, I have do the addition of two matrix same as I want to do the addition of two integer number.
Expand|Select|Wrap|Line Numbers
- #include<iostream.h>
- #include<conio.h>
- class matrix
- {
- int a[3][3],i,j,k;
- public:
- void getdata();
- void putdata();
- matrix operator +(matrix);
- };
- void matrix::getdata()
- {
- cout<<"\n Enter the matrix :- ";
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- cin>>a[i][j];
- }
- }
- }
- void matrix::putdata()
- {
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- cout<<"\n Matrix is :- "<<a[i][j];
- }
- }
- }
- matrix matrix::operator +(matrix m)
- {
- matrix m1;
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- m1.a[i][j]=a[i][j]+m.a[i][j];
- }
- }
- return m1;
- }
- void main()
- {
- matrix m2,m3,m4;
- clrscr();
- m2.getdata();
- m3.getdata();
- m4=m2+m3;
- cout<<"\n Addition of matrix is ...";
- m4.putdata();
- getch();
- }
I have tried to addtion, and I have written my code as follow:
Expand|Select|Wrap|Line Numbers
- #include<iostream.h>
- #include<conio.h>
- class add
- {
- int a,b;
- public:
- void getdata();
- void putdata();
- add operator +(add);
- };
- void add::getdata()
- {
- cout<<"\n Enter the Marks of 1st Subject :- ";
- cin>>a;
- cout<<"\n Enter the Marks of 2nd Subject :- ";
- cin>>b;
- }
- void add::putdata()
- {
- cout<<"\n Marks of Subject1 is :- "<<a;
- cout<<"\n Marks of Subject2 is :- "<<b;
- }
- add add::operator +(add x)
- {
- return a+b;
- }
- void main()
- {
- add x;
- clrscr();
- cout<<"\n Addition is :- ";
- x.putdata();
- getch();
- }
Error : Error CPP\3.CPP 25: Cannot convert 'int' to 'add'
and 1 warning also occured
Warning :Warning CPP\3.CPP 26: Parameter 'x' is never used
What changes I have to do in my second program?