7.9

#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.8
下一篇7.10
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭