Code:
#include<iostream>
using namespace std;
class list
{
public:
int number,score;
char name[10];
class list*next;
};
void create(list* head)
{
list* p=head;
while(1)
{
list* pp=new node;
if(!pp)
{
cout<<"erroe"<<endl;
exit(1);
}
cout<<"Please input the student ID:";
cin>>pp->number;
if(pp->number==0)
break;
else
{
cout<<"Pleast input the studnet name";
cin>>pp->name;
cout<<"Please input score:";
cin>>pp->score;
p->next=pp;
p=pp;
}
}
}
void show(list* head)
{
list* ptr=head;
cout<<"\n -- STUDNET ---"<<endl;
cout<<"ID\tNAME\tscore\n============================"<<endl;
while(ptr!=NULL)
{
cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl;
ptr=ptr->next;
}
}
int main()
{
list* head=NULL;
create(head);
show(head);
return 0;
}
Comment