Define a class Coord, which has x and y coordinates as its data members. Overload ++ and – operators for the Coord class. Create both its prefix and postfix forms.
CODING:
#include<iostream.h>
#include<conio.h>
class coor
{
int x,y;
public:
void get(int a,int b)
{
x=a;
y=b;
}
void disp()
{
cout<<"X="<<x<<"\nY="<<y;
}
coor operator ++();
coor operator --();
};
coor coor::operator ++()
{
coor c;
c.x=++x;//prefix
c.y=++y;//prefix
return c;
};
coor coor::operator --()
{
coor c;
c.x=x--;//postfix
c.y=y--;//postfix
return c;
};
void main()
{
clrscr();
coor o1,o2;
o1.get(4,9);
cout<<"Class o1:\n";
o1.disp();
o2=++o1;
cout<<"\nPrefix Expression after value.\nClass o1:\n";
o1.disp();
cout<<"\nClass o2:\n";
o2.disp();
o2=--o1;
cout<<"\nPostfix Expression after value.\nClass o1:\n";
o1.disp();
cout<<"\nClass o2:\n";
o2.disp();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class coor
{
int x,y;
public:
void get(int a,int b)
{
x=a;
y=b;
}
void disp()
{
cout<<"X="<<x<<"\nY="<<y;
}
coor operator ++();
coor operator --();
};
coor coor::operator ++()
{
coor c;
c.x=++x;//prefix
c.y=++y;//prefix
return c;
};
coor coor::operator --()
{
coor c;
c.x=x--;//postfix
c.y=y--;//postfix
return c;
};
void main()
{
clrscr();
coor o1,o2;
o1.get(4,9);
cout<<"Class o1:\n";
o1.disp();
o2=++o1;
cout<<"\nPrefix Expression after value.\nClass o1:\n";
o1.disp();
cout<<"\nClass o2:\n";
o2.disp();
o2=--o1;
cout<<"\nPostfix Expression after value.\nClass o1:\n";
o1.disp();
cout<<"\nClass o2:\n";
o2.disp();
getch();
}
Hey, try playing around with margin and padding property on the first element in your menu. You can also instead write a “margin-top or padding-top” CSS rule to the first element in menu to reduce “space” between them. Whatever helps you to achieve the right UI you want.
ReplyDeleteHope this helps!