Do I NEED those two getInspector lines?
What would happen if I don't use those two lines?
Doesn't accessor functions defeat the purpose of having 'private' information?
I am just trying to understand the purpose of accessor functions.
#include <iostream>
using namespace std;
class Point
{
public:
void input();
void output();
void movePoint();
void rotatePoint();
int getInspectorXPoint();
int getInspectorYPoint();
private:
int x;
int y;
};
int main()
{
Point graph;
graph.input();
cout << "Starting graph points:" << endl;
graph.output();
graph.movePoint();
cout << "Graph points after move:" << endl;
graph.output();
graph.rotatePoint();
cout << "Graph points after 90 degree clockwise rotation:" << endl;
graph.output();
system("pause");
return 0;
}
void Point::input()
{
cout << "Enter x coordinate: ";
cin >> x;
cout << "Enter y coordinate: ";
cin >> y;
}
void Point::output()
{
cout << "x Coordinate: ";
cout << getInspectorXPoint() << endl;
cout << "y Coordinate: ";
cout << getInspectorYPoint() << endl;
}
void Point::movePoint()
{
int tempX, tempY;
cout << "How far do you want to move the x-Coordinate: ";
cin >> tempX;
cout << "How far do you want to move the y-Coordinate: ";
cin >> tempY;
x = x + tempX;
y = y + tempY;
}
void Point::rotatePoint()
{
int tempY;
tempY = x;
x = y;
y = -tempY;
}
int Point::getInspectorXPoint()
{
return x;
}
int Point::getInspectorYPoint()
{
return y;
}
This post has been edited by pesadilla143: 20 September 2009 - 10:38 AM

New Topic/Question
Reply




MultiQuote











|