• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

HELP ME debug!!!!!!

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

rapter_F22

Registered
Joined
Apr 28, 2002
Location
North Dakota
I am just learning how to program and i am having a very hard time learning how to us classes in c++.

I have writen a program but it refuses to work.

//---------------------------------------------------------------------------

#include <vcl.h>
#include <iostream.h>


class Point
{
private:
double x;
double y;
public:
double getX();
double getY();
Point(double xx, double yy);

};



int main()

{
int i;
int stop;
double x1;
double y1;
//trying to create 5 object variable of Point with arrary
Point P[5];

for (i=0;i<5;i++)
{
cin>>x1;
cin>>y2;
Point P=Point(x1,y1);
cout<<"For the point "<<i+1<<endl;
cout<<P.getX()<<" "<< P.getY()<<endl;

}

cin>>stop;
}

double Point::getX()
{
return x;
}

double Point::getY()
{
return y;
}

Point::point(double xx, double yy)
{
x=xx;
y=yy;
}


Thank you for any help!!!!!!!
 
change the line : Point P=Point(x1,y1);

to: Point P=Point.Point(x1,y1);

I'm pretty sure the compiler thinks your creating another Point type object.
 
Ok I did that but I am getting an error at point [5]. The error is cannnot find default constructor to initialize array element of type 'point'
 
This is a long shot:

make a public function called Point();

then its prototype will be:
Point::point() {x=y=0;}

change your Point(double xx, double yy);
to:
Setpoint(double xx, double yy);
and then change where needed.

again this is a long shot, but I think this will get around the initialization problem. I could help you more, but I just got to the chapter on default constructers about 2 hours ago :D. But I'll keep trying.
 
Modifications I have made have comments with three asterisks to mark the points where I did the modifications.

There were around 3 mistakes you made :)

Here's the code

#include <iostream.h>
#include <vcl.h>

class Point
{
private:
double x;
double y;
public:
double getX();
double getY();
// ***Give xx and yy a default value
// You didnt include this, thats why the line where you were
// trying to declare an array variable of type Point was flaging
// an error
Point(double xx=0,double yy=0);
};

Point :: Point(double xx, double yy)
{
x=xx;
y=yy;
}

double Point::getX()
{
return x;
}

double Point::getY()
{
return y;
}

int main()
{
int i;
int stop;
double x1;
double y1;
//trying to create 5 object variable of Point with arrary
Point P[5];

for (i=0;i<5;i++)
{
cin >> x1;

// *** You declared a variable by the name of y1 and were
// trying to use a variable by the name of y2 instead
cin >> y1;

// *** You did Point P=Point(x1,y1); WRONG. Its done like this
P = Point(x1,y1);

cout<<"For the point "<<i+1<<endl;

cout<<P.getX()<<" "<< P.getY()<<endl;
}

cin>>stop;

return 0; // ***Remember always to return something
}
 
THANK YOU YOU ARE A LIFE SAVER!!!!!!!!!!!!!!
WORD CAN'T EXPRESS HOW MUCH I AM THANKFULL FOR YOUR HELP!!!!!!

THANK YOU
 
Back