get() function or show() function ?!
Jun 30, 2011 at 6:54am UTC
Hi,
can i use get_xy() function in this program instead of show() function?
if so, what is the difference?
which one is better and why?
void showxy() {cout<< x << " ' " << y << endl;}
void get_xy(int &i,int &j) {i=x;j=y;}
full program code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <iostream>
using namespace std;
class coord
{
int x,y;
public :
coord () {x=0 ; y=0;}
coord (int i,int j) {x=i;y=j;}
void showxy() {cout<< x << " ' " << y << endl;}
coord operator +(coord ob)
{
coord temp;
temp.x = x + ob.x;
temp.y = y + ob.y;
return temp;
}
coord operator -(coord ob)
{
coord temp;
temp.x = x - ob.x;
temp.y = y - ob.y;
return temp;
}
coord operator =(coord ob)
{
x = ob.x;
y = ob.y;
return *this ;
}
};
int main()
{
coord ob1(10,10),ob2(5,3),ob3;
ob3=ob1+ob2;
ob3.showxy();
ob3=ob1-ob2;
ob3.showxy();
ob3=ob2;
ob3.showxy();
}
Last edited on Jun 30, 2011 at 6:56am UTC
Topic archived. No new replies allowed.