资源描述
C语言程序设计-基于链表的学生成绩管理系统优质资料
(可以直接使用,可编辑 优质资料,欢迎下载)
华北科技学院计算机系综合性实验
实 验 报 告
课程名称 C语言程序设计
实验学期 2021 至 2021 学年 第 二 学期
学生所在系部 计算机系
年级 2021 专业班级 计算机科学与技术B-111
学生姓名学号
任课教师
实验成绩
计算机系制
实验报告须知
1、 学生上交实验报告时,必须为打印稿(A4纸)。页面空间不够,可以顺延。
2、 学生应该填写的内容包括:封面相关栏目、实验地点、时间、目的、设备环境、内容、结果及分析等。
3、 教师应该填写的内容包括:实验成绩、教师评价等。
4、 教师根据本课程的《综合性实验指导单》中实验内容的要求,评定学生的综合性实验成绩;要求在该课程期末考试前将实验报告交给任课教师。综合性实验中,所涉及的程序,文档等在交实验报告前,拷贝给任课教师。任课教师统一刻录成光盘,与该课程的期末考试成绩一同上交到系里存档。
5、 未尽事宜,请参考该课程的实验大纲和教学大纲。
《C语言程序设计》课程综合性实验报告
开课实验室:基础五 2021年7月 6 日
实验题目
基于链表的学生成绩管理系统
一、实验目的
1、掌握链表的创建、遍历显示和清除;
2、掌握链表数据的文件保存、读取;
二、设备与环境
微型计算机、VC++6.0
三、实验内容
1、定义结构体,创建链表
struct xsnode
{
int xh;
char xm[15];
int gs;
int yy;
int wl;
struct xsnode *next;
};
2、根据以上链表结点结构,实现以下功能
a、学生学号、姓名、各门成绩的录入;
b、链表数据显示及清除;
c、链表数据的文件保存与读取;
四、实验结果及分析
1、运行结果
主菜单
数据显示
2、源程序
主函数
void main()
{
int xz=0;
struct xs *head;
head=init();
while(xz!=5)
{
menu();
scanf("%d",&xz);
switch(xz)
{
case 1:
create(head);
break;
case 2:
print(head);
break;
case 3:
save(head);
break;
case 4:
read(head);
break;
case 5:
printf("\n 系统退出,拜拜!\n ");
break;
default:
printf("\n 选择错误,请按任意键选择!\n ");
getch();
break;
}
}
fr(head);
free(head);
}
数据录入源代码
void create(struct xs *hd)
{
int xh,gs,yy,wl,i;
char xm[20];
struct xs *p;
fr(hd);
printf("\n 请输入学生个数:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("请输入%d个学生 of %d\n",i+1,num);
printf(" 学号:");
scanf("%d",&xh);
printf(" 姓名:");
scanf("%s",xm);
printf(" 高数:");
scanf("%d",&gs);
printf(" 英语:");
scanf("%d",&yy);
printf(" 物理:");
scanf("%d",&wl);
p=(struct xs *)malloc(sizeof(struct xs));
p->xh=xh;
strcpy(p->xm,xm);
p->gs=gs;
p->yy=yy;
p->wl=wl;
p->next=hd->next;
hd->next=p;
}
printf(" 录入数据完毕,请按任意键继续!\n ");
getch();
}
添加记录源代码
void print(struct xs *hd)
{
struct xs*p;
p=hd->next;
if(p!=NULL)
{
printf("\n 数据显示\n");
printf("**********************************************\n");
printf(" 学号 姓名 高数 英语 物理 平均分\n");
printf("**********************************************\n");
while(p!=NULL)
{
printf("%4d ",p->xh);
printf("%10s",p->xm);
printf("%8d",p->gs);
printf("%7d",p->yy);
printf("%6d",p->wl);
printf("%8.2f\n",(p->wl+p->wl+p->wl)/3.0);
p=p->next;
}
printf("**********************************************\n");
printf(" 链表显示完毕,请按任意键继续!\n");
getch();
}
else
printf("\n 当前链表为空,请先读取文件或创建链表!\n 按任意键继续!\n ");
}
查询记录源代码
void menu()
{
system("cls");
printf(" ****************************************\n");
printf(" * 学生成绩管理系统(1.0) *\n");
printf(" ****************************************\n");
printf(" * jb11-1 31 宋洁 2021-7-3 *\n");
printf(" ****************************************\n");
printf(" * 1-创建链表 *\n");
printf(" * 2-数据显示 *\n");
printf(" * 3-保存文件 *\n");
printf(" * 4-读取文件 *\n");
printf(" * 5-系统退出 *\n");
printf(" ****************************************\n");
printf(" 请选择操作(1-5:");
}
源程序
#include"stdio.h"
#include"stdlib.h"
#include<string.h>
#include"conio.h"
struct xs
{
int xh;
char xm[20];
int gs,yy,wl;
struct xs *next;
};
int num=0;
struct xs *init()
{
struct xs* hd;
hd=(struct xs *)malloc(sizeof(struct xs));
hd->next=NULL;
return hd;
}
void fr(struct xs *hd)
{
struct xs *p;
p=hd->next;
while(hd->next!=NULL)
{
p=hd->next;
hd->next=p->next;
free(p);
}
}
void create(struct xs *hd)
{
int xh,gs,yy,wl,i;
char xm[20];
struct xs *p;
fr(hd);
printf("\n 请输入学生个数:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("请输入%d个学生 of %d\n",i+1,num);
printf(" 学号:");
scanf("%d",&xh);
printf(" 姓名:");
scanf("%s",xm);
printf(" 高数:");
scanf("%d",&gs);
printf(" 英语:");
scanf("%d",&yy);
printf(" 物理:");
scanf("%d",&wl);
p=(struct xs *)malloc(sizeof(struct xs));
p->xh=xh;
strcpy(p->xm,xm);
p->gs=gs;
p->yy=yy;
p->wl=wl;
p->next=hd->next;
hd->next=p;
}
printf(" 录入数据完毕,请按任意键继续!\n ");
getch();
}
void save(struct xs *hd)
{
if(hd->next!=NULL)
{
struct xs *p=hd->next;
int i;
FILE *fp;
fp=fopen("yh.txt","w");
fprintf(fp,"%3d\n",num);
for(i=0;i<num;i++)
{
fprintf(fp,"%3d %12s %3d %3d %3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);
p=p->next;
}
fclose(fp);
printf("\n 保存文件完毕,请按任意键继续!\n ");
getch();
}
else
{
printf("\n 当前链表为空,不需要保存,请按任意键继续!\n ");
getch();
}
}
void read(struct xs *hd)
{
int i;
struct xs *p;
FILE *fp;
fr(hd);
fp=fopen("yh.txt","r");
fscanf(fp,"%3d\n",&num);
for(i=0;i<num;i++)
{
p=(struct xs *)malloc(sizeof(struct xs));
fscanf(fp,"%3d %12s %3d %3d %3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);
p->next=hd->next;
hd->next=p;
}
fclose(fp);
printf("\n 读取文件完毕,请按任意键继续!\n ");
getch();
}
void print(struct xs *hd)
{
struct xs*p;
p=hd->next;
if(p!=NULL)
{
printf("\n 数据显示\n");
printf("**********************************************\n");
printf(" 学号 姓名 高数 英语 物理 平均分\n");
printf("**********************************************\n");
while(p!=NULL)
{
printf("%4d ",p->xh);
printf("%10s",p->xm);
printf("%8d",p->gs);
printf("%7d",p->yy);
printf("%6d",p->wl);
printf("%8.2f\n",(p->wl+p->wl+p->wl)/3.0);
p=p->next;
}
printf("**********************************************\n");
printf(" 链表显示完毕,请按任意键继续!\n");
getch();
}
else
printf("\n 当前链表为空,请先读取文件或创建链表!\n 按任意键继续!\n ");
}
void menu()
{
system("cls");
printf(" ****************************************\n");
printf(" * 学生成绩管理系统(1.0) *\n");
printf(" ****************************************\n");
printf(" * jb11-1 31 宋洁 2021-7-3 *\n");
printf(" ****************************************\n");
printf(" * 1-创建链表 *\n");
printf(" * 2-数据显示 *\n");
printf(" * 3-保存文件 *\n");
printf(" * 4-读取文件 *\n");
printf(" * 5-系统退出 *\n");
printf(" ****************************************\n");
printf(" 请选择操作(1-5:");
}
void main()
{
int xz=0;
struct xs *head;
head=init();
while(xz!=5)
{
menu();
scanf("%d",&xz);
switch(xz)
{
case 1:
create(head);
break;
case 2:
print(head);
break;
case 3:
save(head);
break;
case 4:
read(head);
break;
case 5:
printf("\n 系统退出,拜拜!\n ");
break;
default:
printf("\n 选择错误,请按任意键选择!\n ");
getch();
break;
}
}
fr(head);
free(head);
}
3、试验收获
通过这次试验,我掌握了链表的创建、遍历显示和清除功能,掌握了链表数据的文件保存、读取,能够熟练的使用VC++6.0,对C程序有了更深的了解。
教 师 评 价
评定项目
A
B
C
D
评定项目
A
B
C
D
算法正确
界面美观,布局合理
程序结构合理
操作熟练
语法、语义正确
解析完整
实验结果正确
文字流畅
报告规范
题解正确
其他:
评价教师签名:
年 月 日
代码:
#include"stdio.h"
#include"stdlib.h"
#include<string.h>
#include"conio.h"
struct xs
{
int xh;
char xm[20];
int gs,yy,wl;
struct xs *next;
};
int num=0;
struct xs *init()
{
struct xs* hd;
hd=(struct xs *)malloc(sizeof(struct xs));
hd->next=NULL;
return hd;
}
void fr(struct xs *hd)
{
struct xs *p;
p=hd->next;
while(hd->next!=NULL)
{
p=hd->next;
hd->next=p->next;
free(p);
}
}
void create(struct xs *hd)
{
int xh,gs,yy,wl,i;
char xm[20];
struct xs *p;
fr(hd);
printf("\n 请输入学生个数:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("请输入%d个学生 of %d\n",i+1,num);
printf(" 学号:");
scanf("%d",&xh);
printf(" 姓名:");
scanf("%s",xm);
printf(" 高数:");
scanf("%d",&gs);
printf(" 英语:");
scanf("%d",&yy);
printf(" 物理:");
scanf("%d",&wl);
p=(struct xs *)malloc(sizeof(struct xs));
p->xh=xh;
strcpy(p->xm,xm);
p->gs=gs;
p->yy=yy;
p->wl=wl;
p->next=hd->next;
hd->next=p;
}
printf(" 录入数据完毕,请按任意键继续!\n ");
getch();
}
void save(struct xs *hd)
{
if(hd->next!=NULL)
{
struct xs *p=hd->next;
int i;
FILE *fp;
fp=fopen("yh.txt","w");
fprintf(fp,"%3d\n",num);
for(i=0;i<num;i++)
{
fprintf(fp,"%3d %12s %3d %3d %3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);
p=p->next;
}
fclose(fp);
printf("\n 保存文件完毕,请按任意键继续!\n ");
getch();
}
else
{
printf("\n 当前链表为空,不需要保存,请按任意键继续!\n ");
getch();
}
}
void read(struct xs *hd)
{
int i;
struct xs *p;
FILE *fp;
fr(hd);
fp=fopen("yh.txt","r");
fscanf(fp,"%3d\n",&num);
for(i=0;i<num;i++)
{
p=(struct xs *)malloc(sizeof(struct xs));
fscanf(fp,"%3d %12s %3d %3d %3d\n",p->xh,p->xm,p->gs,p->yy,p->wl);
p->next=hd->next;
hd->next=p;
}
fclose(fp);
printf("\n 读取文件完毕,请按任意键继续!\n ");
getch();
}
void print(struct xs *hd)
{
struct xs*p;
p=hd->next;
if(p!=NULL)
{
printf("\n 数据显示\n");
printf("**********************************************\n");
printf(" 学号 姓名 高数 英语 物理 平均分\n");
printf("**********************************************\n");
while(p!=NULL)
{
printf("%4d ",p->xh);
printf("%10s",p->xm);
printf("%8d",p->gs);
printf("%7d",p->yy);
printf("%6d",p->wl);
printf("%8.2f\n",(p->wl+p->wl+p->wl)/3.0);
p=p->next;
}
printf("**********************************************\n");
printf(" 链表显示完毕,请按任意键继续!\n");
getch();
}
else
printf("\n 当前链表为空,请先读取文件或创建链表!\n 按任意键继续!\n ");
}
void menu()
{
system("cls");
printf(" ****************************************\n");
printf(" * 学生成绩管理系统(1.0) *\n");
printf(" ****************************************\n");
printf(" * jb11-1 31 宋洁 2021-7-3 *\n");
printf(" ****************************************\n");
printf(" * 1-创建链表 *\n");
printf(" * 2-数据显示 *\n");
printf(" * 3-保存文件 *\n");
printf(" * 4-读取文件 *\n");
printf(" * 5-系统退出 *\n");
printf(" ****************************************\n");
printf(" 请选择操作(1-5:");
}
void main()
{
int xz=0;
struct xs *head;
head=init();
while(xz!=5)
{
menu();
scanf("%d",&xz);
switch(xz)
{
case 1:
create(head);
break;
case 2:
print(head);
break;
case 3:
save(head);
break;
case 4:
read(head);
break;
case 5:
printf("\n 系统退出,拜拜!\n ");
break;
default:
printf("\n 选择错误,请按任意键选择!\n ");
getch();
break;
}
}
fr(head);
free(head);
}
高级语言(C语言)课程设计说明书
起止日期: 2021年07月2日 至 2021年07月14日
题目
工资管理系统
学生姓名
班级
学号
成绩
通信与信息工程学院
一. 课程设计要求
课程设计系统组成及模块功能:工资管理程序主要完成对职工的工资信息录入,然后进行排序,统计,查询,计算税金等功能操作。
具体要求如下:
1. 职工录入工资信息包括:编号,姓名,基本工资,扣款,应发工资,税金,实发工资
2.程序主菜单如下:
"**************MENU*************", /*菜单的标题行*/
0. init list /*初始化单链表*/
1. Enter list /*输入数据,创建单链表*/
2. List all /*显示所有记录*/
3. Calc the salary /*计算实发工资*/
4. Search record on name /*查找职工信息数据*/
5. Delete a record /*删除记录*/
6. Sort on sfgz /*按实发工资升序排序*/
7. Computer ticket number /*计算所需票面数*/
8. Total on number /*分类合计*/
9. Quit /*退出*/
3. 要求定义如下函数,对应菜单功能
/******函数原型*********/
void init(); /*单链表初始化*/
void create(); /*创建单链表,输入数据*/
void calc(); /*计算实发工资*/
void delete(); /*删除*/
void search(); /*查找*/
void computer(); /*计算所需各种票面张数*/
void sort(); /*排序*/
void list(); /*显示所有数据*/
void print(SALARY *p); /*输出单条记录*/
float fax(float x); /*计算税金*/
void total(); /*分类合计*/
int menu_select(); /*主菜单*/
二. 程序的功能设计
此工资管理系统主要利用链表实现,由如下八个功能模块实现
1、输入模块。主要完成输入工资信息的工作,并存入链表中。
2、输出模块。主要完成对所有工人信息的输出。
3、修改模块。主要完成对职工信息的修改工作。
4、插入模块。主要完成对职工信息的插入工作。
5、查询模块。主要完成对某个职工信息的查询工作。
6、删除模块。主要完成对某退休或离职职工信息的删除。
7、排序模块。主要完成对所有职工按实发工资进行的升序或降序排列。
8、保存模块。主要完成对已经输入和修改或删除的保存文件。
9、退出。 退出系统
三. 程序的数据结构
本程序运用结构体、单项链表等数据结构。
职工信息结构体如下:
struct worker //定义数据结构//
{
char no[11]; //编号//
char name[15]; //姓名//
char xb[10]; //性别//
double jbgz; //基本工资//
double koukuan; //扣款//
double yfgz; //应发工资//
double shuijin; //税金//
double sfgz; //实发工资//
char post[10]; //职位//
struct worker *next;
};
typedef struct worker STU;//结构体类型名///
四、程序的函数设计
1. 函数的功能描述
int menu_select(void); //主菜单//
STU *append(STU *head); //添加记录//
STU *appendNode(STU *head);
void list(STU *head); //显示所有数据//
STU *modify(STU *head);//修改职工记录//
STU *modifyNode(STU *head);
void *search(STU *head); //查询职工信息//
void *no(STU *head); //编号查询//
void *name(STU *head); //姓名查询//
STU *dele(STU *head); //删除职工信息//
STU *deleNode(STU *head, char k[11]);
void *save(STU *head); //保存文件//
STU *insert(STU *head); //插入职工信息//
STU *tax(STU *head); //计算税金//
STU *calc(STU *head); //计算应发工资//
STU *total(STU *head); //计算实发工资//
STU *sort(STU *head); //对职工信息进行排序//
STU *insort(STU *head); //升序函数//
STU *desort(STU *head); //降序函数//
void *index(STU *head); //分类统计//
void *index1(STU *head);
void *index2(STU *head);
void *index3(STU *head);
void *index4(STU *head);
int user_ID(); //登录账户函数//
STU 表示结构体类型名
Head 表示链表的头结点
2. 、函数的调用关系
void main()
{ int ch;
char a;
STU *head = NULL;
system("color 02");//背景色/前景色的设置(0黑色、1蓝色、2绿色、3浅绿色、4红色、5紫色、6黄色、7白色、8灰色、9淡紫色、A淡绿色、B淡浅绿色、C淡红色、D淡紫色、E淡黄色、F亮白色)//
a=getchar();
while(!a);
system("cls");
user_ID();
while(1)
{
ch=menu_select();
switch(ch)
{
case 1:
head=append(head);
break; //制作工资表//
case 2:
list(head);
break; //输出所有的职工的信息 //
case 3:
head=modify(head);
break; //修改职工信息//
case 4:
head=insert(head);
break; //插入职工信息//
case 5:
search(head);
break; //查询职工信息//
case 6:
head=dele(head);
break;//删除职工信息//
case 7:
head=sort(head);
break; //对职工信息进行排序//
case 8:
save(head);
break; //保存文件//
case 9:
index(head);
break; //分类统计//
case 0:
exit(0); //退出//
default:printf("Input error!\n");
break;
}
}
五、程序源代码
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#include<memory.h>
#include<windows.h>
struct worker //定义数据结构//
{
char no[11]; //编号//
char name[15]; //姓名//
char xb[10]; //性别//
double jbgz; //基本工资//
double koukuan; //扣款//
double yfgz; //应发工资//
double shuijin; //税金//
double sfgz; //实发工资//
char post[10];//职位//
struct worker
展开阅读全文