I need to modify this program (complete missing functions and anything that must be added) . I'll post my attemps and i want to know if it's correct and if there is any thing missing and need to be done .
thanks in advance
#include <iostream.h>
class point{
int x,y;
public:
point(int a=0, int b=0);
point(point &pnt);
~point();
};
class location{
const point org;
public:
location();
~location();
};
int point::poj=0;
int location::lob=0;
void main(){
location floc;
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - locatio - in use"<<endl;
point spoint(5,2);
point epoint(8,3);
location sloc(epoint);
if( !(spoint < epoint) )
cout<< "moved up - "<<endl;
else
cout << "moved down - "<<endl;
if(!sloc)
cout<<" the x-axis of this location not equal y-axis ..."<<endl;
point pnt = epoint;
location *lp = new location(pnt);
epoint = spoint;
cout<< "same location ..."<<endl;
cout<< " spoint: " <<endl<<spoint
<< " epoint: " <<endl<<epoint
<< " pnt : " <<endl<<pnt<<endl;
if(pnt == epoint)
cout<< "the new point is the same as the epoint ..."<<endl;
else if(!(spoint == pnt))
if(!pnt)
cout<<" the x-axies is not equal to y-axies ..."<<endl;
pnt.setx(8).sety(7);
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - location - in use"<<endl;
point *pp = new point(spoint);
epoint = *pp;
cin>>*pp>>spoint;
cout<<*pp<<pnt;
delete pp;
pp = new point[4];
delete lp;
if(pp[0] == pp[3]) cout<<"equal point ..."<<endl;
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - location - in use"<<endl;
for(int i=0; i<4; i++)
cout<<pp[i]<<endl;
delete [] pp;
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - location - in use"<<endl;
}
now thats my answer (in red )
#include <iostream.h>
class point{
int x,y;
static int poj;
public:
point(int a=0, int b=0);
point(point &pnt);
point(point &spoint);
point(point &epoint);
point operator=(point spoint);
point operator=(point epoint);
point operator==(point epoint);
point operator==(point pnt);
bool operator!();
friend istream operator>>(istream & in, point & spoint);
friend ostream operator<<(ostream & out , point & pnt);
static void potobjects();
~point();
};
class location{
const point org;
static int lob;
public:
bool operator!();
location();
~location();
};
int point::poj=0;
int location::lob=0;
point::point(int a=0,int b=0){
x=a;
y=b;
}
point::point(point &pnt)
{
x=0;
y=0;
}
point::point(point &spoint)
{
}
point::point(point &epoint)
{
}
void point::operator=(point &epoint){
x=epoint.x;
y=epoint.y;
}
void point::operator=(point &spoint){
x=spoint.x;
y=spoint.y;
}
void point::operator==(point &epoint){
x=epoint.x;
y=epoint.y;
}
void point::operator==(point &pnt){
x=pnt.x;
y=pnt.y;
}
bool point::operator!(){
if(!pnt)
return true;
else
return false;
}
ostream & operator<<(ostream & out , point & pnt){
out<<pnt;
return out;
}
istream & operator>>(istream & in , point & spoint){
in>>spoint;
return in;
}
point & point::setx(int){
int a=8;
x=a;
return (*this);
}
point & point::sety(int){
int b=7;
y=b;
return (*this);
}
point::~point(){
}
location::location(point &pnt):point org{
}
location::location(){
}
bool location::operator!(){
if(!sloc)
return true;
else
return false;
}
location::~location(){
}
void main(){
location floc;
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - locatio - in use"<<endl;
point spoint(5,2);
point epoint(8,3);
location sloc(epoint);
if( !(spoint < epoint) )
cout<< "moved up - "<<endl;
else
cout << "moved down - "<<endl;
if(!sloc)
cout<<" the x-axis of this location not equal y-axis ..."<<endl;
point pnt = epoint;
location *lp = new location(pnt);
epoint = spoint;
cout<< "same location ..."<<endl;
cout<< " spoint: " <<endl<<spoint
<< " epoint: " <<endl<<epoint
<< " pnt : " <<endl<<pnt<<endl;
if(pnt == epoint)
cout<< "the new point is the same as the epoint ..."<<endl;
else if(!(spoint == pnt))
if(!pnt)
cout<<" the x-axies is not equal to y-axies ..."<<endl;
pnt.setx(8).sety(7);
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - location - in use"<<endl;
point *pp = new point(spoint);
epoint = *pp;
cin>>*pp>>spoint;
cout<<*pp<<pnt;
delete pp;
pp = new point[4];
delete lp;
if(pp[0] == pp[3]) cout<<"equal point ..."<<endl;
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - location - in use"<<endl;
for(int i=0; i<4; i++)
cout<<pp[i]<<endl;
delete [] pp;
cout<< "there are - "<< point::potobjects() << " - point - in use"<<endl;
cout<< "there are - "<< location::lob << " - location - in use"<<endl;
}