#include<iostream>
using std::cin;
using std::cout;
using std::endl;
const int SLEN = 30;
struct student{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[],int n)
{
int i= 0;
cout<<"enter fullname: ";
cin.getline(pa[0].fullname,SLEN);
while(i<n&&strcmp(pa[i].fullname," ")!=0)
{
//cin.get();
cout<<"enter hobby: ";
cin.getline(pa[i].hobby,SLEN);
cout<<"enter ooplevel";
cin>>pa[i].ooplevel;
cin.get();
i++;
cout<<"enter fullname";
cin.getline(pa[i].fullname,SLEN);
}
return i;
/*int count=0;
for(int i=0;i<n;i++)
{
cin>>pa[i].fullname;
cin>>pa[i].hobby;
cin>>pa[i].ooplevel;
if(strcmp((pa[i].fullname)," ")==0)
break;
count++;
}
return count;*/
}
void display1(student st)
{
cout<<"fullname:";
cout<<st.fullname<<endl;
cout<<"hobby:";
cout<<st.hobby<<endl;
cout<<"ooplevel:";
cout<<st.ooplevel<<endl;
}
void display2(const student *ps)
{
cout<<"fullname";
cout<<ps->fullname<<endl;
cout<<"hobby";
cout<<ps->hobby<<endl;
cout<<"ooplevel";
cout<<ps->ooplevel<<endl;
}
void display3(const student pa[],int n)
{
for(int i = 0;i<n;i++)
{
cout<<"fullname";
cout<<pa[i].fullname<<endl;
cout<<"hobby: ";
cout<<pa[i].hobby<<endl;
cout<<"ooplevel";
cout<<pa[i].ooplevel<<endl;
}
}
int main()
{
cout<<"enter class size: ";
int class_size;
cin>>class_size;
while(cin.get()!='\n')
continue;
student *ptr_stu =new student[class_size];
int entered =getinfo(ptr_stu,class_size);
for(int i=0;i<entered;i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu,entered);
delete []ptr_stu;
cout<<"done"<<endl;
system("pause");
}
7.9
最新推荐文章于 2024-07-12 15:23:49 发布