#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;
}
总是不能正确输出
#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;
}
类的初始化不是那样的。要先创建实例。
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息