求输出结果第二题

来源:百度知道 编辑:UC知道 时间:2024/05/16 02:04:49
#include<iostream.h>
class location {
public:
void init(int i=0, int j=0);
void set A(int n1){A=n1;}
void set B(int n2){B=n2;}
int get A(){return A;}
int get B(){return B;}
private:
int A,B;
};
void Location::init(int i,int j){
A=i;
B=j;
}
void main(){
location X, Y;
X.init(4);
X.setA(10);
cout<<X.getA()<<',' <<X..getB()<<end1;
Y.init(7,9);
Y.setB(8);
cout<<Y.getA()<<','<<Y.getB()<<end1;
}

你的程序有错误,我给你改了下,你看看
#include<iostream.h>
class location
{
private:
int A,B;
public:
void init(int i=0, int j=0);
void setA(int n1){A=n1;}
void setB(int n2){B=n2;}
int getA(){return A;}
int getB(){return B;}
};
void location::init(int i,int j)
{
A=i;
B=j;
}
void main()
{
location X, Y;
X.init(4);
X.setA(10);
cout<<X.getA()<<","<<X.getB()<<endl;
Y.init(7,9);
Y.setB(8);
cout<<Y.getA()<<","<<Y.getB()<<endl;
}
输出结果为:
10,0
7,8

题目有问题,去C++调试一下不就出来了

10,0
7,8