Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ help

Status
Not open for further replies.

ach8

Technical User
Jul 7, 2003
3
MY
Hi, I'm new to C++ and have try to write a small program for testing but is not working and with some error. Anyone can help??


#include <iostream.h>
#include <iomanip.h>

class Point
{
double x,y;
public:
double get_x(return x);
double get_y(return y);
};
//------------------------------------------------

Point::point (double x1, double y1)
{
x=x1;
y=y1;
}
void Point::changepos (doubble chaposx, double chaposy)
{
x+=chaposx;
y+=chaposy;
}
//-------------------------------------------------

void changepoint (Point)
{
if (T.get_x() < 0) || (T.get_y() < 0)
{ T.chapos (2,5);
cout << &quot;\nPoint x value is &quot;<<T.get_x();
cout << &quot;\nPoint y value is &quot;<<T.get_y();
}
else
cout << &quot;\nNo change of x and y&quot;;
}
//-------------------------------------------------

main ()
{
Point sample (6,-4);
cout << &quot;\nvalue of x : &quot;<<sample.get_x();
cout << &quot;\nvalue of y : &quot;<<sample.get_y();
changepoint (sample) ;
cout << &quot;\nvalue of x : &quot;<<sample.get_x();
cout << &quot;\nvalue of y : &quot;<<sample.get_y();
return 0;
}
 
u had many typo error:\ but there it is
//here indicate where i made changes

#include <iostream.h>
#include <iomanip.h>

class Point
{
double x,y;
public:
Point(double,double); //here
double get_x(){return x;}; //here
double get_y(){return y;}; //here
void changepos (double , double); //here
};
//------------------------------------------------

Point::point (double x1, double y1)
{
x=x1;
y=y1;
}
//------------------------------------------------
void Point::changepos (double chaposx, double chaposy)
{
x+=chaposx;
y+=chaposy;
}
//-------------------------------------------------

void changepoint (Point &T) //here
{
if ((T.get_x() < 0) || (T.get_y() < 0))
{ T.changepos (2,5); //here
cout << &quot;\nPoint x value is &quot;<<T.get_x();
cout << &quot;\nPoint y value is &quot;<<T.get_y();
}
else
cout << &quot;\nNo change of x and y&quot;;
}
//-------------------------------------------------

main ()
{
Point sample (6,-4);
cout << &quot;\nvalue of x : &quot;<<sample.get_x();
cout << &quot;\nvalue of y : &quot;<<sample.get_y();
changepoint (sample) ;
cout << &quot;\nvalue of x : &quot;<<sample.get_x();
cout << &quot;\nvalue of y : &quot;<<sample.get_y();
return 0;
}

jb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top