Question #36940

Create a class point with xcod and ycod as data members.include member functions to read and print the coordinate values as get point() and show point() respectively. write a main method to demonstrate point class

Expert's answer

#include <iostream>
#include <conio.h>
using namespace std;
class Point
{
public:
    int GetPointX() const { return xcod; }
    int GetPointY() const { return ycod; }
    void SetPoint(int newX, int newY)
    {
        xcod = newX;
        ycod = newY;
    }
private:
    int xcod;
    int ycod;
};
int main()
{
    Point point;
    cout << "So we created an object 'point'" << endl;
    cout << "Let's set coordinates 3 and 5 to X and Y respectively" << endl;
    point.SetPoint(3,5);
    cout << "We can check it's coordinates: " << endl;
    cout << "X = " << point.GetPointX() << endl;
    cout << "Y = " << point.GetPointY() << endl;
    _getch();
    return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS