#include<iostream>
usingnamespace std;
class point {
private:
int x, y;
public:
void init(int x1, int y1);
int getX();
int getY();
void print();
};
void point::init(int x1, int y1) {
x = x1;
y = y1;
}
int point::getX() {
return x;
}
int point::getY() {
return y;
}
void point::print() {
cout << "(" << x << "," << y << ")" << endl;
}
int main(){
int x1=2;
int x3=5;
point pt;
pt.print();
return 0;
}
#include<iostream>
usingnamespace std;
class point {
private:
int x, y;
public:
void init(int x1, int y1);
int getX();
int getY();
void print();
}pt;
void point::init(int x1, int y1) {
x = x1;
y = y1;
}
int point::getX() {
return x;
}
int point::getY() {
return y;
}
void point::print() {
cout << "(" << x << "," << y << ")" << endl;
}
int main(){
int x1=2;
int x3=5;
point pt;
pt.point::print();
return 0;
}
you're not calling print::init() so there will be no value assigned to x and y.
and yeah, the indentation needs to be fixed.. (generally in main() function )
1 2 3 4 5 6 7 8 9 10 11 12 13
// ...
int main() {
int x1=2; // indent 4 spaces after a ' { '
int x3=5; // do you mean x2 = 5 ?
point pt;
pt.init( x1, x2 ); // call init so values can be assigned to members x and y
pt.print(); // not point::print()
return 0;
}