学生成绩信息管理c++
-------dyh--------
#include<iostream>
#include<cstring>
using namespace std;
struct student{
char id[11]; //学生学号
char name[10]; //学生姓名
char xy[14]; //学院
int c;
int jd;
int sx;
int sm;
student *next;
};
void insert_student(student *s)
{
int i=1,n;
cout<<"\n 请输入所添加的学生人数:";
cin>>n;
student *q;
for(;i<=n;i++)
{
q=new student;
while(s->next!=NULL)
s=s->next;
s->next=q;
cout<<"c请输入第:"<<i<<endl;
cout<<"c请输入学号:";
cin>>q->id;
cout<<endl;
cout<<"c姓名:";
cin>>q->name;
cout<<endl;
cout<<"c学院:";
cin>>q->xy;
cout<<endl;
cout<<"cc语言:";
cin>>q->c;
cout<<endl;
cout<<"c计算机导论:";
cin>>q->jd;
cout<<endl;
cout<<"c数学:";
cin>>q->sx;
cout<<endl;
q->sm=q->c+q->jd+q->sx;
q->next=NULL;
}
}
int out_student(student *s)
{
s=s->next;
int i=1,t=0;
while(s!=NULL)
{
cout<<"\n"<<"-----------"<<i<<"----------"<<endl;
cout<<"c输出第:"<<i<<endl;
cout<<"c学号:"<<s->id;
cout<<endl;
cout<<"c姓名:"<<s->name;
cout<<endl;
cout<<"c学院:"<<s->xy;
cout<<endl;
cout<<"cc语言:"<<s->c;
cout<<endl;
cout<<"c计算机导论:"<<s->jd;
cout<<endl;
cout<<"c数学:"<<s->sx;
cout<<endl;
cout<<"c总分:"<<s->sm;
cout<<endl;
s=s->next;
i++;
cout<<endl;
t++;
}
return t;
}
int modify_student(student *l)
{ int t;
char id[10];
cout<<"\n请输入要修改的学生学号:";
cin>>id;
while(l->next!=NULL)
{
if(strcmp(l->id,id)==0)
break;
l=l->next;
}
if(strcmp(l->id,id)==0)
{
cout<<"\n学号:"<<l->id;
cout<<"\n姓名:"<<l->name;
cout<<"\n学院:";
cin>>l->xy;
cout<<"\nc语言:";
cin>>l->c;
cout<<"\n计算机导论:";
cin>>l->jd;
cout<<"\n数学:";
cin>>l->sx;
l->sm=l->c+l->jd+l->sx;
t=1;
}else{
cout<<"\n没有此学生!";
t=0;
}
return t;
}
int select_student(student *l)
{
int t;
char id[10];
cout<<"\n请输入要查询的学生学号:";
cin>>id;
while(l->next!=NULL)
{
if(strcmp(l->id,id)==0)
break;
l=l->next;
}
if(strcmp(l->id,id)==0)
{
cout<<"\n学号:"<<l->id;
cout<<"\n姓名:"<<l->name;
cout<<"\n学院:"<<l->xy;
cout<<"\nc语言:"<<l->c;
cout<<"\n计算机导论:"<<l->jd;
cout<<"\n数学:"<<l->sx;
cout<<"\n总分:"<<l->sm;
t=1;
}else{
cout<<"\n没有此学生!";
t=0;
}
return t;
}
int clear_student(student *s)
{int t;
if(s->next!=NULL) //判断s是否为空
{
s->next=NULL;//delete[]s;
t=1; //清空成功
}
else
t=0; //失败
return t;
}
int main()
{
student *s;
s=new student; //开辟空间
s->next=NULL;
int n;
cout<<"============c++学生成绩管理============\n";
while(1)
{
cout<<"\n--------学生成绩查询设置--------";
cout<<endl;
cout<<"\n----->1 、添加\n";
cout<<"\n----->2 、修改\n";
cout<<"\n----->3 、查学生成绩\n";
cout<<"\n----->4 、输出学生信息\n";
cout<<"\n----->5 、清空学生信息\n";
cout<<"\n----->0 、退出\n";
cout<<"\n -------------------------------";
cout<<"请选择:";
cin>>n;
switch(n)
{
case 1:
insert_student(s);
cout<<"\n 添加成功...\n";
break;
case 2:
if(modify_student(s))
{ cout<<"\n 添加成功...\n";
break;
}else{
cout<<"\n 添加失败...\n";
break;
}
case 3:
if(select_student(s))
{
cout<<"\n 查询完毕...";
break;
}else{
cout<<"\n 查询失败...";
break;
}
case 4:
if(out_student(s))
{
cout<<"\n 输出成功...";
break;
}else{
cout<<"\n 输出失败...";
break;
}
case 5:
if(clear_student(s))
{
cout<<"\n 清空完成...";
break;
}else{
cout<<"\n 清空失败...";
break;
}
case 0:
return 0;
default : cout<<"输入错误....回车继续!";
}
}
return 0;
}
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17635018.html