c语言大作业非常经典
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "stdafx.h"
#include
#include
#include
#include
#define N 100
struct student
{
char name[10];
int num;
char sex[10];
float math;
float yingyu;
float zhengzhi;
float ywen;
float aver;
float sum;
}stu;
//菜单
void menu() /*便于操作员使用*/
{ /*清屏*/
system("cls");
printf(" * 欢迎使用学生成绩管理系统* \n");
printf(" * ======================= * \n");
printf(" * 请选择相应的功能: * \n");
printf(" * 1.成绩录入* \n");
printf(" * 2.查询成绩* \n");
printf(" * 3.修改成绩* \n");
printf(" * 4.插入成绩* \n");
printf(" * 5.报表输出* \n");
printf(" * 6.统计输出* \n");
printf(" * 7.删除操作* \n");
printf(" * 0.退出系统* \n" );
printf(" * ======================= * \n");
printf(" \n\n\n\n\n\n\n\n\n * * 机101-S1 林凯(201023701102) 制作* * \n");
}
//成绩录入
void input()
{
system("cls");
FILE *fp;
student xs; /*定义一个结构体变量来装从文件中读出来的数据*/
int c=1;
if((fp=fopen("student.dat","ab"))==NULL)
{
printf("can't open file!\n");exit(0);}
printf("\n 成绩录入");
printf("\n****************************************************");
while(c++) /*中间加油break,可使循环中断*/
{printf("\n 请输入您的姓名(姓名为end结束):");
scanf("%s",);
if(strcmp(,"end")==0) break;/*判断姓名是否为end,用字符串判断*/
printf("\n 请输入学号:");
scanf("%d",&xs.num);
printf("\n 性别:");
scanf("%s",&xs.sex);
printf("\n 请输入高数的成绩:");
scanf("%f",&xs.math);
printf("\n 请输入英语的成绩:");
scanf("%f",&xs.yingyu);
printf("\n 请输入政治的成绩:");
scanf("%f",&xs.zhengzhi);
printf("\n 请输入语文的成绩:");
scanf("%f",&xs.ywen);
xs.aver=0;/*给平均分变量赋初值*/
xs.aver=(xs.math+xs.yingyu+xs.zhengzhi+xs.ywen)/4;
xs.sum=0;
xs.sum=xs.math+xs.yingyu+xs.zhengzhi+xs.ywen;
fwrite(&xs,sizeof(stu),1,fp); //将成绩信息写入文件
system("cls");
}
fclose(fp);
}
void xingming()
{
FILE *fp;
student xs;
char name[10];
printf("\n 输入要查学生的姓名: ");scanf("%s",name);
if((fp=fopen("student.dat","rb"))==NULL)
{printf("can't open file!\n");exit(0);}
while(!feof(fp))
{
fread(&xs,sizeof(stu),1,fp);
if(strcmp(,name)==0)/*按姓名查询时判断输入的姓名是否存在,会循环从数据中找取*/
{
printf("\n 学生的信息如下:\n");
printf("\n %10s %6s %6s %6s %6s %6s %6s %6s %6s\n","姓名","学号","性别","高数","英语","政治","语文","平均成绩","总成绩");
printf("\n %10s %6d%6s %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",,xs.num,xs.sex, xs.math,xs.yingyu,xs.zhengzhi,xs.ywen,xs.aver,xs.sum);
break;
}
}
if(feof(fp))
printf("\n 查找失败!!!"); /*学生不存在*/
fclose(fp);
}
void xuehao()
{
FILE *fp;
student xs;
int num;
printf("\n 输入要查学生的学号: ");scanf("%d",&num);
if((fp=fopen("student.dat","rb"))==NULL)
{printf("can't open file!\n");exit(0);}
while(!feof(fp))
{
fread(&xs,sizeof(stu),1,fp);
if(xs.num==num)/*按学号查询时判断输入的学号是否存在,会循环从数据中找取*/
{
printf("\n 学生的信息如下:\n");
printf("\n %10s %6s %6s %6s %6s %6s %6s %6s %6s\n","姓名","学号","性别","高数","英语","政治","语文","平均成绩","总成绩");
printf("\n %10s %6d%6s %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n",,xs.num,xs.sex,xs .math,xs.yingyu,xs.zhengzhi,xs.ywen,xs.aver,xs.sum);
break;
}
}
if(feof(fp)) printf("\n 查找失败!!!");
fclose(fp);
}
//查询
void search()
{
char ch1;
system("cls");
printf(" 请输入按何种方式查询:\n");