your set_x and set_y functions seem a little confusing. The point is to set an x value and set a y value, why do they return and integer? i would go with something along the line of:
1 2 3 4 5 6 7 8 9 10 11 12 13
void set_x(int n)
{
x = n;
}
void set_y(int n)
{
y = n;
}
int get_x(){return x;}
int get_y(){return y;}
The number that you are seeing get printed out is just random garbage that happens to still be in the memory location where X is now staying. You should have a constructor that gets called to prevent this. It would also make for easier debugging.
class print {
public:
print() {
this->x = 0;
this->y = 0;
}
void set_x(int n) {
this->x = n;
}
void set_y(int n) {
this->y = n;
}
private:
int x;
int y;
};
int main() {
print p(); //at this point, x and y both equal 0 because the constructor was called.
p.set_x(5); //now, x = 5 and y = 0
}