go语言学生管理系统 go语言图书管理系统
C语言设计学生成绩管理系统
在win-tc 下编辑的:
创新互联为客户提供专业的网站设计、做网站、程序、域名、空间一条龙服务,提供基于WEB的系统开发. 服务项目涵盖了网页设计、网站程序开发、WEB系统开发、微信二次开发、成都手机网站制作等网站方面业务。
程序如下:
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#define NULL 0
#define Q 10
#define LEN sizeof(struct student)
struct student /*定义一个学生考试信息的结构体*/
{char name[Q]; /*用来存放姓名的*/
char sex[Q]; /*用来存放性别的*/
long id; /*用来存放准考证号的*/
int score[4]; /*用来存放分数的*/
int total; /*用来存放总分数的*/
int m_c; /*用来存放名次的*/
struct student *next;/*定义指向下一个结构体的指针*/
};
int n; /*用来统计考生人数的*/
char ch[Q]; /*用来存放姓名的*/
struct student *creat() /*定义一个指向struct student的结构体指针函数*creat()用来修改考生信息.*/
{int i;
struct student *head,*p1,*p2;/*定义三个指向struct student的结构体指针*/
p1=p2=(struct student *)malloc(LEN);/*调用malloc()函数用来开辟一个新的存储单元*/
n=0;
printf("请输入学生考试信息!\n");
printf("请在姓名处键以\"!\"结束输入。\n");
printf("姓名:");
scanf("%s",ch);
head=NULL; /*给指针head赋初值*/
while (strcmp(ch,"!")!=0) /*调用字符比较函数strcmp()用来判断是否继续输入*/
{p1=(struct student *)malloc(LEN);/*调用malloc()函数用来开辟一个新的存储单元*/
strcpy(p1-name,ch); /*将循环结构前面输入的姓名复制到结构体名为p1的数组name中*/
printf("性别:");
scanf("%s",p1-sex);
printf("准考证号(8位):");
scanf("%ld",p1-id);/*将输入的准考证号存放到p1所指结构体的数组id中*/
printf("数学成绩:");
scanf("%d",p1-score[0]);/*将输入的数学成绩存放到p1所指结构体的数组score中*/
printf("物理成绩:");
scanf("%d",p1-score[1]);/*将输入的物理成绩存放到p1所指结构体的数组score中*/
printf("英语成绩:");
scanf("%d",p1-score[2]);/*将输入的英语成绩存放到p1所指结构体的数组score中*/
printf("C语言成绩:");
scanf("%d",p1-score[3]);/*将输入的C语言成绩存放到p1所指结构体的数组score中*/
p1-total=p1-score[0]+p1-score[1]+p1-score[2]+p1-score[3];/*计算总分 */
if(n==0)head=p1;/*如果是输入第一组学生考试信息就将指针p1赋给指针head*/
else p2-next=p1;/*否则将p1赋给p2所指结构体的next指针*/
p2=p1;/*将指针p1赋给指针p2*/
n++; /*将n的值加1*/
printf("姓名:");
scanf("%s",ch);/*将输入的姓名存放到字符数组ch中*/
}
p2-next=NULL;/*将p2所指结构体的next指针重新赋空值*/
return (head);/*将输入的第一组学生考试信息返回*/
}
void output(struct student *head) /*定义output()函数将考生的信息从头指针所指内容开始输出*/
{struct student *p;/*定义一个指向struct student的结构体指针p*/
printf("-----------------------------------------------------------------------\n");
printf(" *学生考试成绩信息表*\n");
printf("-----------------------------------------------------------------------\n"); /*71个“-”*/
printf("准考证号 姓 名 性别 数学 物理 英语 C语言 平均分 总分\n");
printf("-----------------------------------------------------------------------\n");
p=head;/*将头指针赋给p*/
if(head!=N)
Go语言的支持平台
LiteIDE是一款专门为Go语言开发的跨平台轻量级集成开发环境(IDE),由QT编写。
LiteIDE主要特点: 支持主流操作系统
Windows
Linux
MacOS X Go编译环境管理和切换
管理和切换多个Go编译环境
支持Go语言交叉编译 与Go标准一致的项目管理方式
基于GOPATH的包浏览器
基于GOPATH的编译系统
基于GOPATH的Api文档检索 Go语言的编辑支持
类浏览器和大纲显示
Gocode(代码自动完成工具)的完美支持
Go语言文档查看和Api快速检索
代码表达式信息显示F1
源代码定义跳转支持F2
Gdb断点和调试支持
gofmt自动格式化支持 其他特征
支持多国语言界面显示
完全插件体系结构
支持编辑器配色方案
基于Kate的语法显示支持
基于全文的单词自动完成
支持键盘快捷键绑定方案
Markdown文档编辑支持
实时预览和同步显示
自定义CSS显示
可导出HTML和PDF文档
批量转换/合并为HTML/PDF文档 Sublime Text 2(以下简称Sublime)+ GoSublime + gocode + MarGo的组合。
其优点有: 自动化提示代码。 保存的时候自动格式化代码,让您编写的代码更加美观,符合Go的标准。 支持项目管理 支持语法高亮 熟悉Java的读者应该对于idea不陌生,idea是通过一个插件来支持go语言的高亮语法,代码提示和重构实现。
寻高手帮忙做个关于学生成绩管理系统的C语言程序!
分是少了点,不过好心的我就帮帮你吧,呵呵!
你以上的功能我的程序里全有,你自己看看改改吧!
#include stdio.h
#include malloc.h
#include string.h
#include stdlib.h
#define InputRcd 1
#define UpdateRcd 2
#define SelectRcd 3
#define Exit 4
#define NAMELEN 16
#define CLASSLEN 6
struct record {
char classID[CLASSLEN];
int term;
char name[NAMELEN];
int chinese,math,english;
};
void showProgInform()
{
printf("-------------------------------------------------\n");
printf("| *** STUDENTS' SCORE PLATFORM *** |\n");;
printf("-------------------------------------------------\n\n");
}
void showMenu() {
system("cls");
showProgInform();
printf("Please select an operation fo the following MENU: \n");
printf(" 1. Input a record \n");
printf(" 2. Update a record\n");
printf(" 3. Select record(s)\n");
printf(" 4. Exit. \n");
}
void inputRecord() {
struct record inscr;
FILE * fp;
system("cls");
showProgInform();
printf("Mention: You are to add new record\n\n");
printf("Please input by the following instructions: \n");
printf("Class ID: ");
scanf("%s",inscr.classID);
printf("Term Number: ");
scanf("%d",(inscr.term));
printf("Student Name: ");
scanf("%s",inscr.name);
printf("Chinese score: ");
scanf("%d",(inscr.chinese));
printf("Math score: ");
scanf("%d",(inscr.math));
printf("English Score: ");
scanf("%d",(inscr.english));
getchar();
if((fp=(fopen("stu_score.rcd","ab+")))==NULL) {
printf("Input record failed!\n");
return;
}
fwrite(inscr,sizeof(struct record),1,fp);
fclose(fp);
if((fp=fopen("stu_score.txt","ab+"))==NULL) {
return;
}
fprintf(fp,"%s-%d %s: %d %d %d\r\n",inscr.classID,inscr.term,inscr.name,inscr.chinese,inscr.math,inscr.english);;
fclose(fp);
}
void showSingleRecord(struct record rc) {
printf("%s-%d %s: (CHI)%d (MAT)%d (ENG)%d\n",rc.classID,rc.term,rc.name,rc.chinese,rc.math,rc.english);
}
void updateRecord()
{
long fsize,arraySize,i;
struct record *allRecords,newRcd;
int hasFound = 0;
FILE * fp;
FILE * txt;
system("cls");
showProgInform();
if((fp = fopen("stu_score.rcd","rb")) == NULL ) {
printf("! No records , cannot operate\n");
return;
}
printf("Mention: You are to update record\n\n");
printf("Please the record you want to update by the follow mention: \n");
printf("Class Id: ");
scanf("%s",newRcd.classID);
printf("Term number: ");
scanf("%d",newRcd.term);
printf("Student name: ");
scanf("%s",newRcd.name);
fseek(fp,0,SEEK_END);
fsize = ftell(fp);
arraySize = fsize/(sizeof(struct record));
allRecords = (struct record *)calloc(arraySize,sizeof(struct record));
rewind(fp);
fread(allRecords,sizeof(struct record),arraySize,fp);
for(i=0;iarraySize;i++) {
if(strcmp(newRcd.classID,allRecords[i].classID)==0 newRcd.term==allRecords[i].term strcmp(newRcd.name,allRecords[i].name)==0) {
printf("Find the matching record: ");
showSingleRecord(allRecords[i]);
printf("Input new Score: \n");
printf("New Chinese Score: ");
scanf("%d",(allRecords[i].chinese));
printf("New Math Score: ");
scanf("%d",(allRecords[i].math));
printf("New English Score: ");
scanf("%d",(allRecords[i].english));
printf("After update ,the records is : \n\t");
showSingleRecord(allRecords[i]);
printf("\n");
hasFound = 1;
break;
}
}
fclose(fp);
if(!hasFound) {
printf("No matching record has found!\n");
free(allRecords);
return;
}
if((fp = fopen("stu_score.rcd","w"))==NULL) {
printf("Write file stu_score.rcd failed\n");
return;
}
if((txt = fopen("stu_score.txt","w"))==NULL) {
printf("Write file stu_score.txt failed\n");
return;
}
fwrite(allRecords,sizeof(struct record),arraySize,fp);
for(i=0;iarraySize;i++) {
fprintf(txt,"%s-%d %s: %d %d %d\r\n",allRecords[i].classID,allRecords[i].term,allRecords[i].name,allRecords[i].chinese,allRecords[i].math,allRecords[i].english);
}
free(allRecords);
fclose(fp);
fclose(txt);
}
void showSelectMenu(char classID[],int term) {
system("cls");
showProgInform();
printf("Mention: All the following opertion based on classID: %s,Term: %d\n\n",classID,term);
printf("Mention: You are to select the records\n\n");
printf("\t Please choose an operation: \n");
printf("\t 1. Select all records of the classID.\n");
printf("\t 2. Sort by the average score.\n");
printf("\t 3. Select no passed record.\n");
printf("\tOther. Return the high level menu.\n\n");
}
void showStatistic(struct record *r ,long size,char classID[],int term) {
int total;
float ave;
long i;
system("cls");
showProgInform();
printf("All records for class: %s,term: %d; total record nubmer: %ld\n",classID,term,size);
printf("********************************************************\n");
for(i=0;isize;i++) {
total = r[i].chinese+r[i].english +r[i].math ;
ave = (float)total/3;
printf(" %s: (CHI)%d (MAT)%d (ENG)%d (Total)%d (Ave)%.2f\r\n",r[i].name,r[i].chinese,r[i].math,r[i].english,total,ave);
}
printf("********************************************************\n\n");
printf("Press Enter to return Select submenu\n");
getchar();
}
void sortSelectByAve(struct record * r,long size) {
FILE *fp;
struct record temp;
float outerAve ,innerAve;
int total;
long i,j;
system("cls");
showProgInform();
printf("\nSorted the records by average score\n");
for(i=0;isize;i++) {
outerAve = (float)(r[i].chinese+r[i].math+r[i].english)/3;
for(j=i+1;jsize;j++) {
innerAve = (float)(r[j].chinese+r[j].math+r[j].english)/3;
if(innerAve outerAve) {
strcpy(temp.name,r[j].name);
temp.chinese = r[j].chinese;
temp.math = r[j].math ;
temp.english = r[j].english ;
strcpy(r[j].name,r[i].name);
r[j].chinese = r[i].chinese ;
r[j].math = r[i].math ;
r[j].english = r[i].english ;
strcpy(r[i].name,temp.name);
r[i].chinese = temp.chinese ;
r[i].math = temp.math ;
r[i].english = temp.english ;
}
}
}
printf("\nshow sorted records \n");
printf("********************************************\n");
for(i=0;isize;i++) {
total = r[i].chinese + r[i].math + r[i].english ;
innerAve = (float)total/3;
printf("%s: %d %d %d %d %f\n",r[i].name,r[i].chinese,r[i].math,r[i].english,total,innerAve);
}
printf("********************************************\n");
printf("write sorted records to \"sorted.txt\"\n");
if((fp = fopen("sorted.txt","w"))== NULL) {
printf("open sort.txt failed\n");
return;
}
for(i=0;isize;i++) {
total = r[i].chinese + r[i].math + r[i].english ;
innerAve = (float)total/3;
fprintf(fp,"(CLASS-TERM)%s-%d (NAME)%s: (CHI)%3d (MAT)%3d (ENG)%3d (TOTAL)%4d (AVERG)%.2f\r\n",r[i].classID,r[i].term,r[i].name,r[i].chinese,r[i].math,r[i].english,total,innerAve);
}
printf("write file sorted.txt finished\n");
fclose(fp);
printf("\nPress any key to return Select subMenu\n");
}
void noPass(struct record * r,int size) {
long i=0,j=0;
FILE * fp;
if((fp=fopen("no-pass.txt","w"))==NULL) {
printf("create no-pass.txt failed");
return;
}
system("cls");
showProgInform();
printf("Mention: The following operation will be all on the classId and term you input\n\n");
printf("\nShow student that one subject is no-pass\n");
printf("***********************************************\n");
for(i=0;isize;i++) {
if(r[i].chinese 60 || r[i].math60 || r[i].english 60) {
printf("%s-%d %s: ",r[i].classID,r[i].term,r[i].name);
fprintf(fp,"%s-%d %s: ",r[i].classID,r[i].term,r[i].name);
if(r[i].chinese 60 ) {
printf("(Chinese)%d ",r[i].chinese);
fprintf(fp,"(Chinese)%d ",r[i].chinese );
}
if(r[i].math 60) {
printf("(Math)%d ",r[i].math);
fprintf(fp,"(Math)%d ",r[i].math);
}
if(r[i].english 60) {
printf("(English)%d",r[i].english);
fprintf(fp,"(English)%d",r[i].english);
}
printf("\r\n");
fprintf(fp,"\r\n");
}
}
printf("***********************************************\n");
fclose(fp);
printf("Press Enter to return \"Select\" submenu\n");
}
void selectRecord() {
char classID[CLASSLEN];
int term;
FILE * fp;
long fsize=0,arraySize=0,thisSize=0,i=0,j=0;
struct record *allRcd,*thisClass;
system("cls");
showProgInform();
printf("Mention: The following operation will be all on the classId and term you input\n\n");
printf("Mention: please operate by the following instructions\n\n");
printf("Input ClassID: ");
scanf("%s",classID);
printf("Input term number: ");
scanf("%d",term);
if((fp=fopen("stu_score.rcd","r"))==NULL) {
printf("\nWarining: No record exists!\n");
return;
}
fseek(fp,0,SEEK_END);
fsize = ftell(fp);
arraySize = fsize/(sizeof(struct record));
allRcd = (struct record *)calloc(arraySize,sizeof(struct record));
rewind(fp);
fread(allRcd,sizeof(struct record),arraySize,fp);
printf("Press Enter to show the sub menu of Select menu\n");
for(i=0;iarraySize;i++) {
if(strcmp(classID,allRcd[i].classID)==0 term==allRcd[i].term) {
thisSize++;
}
}
if(thisSize==0) {
printf("\nWaring: No record for Class %s Term %d\n",classID,term);
fclose(fp);
free(allRcd);
return;
}
thisClass = (struct record *)calloc(thisSize,sizeof(struct record));
j=0;
for(i=0;iarraySize;i++) {
if(strcmp(classID,allRcd[i].classID)==0 term==allRcd[i].term ) {
strcpy(thisClass[j].classID,classID) ;
thisClass[j].term = term ;
strcpy(thisClass[j].name,allRcd[i].name);
thisClass[j].chinese = allRcd[i].chinese;
thisClass[j].math = allRcd[i].math ;
thisClass[j].english = allRcd[i].english ;
j++;
}
}
free(allRcd);
/////////////////////////////////////////////////////////////
getchar();
getchar();
while(1) {
system("cls");
showProgInform();
printf("Mention: The following operation will be all on the classId and term you input\n\n");
showSelectMenu(classID,term);
switch(getchar()) {
case '1':
getchar();
showStatistic(thisClass,thisSize,classID,term);
break;
case '2':
getchar();
sortSelectByAve(thisClass,thisSize);
getchar();
break;
case '3':
getchar();
noPass(thisClass,thisSize);
printf("0: Press 0 to return \"Select\" submenu\n");
if(getchar()=='0')
break;
default:
getchar();
return;
}
}
free(thisClass);
fclose(fp);
}
void go_on() {
printf("Press Enter to continue\n");
getchar();
}
void main() {
showProgInform();
while(1) {
showMenu();
switch(getchar()) {
case '1':
getchar();
inputRecord();
go_on();
break;
case '2':
getchar();
updateRecord();
getchar();
go_on();
break;
case '3':
getchar();
selectRecord();
getchar();
go_on();
break;
case '4':
getchar();
//exit(1);
return;
default:
getchar();
printf("Wrong Option! input again\n");
go_on();
break;
}
}
}
求救 学生成绩管理C程序
/*头文件*/
#include stdio.h
#includedos.h
#includestdlib.h /*其它说明*/
#includestring.h /*字符串函数*/
#includemem.h /*内存操作函数*/
#includectype.h /*字符操作函数*/
#includealloc.h /*动态地址分配函数*/
#define LEN sizeof(STUDENT)
typedef struct stu /*定义结构体数组用于缓存数据*/
{char num[6];
char name[5];
int score[3];
int sum;
float average;
int order;
struct stu *next;
}STUDENT;
/*函数原型*/
STUDENT *init(); /*初始化函数*/
int menu_select(); /*菜单函数*/
STUDENT *create(); /*创建链表*/
void print(STUDENT *head); /* 显示全部记录*/
void search(STUDENT *head); /*查找记录*/
STUDENT *delete(STUDENT *head); /*删除记录*/
STUDENT *sort(STUDENT *head); /*排序*/
STUDENT *insert(STUDENT *head,STUDENT *new); /*插入记录*/
void save(STUDENT *head); /*保存文件*/
STUDENT *load(); /*读文件*/
/*主函数界面*/
main()
{STUDENT *head,new;
head=init(); /*链表初始化,使head的值为NULL*/
for(;;) /*循环无限次*/
{switch(menu_select())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:search(head);break;
case 4:head=delete(head);break;
case 5:head=sort(head);break;
case 6:head=insert(head,new);break; /*new表示返回地址*/
case 7:save(head);break;
case 8:head=load(); break;
case 9:exit(0); /*如菜单返回值为9则程序结束*/
}
}
}
/*初始化函数*/
STUDENT *init()
{
return NULL; /*返回空指针*/
}
/*菜单选择函数*/
menu_select()
{int n;
struct date d; /*定义时间结构体*/
getdate(d); /*读取系统日期并把它放到结构体d中*/
printf("\n按任一键进入主菜单...... \npress any key to enter the menu......"); /*按任一键进入主菜单*/
getch(); /*从键盘读取一个字符,但不显示于屏幕*/
clrscr(); /*清屏*/
printf("********************************************************************************\n");
printf("\t\t 欢迎 Welcome to\n");
printf("\n\t\t\t 使用学生管理系统1.0\n\n\t\t\t\t\t-----------景炎中学计算机组WJQ\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. 输入学生成绩记录 Enter the record\n"); /*输入学生成绩记录*/
printf("\t\t\t2. 显示 Print the record\n"); /*显示*/
printf("\t\t\t3. 寻找 Search record on name\n"); /*寻找*/
printf("\t\t\t4. 删除 Delete a record\n"); /*删除*/
printf("\t\t\t5. 排序 Sort to make new a file\n"); /*排序*/
printf("\t\t\t6. 插入 Insert record to list\n"); /*插入*/
printf("\t\t\t7. 保存 Save the file\n"); /*保存*/
printf("\t\t\t8. 读取 Load the file\n"); /*读取*/
printf("\t\t\t9. 退出 Quit\n"); /*退出*/
printf("\n\t\t 制作吴俊遒WJQ Made by Wu Junqiu.\n");
printf("********************************************************************************\n");
printf("\t\t\t\t当前系统日期:%d\\%d\\%d\n",d.da_year,d.da_mon,d.da_day); /*显示当前系统日期*/
do{
printf("\n\t\t\t输入你的选择Enter your choice(1~9):");
scanf("%d",n);
}while(n1||n9); /*如果选择项不在1~9之间则重输*/
return(n); /*返回选择项,主函数根据该数调用相应的函数*/
}
/*输入函数*/
STUDENT *create()
{int i,s;
STUDENT *head=NULL,*p; /* 定义函数.此函数带回一个指向链表头的指针*/
clrscr();
for(;;)
{p=(STUDENT *)malloc(LEN); /*开辟一个新的单元*/
if(!p) /*如果指针p为空*/
{printf("\n输出内存溢出. Out of memory."); /*输出内存溢出*/
return (head); /*返回头指针,下同*/
}
printf("输入学号Enter the num(0:list end):");
scanf("%s",p-num);
if(p-num[0]=='0') break; /*如果学号首字符为0则结束输入*/
printf("输入名字Enter the name:");
scanf("%s",p-name);
printf("请输入3门成绩Please enter the %d scores\n",3); /*提示开始输入成绩*/
s=0; /*计算每个学生的总分,初值为0*/
for(i=0;i3;i++) /*3门课程循环3次*/
{
do{
printf("成绩score%d:",i+1);
scanf("%d",p-score[i]);
if(p-score[i]0 || p-score[i]100) /*确保成绩在0~100之间*/
printf("数据错误,请重新输入 Data error,please enter again.\n");
}while(p-score[i]0 || p-score[i]100);
s=s+p-score[i]; /*累加各门成绩*/
}
p-sum=s; /*将总分保存*/
p-average=(float)s/3; /*先用强制类型转换将s转换成float型,再求平均值*/
p-order=0; /*未排序前此值为0*/
p-next=head; /*将头结点做为新输入结点的后继结点*/
head=p; /*新输入结点为新的头结点*/
}
return(head);
}
/* 显示全部记录函数*/
void print(STUDENT *head)
{int i=0; /* 统计记录条数*/
STUDENT *p; /*移动指针*/
clrscr();
p=head; /*初值为头指针*/
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Sc1 | Sc2 | Sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
i++;
printf("| %3d | %4s | %-4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
i, p-num,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
p=p-next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
}
/*查找记录函数*/
void search(STUDENT *head)
{STUDENT *p; /* 移动指针*/
char s[5]; /*存放姓名用的字符数组*/
clrscr();
printf("请输入个姓名来查找. Please enter name for searching.\n");
scanf("%s",s);
p=head; /*将头指针赋给p*/
while(strcmp(p-name,s) p != NULL) /*当记录的姓名不是要找的,或指针不为空时*/
p=p-next; /*移动指针,指向下一结点*/
if(p!=NULL) /*如果指针不为空*/
{printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p-num,p-name,p-score[0],p-score[1],p-score[2],p-sum,p-average,p-order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\n没有该学生 There is no num %s student on the list.\n",s); /*显示没有该学生*/
}
/*删除记录函数*/
STUDENT *delete(STUDENT *head)
{int n;
STUDENT *p1,*p2; /*p1为查找到要删除的结点指针,p2为其前驱指针*/
char c,s[6]; /*s[6]用来存放学号,c用来输入字母*/
clrscr();
printf("请输入要删除的学号 Please enter the deleted num: ");
scanf("%s",s);
p1=p2=head; /*给p1和p2赋初值头指针*/
while(strcmp(p1-num,s) p1 != NULL) /*当记录的学号不是要找的,或指针不为空时*/
{p2=p1; /*将p1指针值赋给p2作为p1的前驱指针*/
p1=p1-next; /*将p1指针指向下一条记录*/
}
if(strcmp(p1-num,s)==0) /*学号找到了*/
{printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | sc1 | sc2 | sc3 | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1-num,p1-name,p1-score[0],p1-score[1],p1-score[2],p1-sum,p1-average,p1-order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("\n是否要删除,输入Y删除,N则退出\nAre you sure to delete the student Y/N ?"); /*提示是否要删除,输入Y删除,N则退出*/
for(;;)
{scanf("%c",c);
if(c=='n'||c=='N') break; /*如果不删除,则跳出本循环*/
if(c=='y'||c=='Y')
{
if(p1==head) /*若p1==head,说明被删结点是首结点*/
head=p1-next; /*把第二个结点地址赋予head*/
else
p2-next=p1-next; /*否则将一下结点地址赋给前一结点地址*/
n=n-1;
printf("\n学号为(Num): %s 学生以被删除(student have been deleted.)\n",s);
printf("别忘了保存. Don't forget to save.\n");break; /*删除后就跳出循环*/
}
}
}
else
printf("\n没有这个学生在表上\nThere is no num %s student on the list.\n",s); /*找不到该结点*/
return(head);
}
/*排序函数*/
STUDENT *sort(STUDENT *head)
{int i=0; /*保存名次*/
STUDENT *p1,*p2,*t,*temp; /*定义临时指针*/
temp=head-next; /*将原表的头指针所指的下一个结点作头指针*/
head-next=NULL; /*第一个结点为新表的头结点*/
while(temp!=NULL) /*当原表不为空时,进行排序*/
{
t=temp; /*取原表的头结点*/
temp=temp-next; /*原表头结点指针后移*/
p1=head; /*设定移动指针p1,从头指针开始*/
p2=head; /*设定移动指针p2做为p1的前驱,初值为头指针*/
while(t-averagep1-averagep1!=NULL) /*作成绩平均分比较*/
{
p2=p1; /*待排序点值小,则新表指针后移*/
p1=p1-next;
}
if(p1==p2) /*p1==p2,说明待排序点值大,应排在首位*/
{
t-next=p1; /*待排序点的后继为p*/
head=t; /*新头结点为待排序点*/
}
else /*待排序点应插入在中间某个位置p2和p1之间,如p为空则是尾部*/
{
t-next=p1; /*t的后继是p1*/
p2-next=t; /*p2的后继是t*/
}
}
p1=head; /*已排好序的头指针赋给p1,准备填写名次*/
while(p1!=NULL) /*当p1不为空时,进行下列操作*/
{
i++; /*结点序号*/
p1-order=i; /*将结点序号赋值给名次*/
p1=p1-next; /*指针后移*/
}
printf("排序成功 Sorting is sucessful.\n"); /*排序成功*/
return (head);
}
/*插入记录函数*/
STUDENT *insert(STUDENT *head,STUDENT *new)
{STUDENT *p0,*p1,*p2;
int n,sum1,i;
p1=head; /*使p1指向第一个结点*/
p0=new; /*p0指向要插入的结点*/
printf("\nPlease enter a new record.\n"); /*提示输入记录信息*/
printf("输入学号Enter the num:");
scanf("%s",new-num);
printf("输入名字Enter the name:");
scanf("%s",new-name);
printf("Please enter the %d scores.\n",3);
sum1=0; /*保存新记录的总分,初值为0*/
for(i=0;i3;i++)
{
do{
printf("成绩score%d:",i+1);
scanf("%d",new-score[i]);
if(new-score[i]100||new-score[i]0)
printf("数据错误Data error,please enter again.\n");
}while(new-score[i]100||new-score[i]0);
sum1=sum1+new-score[i]; /*累加各门成绩*/
}
new-sum=sum1; /*将总分存入新记录中*/
new-average=(float)sum1/3;
new-order=0;
if(head==NULL) /*原来的链表是空表*/
{head=p0;p0-next=NULL;} /*使p0指向的结点作为头结点*/
else
{while((p0-averagep1-average)(p1-next!=NULL))
{p2=p1; /*使p2指向刚才p1指向的结点*/
p1=p1-next; /*p1后移一个结点*/
}
if(p0-average=p1-average)
{if(head==p1)head=p0; /*插到原来第一个结点之前*/
else p2-next=p0; /*插到p2指向的结点之后*/
p0-next=p1;}
else
{p1-next=p0;p0-next=NULL;} /*插到最后的结点之后*/
}
n=n+1; /*结点数加1*/
head=sort(head); /*调用排序的函数,将学生成绩重新排序*/
printf("\n学生Student %s 已被更新have been inserted.\n",new-name);
printf("不要忘了保存Don't forget to save the new file.\n");
return(head);
}
/*保存数据到文件函数*/
void save(STUDENT *head)
{FILE *fp; /*定义指向文件的指针*/
STUDENT *p; /* 定义移动指针*/
char outfile[10];
printf("输出文件例如:c:\\score Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"w"))==NULL) /*为输出打开一个二进制文件,为只写方式*/
{
printf("打不开文件Cannot open the file\n");
return; /*若打不开则返回菜单*/
}
printf("\n保存中...Saving the file......\n");
p=head; /*移动指针从头指针开始*/
while(p!=NULL) /*如p不为空*/
{
fwrite(p,LEN,1,fp); /*写入一条记录*/
p=p-next; /*指针后移*/
}
fclose(fp); /*关闭文件*/
printf("保存成功....Save the file successfully!\n");
}
/* 从文件读数据函数*/
STUDENT *load()
{STUDENT *p1,*p2,*head=NULL; /*定义记录指针变量*/
FILE *fp; /* 定义指向文件的指针*/
char infile[10];
printf("倒入文件例如:c:\\score Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL) /*打开一个二进制文件,为只读方式*/
{
printf("打不开文件Can not open the file.\n");
return(head);
}
printf("\n寻找文件...Loading the file!\n");
p1=(STUDENT *)malloc(LEN); /*开辟一个新单元*/
if(!p1)
{
printf("内存溢出!Out of memory!\n");
return(head);
}
head=p1; /*申请到空间,将其作为头指针*/
while(!feof(fp)) /*循环读数据直到文件尾结束*/
{
if(fread(p1,LEN,1,fp)!=1) break; /*如果没读到数据,跳出循环*/
p1-next=(STUDENT *)malloc(LEN); /*为下一个结点开辟空间*/
if(!p1-next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1; /*使p2指向刚才p1指向的结点*/
p1=p1-next; /*指针后移,新读入数据链到当前表尾*/
}
p2-next=NULL; /*最后一个结点的后继指针为空*/
fclose(fp);
printf("\n你成功的从文件中读取了数据!\nYou have success to read data from the file!\n");
return (head);
}
c语言学生管理系统
C 语言学生成绩管理系统
#includestdio.h
#includemalloc.h
#includeconio.h
#includestring.h
typedef struct STUDENT
{
char studentNumber[20];/*学生学号*/
char studentName[20];/*学生姓名*/
char className[20];/*班级名称*/
float mark1;/*第1门成绩*/
float mark2;/*第2门成绩*/
float mark3;/*第3门成绩*/
struct STUDENT *next;
}STUDENT;
STUDENT *headLink; /*链表表头指针*/
/*函数声明*/
void ReadInfoFormFile();
void Menu();
void CreateHeadLink();
STUDENT *MallocNode();
void GetInformation(STUDENT *t);
void OutputInformation();
void DesplayInfoBystudentName();
void DesplayInfoBystudentNumber();
void DesplayOneNode(STUDENT *t);
void InsertOneNode(STUDENT *t);
void DeleteNodeBystudentNumber();
void ChangeMarkByName();
void ChangeMarkByNumber();
void SaveLinkToFile();
void paixu();
void DesplayMarkSegment();
int choose;/*用于接受用户的选择*/
/*主函数*/
main()
{
system("color 2a");
printf("\n\t\t欢迎进入***学院***班学生成绩管理系统\n\n\n");
printf("\t\t\t\tO(∩_∩)O\n\n\n\n");
printf("\t\t\t^_^\t\t\t^_^\n\n");
printf("\n\t\t 注意:请按照要求输入相应信息,谢谢!\n\n\n\n\n");
printf("\t\t\t\t\t\t\t\t制作人:***\n\n\n");
printf("\t\t\t 按任意键进入…………");
getch();
system("cls");
CreateHeadLink();
ReadInfoFormFile();
Menu();
}
/*从文件中读学生信息到链表中*/
void ReadInfoFormFile(void)
{
FILE *fp;
STUDENT *p;
fp=fopen("student.txt","r");
if(!fp)
{
printf("\n");
return;
}
p=MallocNode();
while(fscanf(fp,"%s%s%s%f%f%f",p-studentNumber,p-studentName,p-className,(p-mark1),(p-mark2),(p-mark3))0)
{
InsertOneNode(p);
p=MallocNode();
}
fclose(fp);
}
/*显示菜单,根据用户的输入完成相应的功能*/
void Menu(void)
{
STUDENT *p;
printf("\t\t (^o^)欢迎使用学生成绩管理系统(^o^)\n\n");
printf("\t ※--------------------请选择相应功能---------------------※\n\n");
printf("\t 1: 显示所有学生的信息 |");
printf(" \t 2: 按姓名查询 |\n\n");
printf("\t 3: 按学号查询 |");
printf(" \t\t 4: 增加学生 |\n\n");
printf("\t 5: 删除学生 |");
printf(" \t\t 6: 按姓名修改学生成绩 |\n\n");
printf("\t 7: 按学号修改学生成绩 |");
printf(" \t 8: 保存所有学生信息 |\n\n");
printf("\t 9: 按成绩输出学生信息 |");
printf("\t 10: 显示不及格及优秀学生 |\n\n");
printf("\t 11: 返回主菜单 |");
printf("\t\t 12: 退出 |\n\n");
printf("\t ※----------------------O(∩_∩)O------------------------※\n\n");
printf("\t 请输入对应数字:");
scanf("%d",choose);/*取得用户的选择*/
switch(choose)
{
case 1:system("cls");
OutputInformation();/*显示所有学生的信息*/
break;
case 2: system("cls");
DesplayInfoBystudentName();
break;
case 3: system("cls");
DesplayInfoBystudentNumber();/*根据用户输入的学号显示该学生的信息*/
break;
case 4: system("cls");
p=MallocNode();/*先申请一个新结点*/
GetInformation(p);/*要求用户输入信息到新结点中*/
InsertOneNode(p);/*将新结点加到链表中*/
break;
case 5: system("cls");
DeleteNodeBystudentNumber();/*根据用户输入的学号删除该学生*/
break;
case 6: system("cls");
ChangeMarkByName();/*根据用户输入的姓名修改学生成绩*/
break;
case 7: system("cls");
ChangeMarkByNumber();/*根据用户输入的学号修改学生成绩*/
break;
case 8: system("cls");
SaveLinkToFile();/*保存数据*/
break;
case 9: system("cls");
paixu();break;
case 10: system("cls");
DesplayMarkSegment();break;
case 11: system("cls");
break;
case 12: system("cls");
SaveLinkToFile();/*保存数据后再退出*/
free(headLink);
exit(1);
break;
default: system("cls"); break;
}
Menu();/*递归调用*/
}
/*建立链表表头*/
void CreateHeadLink(void)
{
STUDENT *p;
p=(STUDENT*)malloc(sizeof(STUDENT));
headLink=p;
p-next=NULL;
}
/*申请一个新结点,并将其初始化*/
STUDENT *MallocNode(void)
{
STUDENT *p;
int i;
p=(STUDENT*)malloc(sizeof(STUDENT));
if(p==NULL)
return NULL;
for(i=0;i10;i++)
p-studentNumber='\0';
for(i=0;i20;i++)
p-studentName='\0';
for(i=0;i20;i++)
p-className='\0';
p-mark1=0.0;
p-mark2=0.0;
p-mark3=0.0;
p-next=NULL;
return p;
}
/*取得用户输入的学生信息*/
void GetInformation(STUDENT *t)
{
printf("请输入学生学号:");
scanf("%s",t-studentNumber);
printf("请输入学生姓名:");
scanf("%s",t-studentName);
printf("请输入该生所在班级:");
scanf("%s",t-className);
printf("请输入第1门成绩:");
scanf("%f",(t-mark1));
printf("请输入第2门成绩:");
scanf("%f",(t-mark2));
printf("请输入第3门成绩:");
scanf("%f",(t-mark3));
}
/*在链表的结尾处增加一个结点*/
void InsertOneNode(STUDENT *t)
{
STUDENT *p;
p=headLink;
while(p-next)
{
p=p-next;
}
p-next=t;
}
/*根据用户输入的学生姓名显示该学生的信息*/
void DesplayInfoBystudentName(void)
{
STUDENT *p;
char studentName[20];
char flag=0;
p=headLink-next;
printf("请输入学生姓名:");
scanf("%s",studentName);
while(p)
{
if(strcmp(p-studentName,studentName)==0)
{system("cls");
printf("\t学号\t姓名\t班级\t成绩1\t成绩2\t成绩3\t总成绩\t平均成绩\n");
DesplayOneNode(p);
flag=1;
break;
}
p=p-next;
}
if(!flag) {system("cls");
printf("\t 对不起,不存在姓名为 %s 的学生\n",studentName);}
}
/*根据用户输入的学号显示该学生的信息*/
void DesplayInfoBystudentNumber(void)
{
STUDENT *p;
char studentNumber[20];
char flag=0;
p=headLink-next;
printf("请输入学生学号:");
scanf("%s",studentNumber);
while(p)
{
if(strcmp(p-studentNumber,studentNumber)==0)
{ system("cls");
printf("\t学号\t姓名\t班级\t成绩1\t成绩2\t成绩3\t总成绩\t平均成绩\n");
DesplayOneNode(p);
flag=1;
break;
}
p=p-next;
}
if(!flag) {system("cls");
printf("\t 对不起,不存在学号为 %s 的学生\n",studentNumber);
}}
/*输出一个结点的信息*/
void DesplayOneNode(STUDENT *t)
{
printf("\t%s\t",t-studentNumber);
printf("%s\t",t-studentName);
printf("%s\t",t-className);
printf("%.2f\t",t-mark1);
printf("%.2f\t",t-mark2);
printf("%.2f\t",t-mark3);
printf("%.2f\t",t-mark1+t-mark2+t-mark3);
printf("%.2f\t\n",(t-mark1+t-mark2+t-mark3)/3);
}
/*根据用户输入的学号删除该学生*/
void DeleteNodeBystudentNumber(void)
{
char studentNumber[10];
STUDENT *p,*q;
char flag=0;
printf("请输入要删除的学生学号:");
scanf("%s",studentNumber);
p=headLink;
q=headLink-next;
while(q)
{
if(strcmp(q-studentNumber,studentNumber)==0)
{
p-next=q-next;
free(q);
flag=1;
break;
}
p=p-next;
q=q-next;
}
if(!flag)
{ system("cls");
printf("\t 不存在该学号的学生\n");
return;
}
system("cls");
printf("\t 成功删除\n");
}
/*显示所有学生的信息*/
void OutputInformation(void)
{
STUDENT *p;
p=headLink-next;
if(p==NULL)
{
printf("\t 现在没有学生信息,请先输入学生信息\n\n");
return;
}
printf("\t学号\t姓名\t班级\t成绩1\t成绩2\t成绩3\t总成绩\t平均成绩\n");
while(p)
{
DesplayOneNode(p);
p=p-next;
}
}
/*根据输入的姓名修改成绩*/
void ChangeMarkByName(void)
{
STUDENT *p;
char studentName[20];
char flag=0;
float mark1,mark2,mark3;
p=headLink-next;
printf("请输入学生姓名:");
scanf("%s",studentName);
while(p)
{
if(strcmp(p-studentName,studentName)==0)
{
printf("请输入新的第1门成绩:\n");
scanf("%f",mark1);
printf("请输入新的第2门成绩:\n");
scanf("%f",mark2);
printf("请输入新的第3门成绩:\n");
scanf("%f",mark3);
p-mark1=mark1;
p-mark2=mark2;
p-mark3=mark3;
flag=1;
printf("修改成功\n");
break;
}
p=p-next;
}
if(!flag) {system("cls");
printf("\t 对不起,不存在姓名为 %s 的学生\n",studentName);
} }
/*根据输入的姓名修改成绩*/
void ChangeMarkByNumber(void)
{
STUDENT *p;
char studentNumber[20];
char flag=0;
float mark1,mark2,mark3;
p=headLink-next;
printf("请输入学生学号:");
scanf("%s",studentNumber);
while(p)
{
if(strcmp(p-studentNumber,studentNumber)==0)
{
printf("请输入新的第1门成绩:\n");
scanf("%f",mark1);
printf("请输入新的第2门成绩:\n");
scanf("%f",mark2);
printf("请输入新的第3门成绩:\n");
scanf("%f",mark3);
p-mark1=mark1;
p-mark2=mark2;
p-mark3=mark3;
flag=1;
printf("修改成功\n");
break;
}
p=p-next;
}
if(!flag){system("cls");
printf("\t 对不起,不存在学号为 %s 的学生\n",studentNumber);
}}
/*保存链表数据到文件中*/
void SaveLinkToFile(void)
{
STUDENT *p;
FILE *fp;
p=headLink-next;
if(p==NULL)
{
printf("\t 现在没有学生信息,请先输入学生信息\n\n");
return;
}
fp=fopen("student.txt","w+");
if(!fp)
{
printf("文件不存在\n");
return;
}
while(p)
{
fprintf(fp,"%s %s %s %f %f %f\n",p-studentNumber,p-studentName,p-className,p-mark1,p-mark2,p-mark3);
p=p-next;
}
fclose(fp);
}
/*显示优秀和不及格学生成绩*/
void DesplayMarkSegment(void)
{
STUDENT *p;
int count=0;
p=headLink-next;
printf("\t60分以下(不及格)的学生成绩如下:\n");
printf("\t学号\t姓名\t班级\t成绩1\t成绩2\t成绩3\t总成绩\t平均成绩\n\n");
while(p)
{
if((6((int)(p-mark1/10)))||(6((int)(p-mark2/10)))||(6((int)(p-mark3/10))))/*只要有一科不及格就认为该生不及格*/
{
count++;
DesplayOneNode(p);
}
p=p-next;
}
printf("\t不及格的学生一共有%d人\n",count);
p=headLink-next;
printf("\t成绩优秀的学生成绩如下:\n");
printf("\t学号\t姓名\t班级\t成绩1\t成绩2\t成绩3\t总成绩\t平均成绩\n\n");
count=0;
while(p)
{
if((8=((int)(p-mark1/10)))(8=((int)(p-mark2/10)))(8=((int)(p-mark3/10))))
{
count++;
DesplayOneNode(p);
}
p=p-next;
}
printf("\t成绩优秀的学生一共有%d人\n",count);
}
/*按总成绩排序*/
void paixu(void)
{
STUDENT exchange,*r,*p,*q;
r=headLink-next;
if(r==NULL)
{
printf("\t 现在还没学生信息,请先输入学生信息\n");
return;
}
while(r)/*两层while循环实现排序*/
{
p=r;
q=r-next;
while(q)
{
if((q-mark1+q-mark2+q-mark3)(p-mark1+p-mark2+p-mark3))
{
strcpy(exchange.studentNumber,q-studentNumber);/*先复制q结点信息到exchange*/
strcpy(exchange.studentName,q-studentName);
strcpy(exchange.className,q-className);
exchange.mark1=q-mark1;
exchange.mark2=q-mark2;
exchange.mark3=q-mark3;
strcpy(q-studentNumber,p-studentNumber);/*再复制p结点信息到q*/
strcpy(q-studentName,p-studentName);
strcpy(q-className,p-className);
q-mark1=p-mark1;
q-mark2=p-mark3;
q-mark3=p-mark3;
strcpy(p-studentNumber,exchange.studentNumber);/*最后复制exchange结点信息到p*/
strcpy(p-studentName,exchange.studentName);
strcpy(p-className,exchange.className);
p-mark1=exchange.mark1;
p-mark2=exchange.mark2;
p-mark3=exchange.mark3;
}
q=q-next;
}
r=r-next;
}
OutputInformation();
}
如何建立“学生管理”数据库,并在“学生管理”数据库中分别建立“学生基本情况表”求高手教一下
USE [master]
GO
CREATE DATABASE StudentManage ON PRIMARY
( NAME = N'StudentManage', FILENAME = N'D:\StudentManage.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'StudentManage_log', FILENAME = N'D:\StudentManage_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
/*学生管理数据库(StudentManage)创建完成,下面创建学生表(Student):*/
USE [Jinlong]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Student](
[学号C9] [char](7) NOT NULL,
[姓名C10] [char](6) NULL,
[性别C2] [char](2) NULL,
CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED
(
[SID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
分享标题:go语言学生管理系统 go语言图书管理系统
网页地址:http://ybzwz.com/article/dosdhgj.html