I need help please

+1 itay zaguri · January 6, 2015
so the task is to make a class named point with x,y cords and main in which you simply enter the cords you'd like and get them shown in the screen.I also asked to make it using header and cpp files. i know its simple but i got it messed up a lil bit. i'm new to C++ though .. 
this is the Point.h file

#include<iostream>
using namespace std;
#ifndef POINT_H
#define POINT_H

class point{
private:
double xcord,ycord;
public:
void show() static;
void setx(double x);
void sety(double y);
double getx() (return x);
double gety() (return y);
}
#endif

this is the point.cpp file 

#include "point.h"

void point::show()
{
cout<<"X is "<<xcord
<<"\n Y is "<<ycord;
}
void point::setx(double x)
{
cin>>x;
}
void point::sety(double y)
{
cin>>y;
}

this is the main.cpp

#include<iostream>
using namespace std;
#include "point.h"

void main()
{
point p;
cout<<"X?";
p.setx();
cout<<"Y?";
p.sety();
}

thanks in advance

Post a Reply

Replies

Oldest  Newest  Rating
0 Danny AA · January 6, 2015
i will send you the solution and you can see where is your mistake.
0 Danny AA · January 6, 2015

#include "Point.h"

void Point::show()
{
cout << "X is " << xcord
<< "\n Y is " << ycord;
}
void Point::setx(double x)
{
cin >> x;
}
void Point::sety(double y)
{
cin >> y;
}

that's your class


#include<iostream>
using namespace std;
#ifndef POINT_H
#define POINT_H

class Point
{
private:
double xcord, ycord;
public:
void show();
void setx(double xcord);
void sety(double ycord);
double getx(){ return xcord; }
double gety(){ return ycord; }


#endif
};

h file


using namespace std;
#include<iostream>
#include "Point.h"

void main()
{
Point p;
double x=0, y=0;
cout << "X?";
p.setx(x);
cout << "Y?";
p.sety(y);


}


main
0 itay zaguri · January 6, 2015
thanks for the rapid answer!
 i got many errors trying to complying this including :

1>c:\users\eizzy\documents\visual studio 2010\projects\plusplus\matala1\point.h(14): error C2059: syntax error : 'return'
1>c:\users\eizzy\documents\visual studio 2010\projects\plusplus\matala1\point.h(14): error C2091: function returns function
1>c:\users\eizzy\documents\visual studio 2010\projects\plusplus\matala1\point.h(15): error C2059: syntax error : 'return'
1>c:\users\eizzy\documents\visual studio 2010\projects\plusplus\matala1\point.h(15): error C2091: function returns function
1>c:\users\eizzy\documents\visual studio 2010\projects\plusplus\matala1\main.cpp(5): error C2628: 'point' followed by 'void' is illegal (did you forget a ';'?)
1>c:\users\eizzy\documents\visual studio 2010\projects\plusplus\matala1\main.cpp(6): error C3874: return type of 'main' should be 'int' instead of 'point'
0 Danny AA · January 7, 2015

copy and past my code and let me know 


using namespace std;
#include<iostream>
#include "Point.h"

void main()
{
Point p;
double x=0, y=0;
cout << "X?";
p.setx(x);
cout << "Y?";
p.sety(y);


}

main file

#include<iostream>
using namespace std;
#ifndef POINT_H
#define POINT_H

class Point
{
private:
double xcord, ycord;
public:
void show();
void setx(double xcord);
void sety(double ycord);
double getx(){ return xcord; }
double gety(){ return ycord; }

};
#endif

header file

#include "Point.h"

void Point::show()
{
cout << "X is " << xcord
<< "\n Y is " << ycord;
}
void Point::setx(double x)
{
cin >> x;
}
void Point::sety(double y)
{
cin >> y;
}

cpp file
it runs good for me without any error
0 itay zaguri · January 9, 2015
it works perfectly !
 thanks a lot !
0 Danny AA · January 10, 2015
:)
  • 1

C++

106,983 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator