33,311
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
using namespace std;
class people
{
public:
people()
{
/* string n,s;
int age;
cout<<"请分别输入姓名,年龄,性别"<<endl;
cin>>n>>a>>s;
name=n;
age=a;
sex=s;*/
}
void input()
{
string n,s;
int a;
cout<<"请分别输入姓名,年龄,性别"<<endl;
cin>>n>>a>>s;
name=n;
age=a;
sex=s;
}
void show ()
{
cout<<"name:"<<name<<"tage:"<<age<<"tsex"<<sex<<endl;
}
private:
string name;
int age;
string sex;
};
int main()
{
int num=1;
cout<<"多少人?"<<endl;
cin>>num;
people *student;
student=new people[num];
for(int a=num;a>=0;a--)
{
student[num].input();
}
for(int b=1;b<=num;b++)
{
student[b].show();
}
delete[]student;
return 0;
}
int main()
{
int num=1;
cout<<"多少人?"<<endl;
cin>>num;
people *student;
student=new people[num];
for(int a=0;a<num;a++)
{
student[num].input();
}
for(int b=0;b<num;b++)
{
student[b].show();
}
delete[]student;
return 0;
}