永发信息网

帮我看看这段程序哪错了

答案:1  悬赏:50  手机版
解决时间 2021-07-18 01:54
  • 提问者网友:放下
  • 2021-07-17 11:06

#include <iostream>
using namespace std;
class people
{
private:
char sex;
int old;
float F;
public:
void set_people();
void show_people();
};
int main()
{
people p1;
p1.set_people();
p1.show_people();
return 0;
}
void people::set_people()
{
cout<<"请输入性别:"<<endl;
cout<<"请输入年龄:"<<endl;
cout<<"请输入分数:"<<endl;
cin>>sex;
cin>>old;
cin>>F;
}
void people::show_people()
{
cout<<"性别:"<<sex<<"年龄:"<<old<<"分数: "<<F<<endl;
}

总是不能正确输出

最佳答案
  • 五星知识达人网友:不如潦草
  • 2021-07-17 12:18

#include <iostream>
using namespace std;
class people
{
private:
char sex;
int old;
float F;
public:
void set_people(char sex,int old,float F);
void show_people();
};
int main()
{
people p1;
char sex;
int old;
float F;
cout<<"请输入性别:"<<endl;
cin>>sex;
cout<<"请输入年龄:"<<endl;
cin>>old;
cout<<"请输入分数:"<<endl;
cin>>F;
p1.set_people(sex,old,F);
p1.show_people();
return 0;
}
void people::set_people(char sex,int old,float F)
{
this->old=old;
this->sex=sex;
this->F=F;


}
void people::show_people()
{
cout<<"性别:"<<sex<<"年龄:"<<old<<"分数: "<<F<<endl;
}


类的初始化不是那样的。要先创建实例。

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯