问题描述
请设计一个简单的学生成绩管理系统,要求系统实现以下功能:
学生信息包括学号、姓名、性别、语文、数学、英语。
插入学生信息:
Insert id name sex x y z 其中的参数分别为学号、姓名、性别、三门课的成绩,成绩为浮点数。
退出程序:
Quit或者Exit
输入
输入有多行,每行一条指令,指令格式如下:
Insert id name sex x y z
插入学生信息,分别为学号、姓名、性别和三门课(语文、数学、英语)的成绩。
Quit或者Exit
输出"Good bye!"后结束程序。
输出
输出有多行,对应命令的输出如下:
Insert id name sex x y z
插入后在单独的一行中输出"Insert:",然后在第二行中显示学生信息,数据之间用一个空格分开,成绩保留1位小数。
Quit或者Exit
在单独一行中输出"Good bye!"后结束程序。
输入样列
Insert 0911001 zhangsan F 87 78 65
Insert 0911003 Lisi F 77 72 55
Insert 0911002 zhaoliu F 97 90 55
Insert 0911004 Wangwu F 68 56 95
Quit
输出样例
Insert:
0911001 zhangsan F 87.0 78.0 65.0
Insert:
0911003 Lisi F 77.0 72.0 55.0
Insert:
0911002 zhaoliu F 97.0 90.0 55.0
Insert:
0911004 Wangwu F 68.0 56.0 95.0
Good bye!
#include<bits/stdc++.h>
using namespace std;
typedef struct Student{
char id[20];
char name[20];
char sex[2];
double x,y,z;
struct Student* next;
}Student;
void inputSingle(Student *s)
{
cin>>s->id>>s->name>>s->sex>>s->x>>s->y>>s->z;
}
void outputSingle(Student *s)
{
printf("%s %s %s ",s->id,s->name,s->sex);
printf("%.1f %.1f %.1f\n",s->x,s->y,s->z);
}
Student *createList()
{
Student *L;
L=(Student*)malloc(sizeof(Student));
L->next=NULL;
return L;
}
void insert(Student *L,Student *s)
{
Student *pre,*p;
pre=L;
p=L->next;
while(p!=NULL){
pre=p;
p=p->next;
}
s->next=pre->next;
pre->next=s;
}
void outputList(Student *L)
{
Student *p;
p=L->next;
while(p!=NULL){
outputSingle(p);
p=p->next;
}
}
int main()
{
string order;
Student *L,*s;
L=(Student *)malloc(sizeof(Student));
while(1){
cin>>order;
if(order=="Insert"){
puts("Insert:");
s=(Student *)malloc(sizeof(Student));
inputSingle(s);
insert(L,s);
outputSingle(s);
}
else{
puts("Good bye!");
break;
}
}
return 0;
}