#include<iostream>
#include<string>
#include<malloc.h>
using namespace std;
typedef struct NodeList
{
string num;
string name;
int chinese;
int math;
int english;
struct NodeList* next;
}List;
void create(List* &L)
{
int i;
List* p, * s;
L = (List*)malloc(sizeof(List));
L->next = NULL;
p = L;
cout << "您正在创建数据..." << endl;
cout << "请输入您要创建的成绩信息,按住#结束" << endl;
cout << "学号" << '\t' << "姓名" << '\t' << "语文" << '\t' << "数学" << '\t' << "英语" << endl;
while (p->num!= "#")
{
cin >> p->num >> p->name >> p->chinese >> p->math >> p->english;
p = p->next;
}
while(p->num!="#")
{
s = (List*)malloc(sizeof(List));
s->num=p->num;
s->name = p->name;
s->chinese = p->chinese;
s->math = p->math;
s->english = p->english;
p->next = s;
p = s;
}
p->next = NULL;
}
void display(List* L)
{
List* p = L->next;
cout << "成绩表:" << endl;
cout << "学号" << '\t' << "姓名" << '\t' << "语文" << '\t' << "数学" << '\t' << "英语" << endl;
while (p!= NULL)
{
cout << p->num << '\t' << p->name << '\t' << p->chinese << '\t' << p->math << '\t' << p->english << endl;
p = p->next;
}
cout << endl;
}
void LengthList(List* L)
{
List* p = L;
int i = 0;
while (p->next != NULL)
{
i++;
p = p->next;
}
cout << "学生的个数为:" << i << endl;
}
int main()
{
NodeList *L;
create(L);
display(L);
LengthList(L);
system("pause");
return 0;
}
11-22
2836
07-18
2036