简单的成绩管理系统,上c语言课上完老师给的作业,没有存盘
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 300
struct student{
float no;//学号
char name[20];
int english;
int meth;
int charater;
float ave;
}stu[N]={0};
bool flag=true;
void input();
void show_all();
void delete_stu( );
void search();//输入姓名查找成绩
void over();
void insertion();
int main()
{
while(flag)
{
int n;
printf("************************************************\n");
printf("* menu : *\n");
printf("* 1,input student's name.... *\n");
printf("* 2,show all students *\n");
printf("* 3,delete one people name *\n");
printf("* 4,search *\n");
printf("* 5,over *\n");
printf("* 6,insertion *\n");
printf("************************************************\n");
scanf("%d",&n);
switch(n)
{
case 1:input();break;
case 2:show_all();break;
case 3:delete_stu();break;
case 4:search();break;
case 5:over();break;
case 6:insertion();break;
default:printf("misinput! try again!\n");
}
}
return 0;
}
/*初始化结构体*/
void input()
{
printf("input you want to ,if you want to over ,you can input '0' \n");
int i=1;
while(getchar()!='0')
{
printf(" %d studens you have get\n",i-1);
printf("no:");
scanf("%f",&stu[i].no);
printf("name:");
scanf("%s",&stu[i].name);
printf("English:");
scanf("%d",&stu[i].english);
printf("math:");
scanf("%d",&stu[i].meth);
printf("charater:");
scanf("%d",&stu[i].charater);getchar();
printf("successful ");
i++;
}
i--;
while(i)
{
stu[i].ave=(stu[i].english+stu[i].meth+stu[i].charater)/3.0;//计算平均值
i--;
}
}
void show_all()//显示所有学生的信息
{
printf("all students:\n");
int i=1;
while(stu[i].ave!=0)
{
printf("no:%.f,name:%s\n",stu[i].no,stu[i].name);
printf("english:%d, math:%d, charater:%d, ave:%f\n",stu[i].english,stu[i].meth,stu[i].charater,stu[i].ave);
i++;
}
}
void delete_stu( )
{
int n;
printf("please input serial numbel\n");
scanf("%d",&n);
while(stu[n].ave!=0)
{
stu[n]=stu[n+1];
n++;
}
printf("delete successful\n");
}
void search( )
{
float n;
printf("please input no you want to find");//输入学号查找对应的序列号
scanf("%f",&n);
int i=1;
while(stu[i].no!=n)
{
i++;
}
printf("sserial number:%d\n",i);
printf("no:%f,name:%s\n",stu[i].no,stu[i].name);
printf("english:%d,math:%d,charater:%d,ave:%f\n",stu[i].english,stu[i].meth,stu[i].charater,stu[i].ave);
}
void over()
{
flag=false;
printf("thank you !!!!");
}
void insertion()
{
int i=1;
while(stu[i].ave!=0){
i++;
}
printf("i=%d\n",i);
printf("no:");
scanf("%f",&stu[i].no);
printf("name:");
scanf("%s",&stu[i].name);
printf("English:");
scanf("%d",&stu[i].english);
printf("math:");
scanf("%d",&stu[i].meth);
printf("charater:");
scanf("%d",&stu[i].charater);getchar();
stu[i].ave=(stu[i].english+stu[i].meth+stu[i].charater)/3.0;
printf("successful \n");
}