Re: Post ur C/C++ Programs Here
guys i have a problem please help.
well can anyone please give me a program on 'classes with other classses as member data'.with a bit of explanation.
for eg you can take a rectangle and point class.
actually there is a program for it but i am not able to get it properly
can anyone please explain it me.
here is the program.
Code:
class point
{private:
int itsx; //to hold the x and y co-ordinate
int itsy;
public:
void setx(int x){itsx=x}
void sety(int y){itsy=y}
int getx()const{return itsx;}
int gety()const{return itsy;}
};
class rectangle
{private:
point itsupperleft; /* from here i am not understanding.if these are of
point itsupperright; type point then why the below its top bottom left etc
point itslowerleft; has been defined*/
point itslowerright;
int itstop;
int itsleft;
int itsbottom;
int its right;
public:
rectangle(int top,int left,int bottom,int right);
~rectangle(){}
*********the accessor functions defined here********
int getarea() const;
};
rectangle::rectangle(int top,etc etc.....)
{itstop=top;
itsleft=left;
etc etc.......;
itsupperleft.setx(left); /*why these declarations */
itsupperleft.sety(top);
itsupperright.setx(right);
itsupperright.sety(top);
etc etc.....;
}
int rectangle::getarea()const
{int width=its right-its left; /*how they are calculating it
int height=its top-its bottom; are they subtracting the two opposite
return(width*height); points*/
int main()
{body etc etc.......
}
i have pointed my doubts in the program only.
is there any other simpler way to write this program.or can anybody post any other simpler program.
i reffered sams publications jesse liberty and bradley jones book.pg no.165.
please help.