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;

}

Er, I haven't looked entirely through everything, but you seem to have the right idea mostly.

Your copy constructor point::point( point &pnt ) should not be setting x and y to zero, but rather to the same values as the pnt variable's x and y.

You also have too many copy constructors: point::point( point &pnt ) point::point( point &spoint ) point::point( point &spoint ) It doesn't matter what you name the argument variable; all that matters is the type of the function. All of them have the same type: point::point( point & ) Pick one and stick with it. I think you are getting confused because you also have variables named spoint and epoint. Remember, a class is a data type, but spoint is an actual piece of data. You can compare it to the architectural blueprints to a house (the class or type) and an actual instance of the house (a variable). You can have as many houses of a specific type as you like, but the blueprints don't change.

The overloaded operator= is similar to a copy constructor, so the two functions should look very much the same. Watch your types. In the class definition you have prototyped point operator=( point ) but the type of the function below is void point::operator=( point & ) I know it is difficult to find clear information on how to overload various operators. Make sure you use your textbook. The type of the overloaded operator should be: point &operator=( const point & ) so a proper overload function might look like this

point &point::operator=( const point &pnt )
{
  x = pnt.x;
  y = pnt.y;
  return *this;
}

Well, that's enough verbiage from me. Check your code for those types of errors. Don't be afraid to ask your professor for help when you are unclear on a specific point.

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.