C++学生管理系统课程设计 源代码
学生管理系统c语言源代码
![学生管理系统c语言源代码](https://img.taocdn.com/s3/m/0de537d049649b6648d74764.png)
int main()
{
initLinkTable(&head);//初始化表头
readStu();//读入源文件
while (1)
{
menu();
system("cls");
}
}
void initLinkTable(studentLinkPoint *p)
int sum(studentLinkPoint);//求和
void avg(studentLinkPoint);//求平均分
void disAvgSum(studentLinkPoint);//显示总分和平均分
char *inputNumber();//专门用来输入一个学生的学号,返回该字符串的指针
char name[20];
char number[18];
int i;
if(temp==0)
{
error("input");
return 0;
}
else
{
temp->student=(studentPint)malloc(sizeof(studentNod));
break;
case 0:
del(head,end);
break;
}
if(c==0)
exit(1);
}
void del(studentLinkPoint p,studentLinkPoint End)
{
studentLinkPoint q;
if(end==head)
printf(" %3.1f %3.1f\n",p->student->sum,p->student->avg);
c语言学生管理系统源代码
![c语言学生管理系统源代码](https://img.taocdn.com/s3/m/87e9d5f8b8f3f90f76c66137ee06eff9aff84947.png)
c语言学生管理系统源代码#include <stdio.h>。
#include <stdlib.h>。
#include <string.h>。
/*定义学生结构体*/。
typedef struct student。
char num[20]; //学号。
char name[20]; //姓名。
int c; //语文成绩。
int math; //数学成绩。
float ave; //平均分。
struct student *next;。
} stu;。
/*函数声明*/。
void menu_select(); //显示菜单。
void add(); //添加学生信息。
void delete(); //删除学生信息。
void modify(); //修改学生信息。
void search(); //查询学生信息。
void get_ave(); //计算学生平均成绩。
void display(); //显示学生信息。
void esc(); //退出系统。
int main()。
menu_select();。
return 0;。
}。
//显示菜单。
void menu_select()。
int select;。
while (1)。
printf("\n学生管理系统\n");。
printf("------菜单------\n");。
printf("1.添加学生信息 2.删除学生信息\n");。
printf("3.修改学生信息 4.查询学生信息\n");。
printf("5.计算学生平均成绩 6.显示学生信息\n");。
printf("7.退出系统\n");。
printf("请输入您的选择:");。
scanf("%d", &select);。
C语言学籍管理系统(内含源代码)
![C语言学籍管理系统(内含源代码)](https://img.taocdn.com/s3/m/b290fb758762caaedc33d409.png)
学籍管理系统一、系统简介设计一个基于结构体数组的学生学籍管理系统,能实现对学生学籍信息进行录入,修改,删除,查询和输出等基本操作二、需求分析学籍管理系统应该实现以下功能:1、能录入学生的基本信息,包括学号,姓名,专业,年级,性别和出生日期信息,保存到结构体数组中。
2、能根据输入的学号查询学生,进行信息的修改。
3、能根据输入的学号从结构体数组中删除学生的记录。
4、实现查询功能,能根据输入的学号或年级在屏幕上显示相应的学生信息。
5、能在屏幕上以列表的方式输出所有学生的信息。
三、概要设计1、系统功能根据项目的开发要求,本系统划分成六个主要功能模块:录入学生信息模块、修改学生信息模块、删除学生信息模块、查询学生信息模块、输出模块和推出模块。
系统功能机构图如下:2、重要数据的数据结构设计学生学籍的记录项用结构体Stu message表示,包括6个属性,stuno,name、spec、grade、sex、birthday 分另U代表学生的学号、专业、年级、性另U和出生日期,其中birthday 类型为自定义的结构体类型Date.Struct stumessage {Char stuno[11]: // 学号Char name[9]: // 姓名Char spec[2]: // 专业Char grade: // 年级Char sex : // 性别Stuct date birthday: // 出生日期};日期类型date包括三个属性,分别代表年、月、日Struct date{int year : // 年Int month: //Int day: // H};3、函数设计学籍管理系统程序采用了结构化程序设计的思想,由1个.h 头文件和3个C源文件组成。
程序中除了主函数外,共设计了以下14个函数,分别包含在3个.c源文件中。
以下是这些函数原型及功能设计。
(1) void sysinfo(void)函数功能:在屏幕上输入系统及信息并等待用户响应。
学生管理系统c语言简单版
![学生管理系统c语言简单版](https://img.taocdn.com/s3/m/cc610f2f2379168884868762caaedd3383c4b5be.png)
学生管理系统c语言简单版学生管理系统c语言简单版介绍:学生管理系统是一种用于管理学生信息的软件,它可以方便地对学生的基本信息、课程成绩等进行录入、查询、修改和删除等操作。
本文将介绍如何使用C语言编写一个简单的学生管理系统。
功能:1. 添加学生信息2. 查询学生信息3. 修改学生信息4. 删除学生信息5. 显示所有学生信息实现方法:1. 添加学生信息添加学生信息需要输入以下内容:姓名、性别、年龄、班级和电话号码。
我们可以定义一个结构体来存储这些信息,代码如下:```struct Student {char name[20];char sex[10];int age;char class[20];char phone[20];};```然后定义一个数组来存储多个学生的信息:```struct Student students[100];int count = 0; // 学生数量```接下来,我们可以编写一个函数来添加新的学生信息:```void addStudent() {struct Student student;printf("请输入姓名:");scanf("%s", );printf("请输入性别:");scanf("%s", student.sex);printf("请输入年龄:");scanf("%d", &student.age);printf("请输入班级:");scanf("%s", student.class);printf("请输入电话号码:");scanf("%s", student.phone);students[count++] = student; // 将新的学生信息存储到数组中 printf("添加成功!\n");}```2. 查询学生信息查询学生信息可以按照姓名或电话号码进行查询。
C语言课程设计—学生成绩管理系统
![C语言课程设计—学生成绩管理系统](https://img.taocdn.com/s3/m/3099effbf80f76c66137ee06eff9aef8941e4805.png)
#include ”stdio.h”#include ”string.h”#include "stdlib.h"#include "conio.h"#include ”string.h”#include "fcntl。
h"typedef struct student{int num;char grade[10];char classroom[10];char name[10];float score_math;float score_chinese;float score_english;float average;float sum;}STU;typedef struct Node{STU data;struct Node *next;}*linklist;void menu();char *loginpassword(char password[],int n);//登录验证密码函数声明//linklist createstulist(linklist head);//创建学生链表即学生信息录入函数声明// void printstulist(linklist head);//学生信息输出函数声明//void searchstu_namelist(linklist head);//学生信息查询函数声明(按姓名)// void searchstu_numlist(linklist head);//学生信息查询函数声明(按学号) linklist modifystulist(linklist head);//学生信息修改函数声明//linklist delatestulist(linklist head);//学生信息删除函数声明//void savestulist(linklist head);//学生信息保存到文件函数声明// linklist loadstulist();//从文件中读取学生信息函数声明// void sortstulist(linklist head); //成绩排名函数(按年级)声明//void sort(STU stu[],int flag); //学生分班函数声明//void sortstuclass(linklist head); //成绩排名函数(按班级)声明////*************************************//void main(){char admin[]=”zhangqiong";char password[]=”123456";char person[20];char password1[10];int i;printf(”********************************************************************************\n”);printf("\t\t **********欢迎来到学生成绩管理系统**********\n\n");printf(”********************************************************************************\n\n”);printf(”\t\t\t\t用户登录\n\n\n\n");for(i=0;i<3;i++){printf("用户名:”);gets(person);fflush(stdin);printf(”\n\n\n”);loginpassword(password1,10);printf("\n\n\n”);if(strcmp(admin,person)==0&&strcmp(password,password1)==0){printf(”\t\t\t\t成功登录,亲!\n”);printf("\n\n”);printf(”按任意键继续!”);getch();menu();break;}elseprintf("\t用户名或者密码输入错误\n”);}if(i==3)printf("\t对不起,您今天输入次数太多,已被强制退出!\n”);}//**********************************************************////**********************************************************//char *loginpassword(char password[],int n)//登录密码函数,隐藏密码可见//{int i=0;int m=0;char ch;printf("用户密码:”);while((ch=getch())!='\r’&&m〈n){password[i++]=ch;printf(”*");}password[i]='\0';return password;}//***************************************************// void menu()//主界面函数//{system("cls");linklist L;L=(linklist)malloc(sizeof(Node));L—>next=NULL;int ch;do{printf(”\t -——-----—-******——--——--—---******—————-————-******-—-—-—-—-—\n\n");printf("\t\t\t**********学生成绩管理系统***********\n\n”);printf("\t ——----——--******-—-——------—******—---———--—-******—---———-——\n\n\n\n\n");printf("\t1。
C语言的教务管理系统(2000行代码)
![C语言的教务管理系统(2000行代码)](https://img.taocdn.com/s3/m/6f09d88d4693daef5ff73d24.png)
C语言教务管理系统一、程序结构图二、程序运行截图1. 个人信息简介2.修改颜色3.注册界面4. 信息保存至文件5.登录界面6.管理员录入信息7. 学生信息录入8.学生成绩录入9.学生课程表录入10.学生信息查询界面11学生信息查询12.学生成绩查询13.学生课表查询三、代码(一个cpp)#include<stdio.h> #include<stdlib.h> #include<string.h> #include<ctype.h> #include <conio.h>#include"windows.h"#define student_num 1000 /*定义1000个学生*/#define teacher_num 5 /*定义5个老师(管理员)*/int is_my_student(struct student *p,int *size); /*声明返回第i+1个学生的函数*/ int is_my_teacher(struct teacher *p,int *size); /*声明返回第i+1个老师的函数*/ int length_student_name(char *p); /*声明验证用户名函数*/int length_student_password(char *p); /*声明验证密码长度函数*/int length_teacher_name(char *p); /*声明验证用户名函数*/int length_teacher_password(char *p); /*声明验证密码长度函数*/int show_menu_login(); /*声明登录菜单函数*/int show_menu_register(); /*声明注册菜单函数*/int show_teacher_select(); /*声明教师录入菜单函数*/int show_student_select(); /*声明学生查询菜单函数*/int student_register(struct student *ptr_student,int *size); /*声明学生注册函数*/ int teacher_register(struct teacher *ptr_teacher,int *size); /*声明老师注册函数*/ int vaild_student_name(char *p); /*声明验证用户名函数*/int vaild_student_password(char *p); /*声明验证密码函数*/int vaild_teacher_name(char *p); /*声明验证用户名函数*/int vaild_teacher_password(char *p); /*声明验证密码函数*/int vaild_two_password(char *p1,char *p2); /*声明验证两次密码是否相同函数*/ int yes_no_return(); /*声明选择是否返回上一层函数*/void load(); /*声明加载函数*/void register_(int *count1,int *count2); /*声明注册函数*/void display_student(struct student stu); /*声明显示学生信息函数*/void display_teacher(struct teacher tea); /*声明显示老师信息函数*/void student_file1(); /*将保存的学生的账号密码存入文件中*/ void student_file2(); /*将保存的学生的个人信息存入文件中*/ void student_file3(); /*将保存的学生的成绩存入文件中*/void teacher_file(); /*将保存的老师的账号密码存入文件中*/ void input_information(int count); /*声明输入学生信息函数*/void input_score_menu(int count); /*声明输入学生成绩函数*/void color(); /*声明选择窗体颜色函数*/void print_stu_information(int count_stu); /*声明输出账号为num的学生的信息函数*/void print_stu_score(int count_stu); /*声明输出账号为num的学生的成绩函数*/void show_menu(); /*声明初始化界面函数*/void input(); /*声明输入函数*/void menu1(); /*声明教师录入课程表主菜单函数*/void menu2(); /*声明学生查询课程表主菜单函数*/void rank(); /*声明显示时间顺序函数*/void querymenu3(); /*声明查询函数*/void looktime(); /*声明按照时间查询函数*/void looklessonname(); /*声明按照课程名查询函数*/void add(); /*声明保存函数*/void amend(); /*声明修改课程函数*/void amend1(); /*声明修改课程子函数*/void amendnews(int i); /*声明修改整个课程信息函数*/void amendtime(int i); /*声明修改课程时间函数*/void amendlessonname(int i); /*声明修改课程课程名函数*/void amendclassroom(int i); /*声明修改课程教室函数*/void deleted(); /*声明删除函数*/void add_score(int count); /*声明添加学生成绩函数*/void xiugai_score(int count); /*声明修改学生成绩函数*/void shanchu_score(int count); /*声明删除学生成绩函数*/void chaxun_score(int count); /*声明按要求查询学生成绩函数*/void paixu_score(int count); /*声明学生成绩排序函数*/void tongji_score(int count); /*声明学生成绩统计函数*/float chinese(int count); /*声明计算语文成绩最大值函数*/int chr(int count); /*声明计算语文成绩及格人数的函数*/ float english(int count); /*声明计算英语成绩最大值函数*/int ehr(int count); /*声明计算英语成绩及格人数的函数*/ float math(int count); /*声明计算数学成绩最大值函数*/int mhr(int count); /*声明计算数学成绩及格人数的函数*/ float computer(int count); /*声明计算计算机成绩最大值函数*/int thr(int count); /*声明计算计算机成绩及格人数的函数*/float PE(int count); /*声明计算体育成绩最大值函数*/int phr(int count); /*声明计算体育成绩及格人数的函数*/ float sum_score(int count); /*声明计算总分成绩最大值函数*/ void load_student(int a); /*声明启动学生函数*/void load_teacher(int a); /*声明启动老师函数*/struct student /*学生结构体*/{/*个人信息*/int student_id; /*账号*/char student_name[20]; /*姓名*/char password[16]; /*密码*/int age; /*年龄*/char qq[12]; /*QQ号*/char tel[12]; /*电话*/int grade; /*年级*//*各科成绩*/float chinese; /*语文分数*/float english; /*英语分数*/float math; /*数学分数*/float computer; /*计算机分数*/float PE; /*体育分数*/float sum; /*总分*//*课程表*/char time[10]; /*时间*/char lessonname[20]; /*课程名*/char teacher[20]; /*授课老师*/char classroom[10]; /*教室*/char hours[10]; /*第几节课*/int weeks; /*周时*/};struct teacher /*老师结构体*/ {int teacher_id; /*账号*/char teacher_name[20]; /*姓名*/char password[16]; /*密码*/};struct student our_student[student_num]; struct teacher our_teacher[teacher_num];void main() /*主函数*/{system("color f0"); /*初始化背景颜色*/show_menu(); /*制作人信息简介*/load();}void load() /*启动函数*/{int flag=1; /*控制循环结束的变量*/int a=0,b=0; /*记录已注册的学生的人数a为学生个数b为老师个数*/int *count1=&a,*count2=&b; /*指向学生人数和老师人数的指针*/int correct_student,correct_teacher;color();register_(count1,count2); /*注册学生和老师的帐号*/student_file1();teacher_file();while(flag){switch(show_menu_login()) /*显示登录菜单*/{case 1: /*选择1,进入学生登录*/if(correct_student=is_my_student(our_student,count1)){printf("\n ◆学生登录成功!\n");display_student(our_student[correct_student-1]);printf("\n");printf(" ");system("pause");load_student(a);}elseprintf("\n登录失败!\n");printf("\n");printf(" 提示:按Y退出登录界面,按N返回登录界面!!!\n");flag=yes_no_return();system("cls");break;case 2: /*选择2,进入老师登录,即管理员登录*/ if(correct_teacher=is_my_teacher(our_teacher,count2)){printf("\n ◆管理员登录成功!\n");display_teacher(our_teacher[correct_teacher-1]);printf("\n");printf(" ");system("pause");load_teacher(a);}elseprintf("\n登录失败!\n");printf("\n");printf(" 提示:按Y退出登录界面,按N返回登录界面!!!\n");flag=yes_no_return();system("cls");break;case 3: /*选择3,退出登录*/system("cls");flag=0;break;default:printf("请正确输入1-3:");system("cls");}}}void load_student(int a) /*启动学生函数*/{int flag=1;system("cls");while(flag){switch(show_student_select()){case 1: /*选择1,学生信息查询*/system("cls");print_stu_information(a);printf("\n");printf(" 提示:按Y退出学生查询界面,按N返回学生查询界面!!!\n");flag=yes_no_return();system("cls");break;case 2: /*选择2,学生成绩查询*/system("cls");print_stu_score(a);printf("\n");printf(" 提示:按Y退出学生查询界面,按N返回学生查询界面!!!\n");flag=yes_no_return();system("cls");break;case 3: /*选择3,学生课表查询*/menu2();printf(" 提示:按Y退出学生查询界面,按N返回学生查询界面!!!\n");flag=yes_no_return();system("cls");break;case 4: /*选择4,退出查询界面*/system("cls");flag=0;break;default:printf("请正确输入1-4:");system("cls");}}}void load_teacher(int a) /*启动老师函数*/{int flag=1;system("cls");while(flag){switch(show_teacher_select()){case 1: /*选择1,学生信息录入*/input_information(a);system("cls");student_file2();printf("\n 提示:按Y退出教师录入界面,按N返回教师录入界面!!!\n");flag=yes_no_return();system("cls");break;case 2: /*选择2,学生成绩录入*/input_score_menu(a);system("cls");student_file3();printf("\n 提示:按Y退出教师录入界面,按N返回教师录入界面!!!\n");flag=yes_no_return();system("cls");break;case 3: /*选择3,学生课表录入*/menu1();printf(" 提示:按Y退出教师录入界面,按N返回教师录入界面!!!\n");flag=yes_no_return();system("cls");break;case 4: /*选择4,退出管理界面*/system("cls");flag=0;break;default:printf("请正确输入1-4:");system("cls");}}}int length_student_name(char *p) /*验证用户名是否合法*/ {int l;l=strlen(p);if(l>20||l<1)return 0;elsereturn 1;}int vaild_student_name(char *p) /*判断用户名是否有效*/{int i=0;int len=strlen(p);if((*p>='a'&&*p<='z')||(*p>='A'&&*p<='Z')) /*判断首字母是不是字母*/ {for(i=0;i<len;i++){if(!(p[i]='_'||(p[i]>='a'&&p[i]<='z')||(p[i]>='A'&&p[i]<='Z')||(p[i]>='0'&&p[i]<=' 9'))) /*判断后面的字符是否有效*/return 0;}return 1;}elsereturn 0;}int length_student_password(char *p) /*密码长度有效性验证*/{int len;len=strlen(p);if(len<6||len>16)return 0;elsereturn 1;}int vaild_student_password(char *p) /*密码的有效性验证*/{int i=0;for(;*p!='\0';p++){if(!((*p>='a'&&*p<='z')||(*p>'A'&&*p<'Z')||(*p>='0'&&*p<='9'))) return 0;}return 1;}int vaild_two_password(char *p1,char *p2) /*验证两次密码是否相同*/{if(strcmp(p1,p2)==0)return 1;elsereturn 0;}int student_register(struct student *ptr_student,int *size) /*完成注册功能*/{char password[16];char repassword[16];if(*size==student_num){puts(" ◆注册人数已满!");printf("\n");return 0;}system("cls");printf("\n\n");printf(" ★请输入注册学生姓名:");fflush(stdin);gets(ptr_student[*size].student_name);if(!(length_student_name(ptr_student[*size].student_name)&&vaild_student_name(ptr_student[*size].student_name))){printf(" ◆您输入的姓名无效,学生姓名在1-20之间,首字符为字母,后面必须为字母、数字或下划线!!!");return 0;}printf("\n");printf(" ★请输入注册密码:");fflush(stdin);gets(password);printf("\n");printf(" ★请再次输入注册密码:");fflush(stdin);gets(repassword);printf("\n");if(!vaild_two_password(password,repassword)){printf("\n №:两次输入的密码不一致!!!");printf("\n");return 0;}elsestrcpy(ptr_student[*size].password,password);if(!(length_student_password(ptr_student[*size].password)&&vaild_student_pa ssword(ptr_student[*size].password))){printf(" ◆您输入的密码无效,密码应在6-16位之间,密码只能包含字母和数字!!!");printf("\n");return 0;}printf(" ★您的编号为:%d,这将是您的登录账号!!!",ptr_student[*size].student_id=20150000+*size);return 1;}int is_my_student(struct student *p,int *size) /*如果登录成功则返回第i+1个学生的信息,否则返回0*/{int i;int zhanghao;char mima[18];system("cls");printf("\n\n");printf(" ★请输入您的账号:");scanf("%d",&zhanghao);fflush(stdin);printf("\n");printf(" ★请输入您的密码:");gets(mima);for(i=0;i<*size;i++){if((zhanghao==p[i].student_id)&&(strcmp(mima,p[i].password)==0)) return i+1;}return 0;}void display_student(struct student stu) /*显示学生信息*/{printf("\n ★您的账号是:%d\n",stu.student_id);}int length_teacher_name(char *p) /*验证用户名是否合法*/{int l;l=strlen(p);if(l>20||l<1)return 0;elsereturn 1;}int vaild_teacher_name(char *p) /*判断用户名是否有效*/{int i=0;int len=strlen(p);if((*p>='a'&&*p<='z')||(*p>='A'&&*p<='Z')) /*判断首字母是不是字母*/ {for(i=0;i<len;i++){if(!(p[i]='_'||(p[i]>='a'&&p[i]<='z')||(p[i]>='A'&&p[i]<='Z')||(p[i]>='0'&&p[i]<=' 9'))) /*判断后面的字符是否有效*/return 0;}return 1;}elsereturn 0;}int length_teacher_password(char *p) /*密码长度有效性验证*/{int len;len=strlen(p);if(len<6||len>16)return 0;elsereturn 1;}int vaild_teacher_password(char *p) /*密码的有效性验证*/{int i=0;for(;*p!='\0';p++){if(!((*p>='a'&&*p<='z')||(*p>'A'&&*p<'Z')||(*p>='0'&&*p<='9'))) return 0;}return 1;}int teacher_register(struct teacher *ptr_teacher,int *size) /*完成注册功能*/{char password[16];char repassword[16];if(*size==teacher_num){puts(" ◆注册人数已满!");printf("\n");return 0;}system("cls");printf("\n\n");printf(" ★请输入注册教师姓名:");fflush(stdin);gets(ptr_teacher[*size].teacher_name);if(!(length_teacher_name(ptr_teacher[*size].teacher_name)&&vaild_teacher_na me(ptr_teacher[*size].teacher_name))){printf(" ◆您输入的姓名无效,教师姓名在1-20之间,首字符为字母,后面必须为字母、数字或下划线!!!");printf("\n");return 0;}printf("\n");printf(" ★请输入注册密码:");fflush(stdin);gets(password);printf("\n");printf(" ★请再次输入注册密码:");fflush(stdin);gets(repassword);printf("\n");if(!vaild_two_password(password,repassword)){printf("\n №:两次输入的密码不一致!!!");printf("\n");return 0;}elsestrcpy(ptr_teacher[*size].password,password);if(!(length_teacher_password(ptr_teacher[*size].password)&&vaild_teacher_password(ptr_teacher[*size].password))){printf(" ◆您输入的密码无效,密码应在6-16位之间,密码只能包含字母和数字!!!");printf("\n");return 0;}printf(" ★您的编号为:%d,这将是您的登录账号。
学生信息管理系统 系统源代码
![学生信息管理系统 系统源代码](https://img.taocdn.com/s3/m/0b2592cd3968011ca2009111.png)
系统源代码一、登录界面代码using System;using System.Data;using System。
Configuration;using System。
Collections;using System.Web;using System.Web。
Security;using System。
Web.UI;using System。
Web。
UI。
WebControls;using System.Web。
UI.WebControls。
WebParts;using System。
Web.UI.HtmlControls;using System.Data。
SqlClient;public partial class login :System.Web。
UI。
Page{protected void txtid_Click(object sender,EventArgs e){txtid.Text = ”";txtpassword。
Text = ””;}protected void Button1_Click(object sender, EventArgs e){string strconn = ConfigurationManager。
AppSettings[”connStr”];SqlConnection conn = new SqlConnection(strconn);conn。
Open();DataSet ds=new DataSet ();SqlDataAdapter da = new SqlDataAdapter("select * from users where userid=’" + txtid。
Text + "' and userpwd=’” + txtpassword.Text + ”’", conn);da.Fill(ds);if (ds。
[工学]学生信息管理系统完整源码
![[工学]学生信息管理系统完整源码](https://img.taocdn.com/s3/m/3483296b26284b73f242336c1eb91a37f1113291.png)
学生信息管理系统完整源代码注:本系统采用C/S结构,运用Java GUI知识编写,数据库为SQL SERVER 2005,没有采用典型的三级框架结构,所以代码有冗余,仅供参考。
一、数据表及数据源首先创建数据库,包含数据表如下:数据库创建完成后,新建一个名为SIMS的数据源,不会建数据源的同学可以在去搜索创建数据源的详细步骤,这里的数据名称一定要为SIMS,否则在以后程序连接数据库的语句中会出现错误。
二、操作演示三、代码部分创建Java工程,创建名称为SIMS的包,一下Java类均包含在一个包内。
1.登录界面package SIMS;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;import java.text.SimpleDateFormat;import java.util.*;import java.util.Date;public class login extends JFrame implements ActionListener{String userID; //保留用户输入IDString password; //保留用户输入passwordJLabel jlID=new JLabel("用户ID:"); //使用文本创建标签对象 JLabel jlPwd=new JLabel("密码:");JTextField jtID=new JTextField(); //创建ID输入框JPasswordField jpPwd=new JPasswordField(); //创建密码输入框ButtonGroup bg=new ButtonGroup(); //创建ButtonGroup组件对象JPanel jp=new JPanel(); //创建Panel容器JLabel jl=new JLabel();JRadioButton jrb1=new JRadioButton("管理员");JRadioButton jrb2=new JRadioButton("教师");JRadioButton jrb3=new JRadioButton("学生",true);JButton jb1=new JButton("登录");JButton jb2=new JButton("重置");public login(){this.setLayout(null); //设置窗口布局管理器this.setTitle("学生信息管理系统"); //设置窗口标题this.setBounds(200,150,500,300); //设置主窗体位置大小和可见性this.setVisible(true); //设置窗口的可见性this.setResizable(false);jlID.setBounds(150,60,100,20); //设置ID框属性jtID.setBounds(220,60,100,20); //设置ID输入框属性jlPwd.setBounds(150,90,100,20); //设置密码框属性jpPwd.setBounds(220,90,100,20); //设置密码输入框属性jp.setBounds(35,120,400,250); //设置JPanel容器属性jb1.setBounds(160,170,60,20); //设置登录按钮属性jb2.setBounds(250,170,60,20); //设置取消按钮属性jb1.addActionListener(this); //设置登录按钮监听器jb2.addActionListener(this); //设置取消按钮监听器jl.setBounds(340,75,130,20); //设置提示框属性bg.add(jrb1); //将所有空间加入窗体bg.add(jrb2);bg.add(jrb3);this.add(jlID);this.add(jlPwd);this.add(jtID);this.add(jpPwd);this.add(jb1);this.add(jb2);this.add(jl);jp.add(jrb1);jp.add(jrb2);jp.add(jrb3);this.add(jp);centerShell(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(( (screenWidth - shellWidth) / 2),((screenHeight - shellHeight) / 2) );}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(userID);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入IDpassword=jpPwd.getText(); //获取用户输入密码if(e.getSource()==jb1){ //处理登录事件if(userID.equals("") || password.equals("")){jl.setFont(new Font("red",Font.BOLD,12)); //设置提示字体jl.setForeground(Color.red);jl.setText("请输入用户ID和密码");}else{Connection con=null;try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"","");//获取连接字符串Statement stat=con.createStatement();if(jrb1.isSelected())//如果登录选中的管理员{ResultSet rs=stat.executeQuery("select * from Admin"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rss=stat.executeQuery("selectAdmin_Pwd,Admin_Name from Admin where Admin_ID='"+userID+"'");//从表Admin获取信息while(rss.next()){String str=rss.getString(1);if(str.equals(password)){new admin(rss.getString(2));//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12)); //设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}else if(jrb2.isSelected()){ResultSet rs=stat.executeQuery("select * from Teacher_Info"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rss=stat.executeQuery("selectTea_Pwd,Tea_Names from Teacher_Info where Tea_ID='"+userID+"'");//从表Teacher_Info获取信息while(rss.next()){String str=rss.getString(1);if(str.equals(password)){new teacher(rss.getString(2),userID);//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}else if(jrb3.isSelected()){ResultSet rs=stat.executeQuery("select * from Student_Info"); //判断输入用户名是否存在int flag=0;while(rs.next()){if(rs.getString(1).equals(userID)){flag=1;break;}}if(flag==0){jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("用户ID不存在");}if(flag==1){ResultSet rsss=stat.executeQuery("selectStu_Pwd,Stu_Name from Student_Info where Stu_ID='"+userID+"'");//从表Student_Info获取信息while(rsss.next()){String str=rsss.getString(1);if(str.equals(password)){new student(rsss.getString(2),userID);//创建admin窗口this.dispose(); //释放窗体}else{jl.setFont(new Font("red",Font.BOLD,12));//设置提示字体jl.setForeground(Color.red);jl.setText("密码错误");}}}}}catch(Exception ex){ex.getStackTrace();}finally{try{con.close();}catch(Exception exc){exc.printStackTrace();}}}}else if(e.getSource()==jb2){ //处理登录事件jtID.setText("");jpPwd.setText("");jrb3.setSelected(true);jl.setText("");}}public static void main(String[] args){new login();}}2.添加课程package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_course extends JFrame implements ActionListener{ static add_course ss;String courseID=""; //课程名String coursename=""; //课程名String count=""; //课时JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel jlcourseID=new JLabel("课程号:"); //使用文本框创建标签对象JLabel jlcoursename=new JLabel("课程名:");JLabel jlcount=new JLabel("课时:");JTextField jtcourseID=new JTextField(); //创建文本框对象JTextField jtcoursename=new JTextField();JTextField jtcount=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_course(){ //添加教师账号信息this.setTitle("添加课程信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlcourseID); //将控件添加到窗体this.add(title);this.add(jlcoursename);this.add(jlcount);this.add(jtcourseID);this.add(jtcoursename);this.add(jtcount);this.add(note1);this.add(note2);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加课程信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlcourseID.setBounds(180,80,100,20);jlcoursename.setBounds(180,140,100,20);jlcount.setBounds(180,200,100,20);jtcourseID.setBounds(250,80,140,20);jtcoursename.setBounds(250,140,140,20);jtcount.setBounds(250,200,140,20);note1.setBounds(400,80,140,20);note2.setBounds(400,140,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,140,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(courseID);}return false;}public void actionPerformed(ActionEvent e){courseID=jtcourseID.getText(); //获取用户输入内容coursename=jtcoursename.getText();count=jtcount.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(courseID.equals("") || coursename.equals("")){warning.setText("请输入必填信息");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Course_ID from Course");while(rs.next()){if(rs.getString(1).equals(courseID)){warning.setText("课程ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!count.equals("")){temp=stat.executeUpdate("insert intoCourse(Course_ID,Course_Name,Course_Count)values('"+courseID+"','"+coursename+"','"+count+"')");}else{temp=stat.executeUpdate("insert intoCourse(Course_ID,Course_Name) values('"+courseID+"','"+coursename+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");warning.setText("");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){warning.setText("");jtcourseID.setT ext("");jtcoursename.setText("");jtcount.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}}3.添加学生package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_student extends JFrame implements ActionListener{static add_teacher ss;String userID=""; //用户名String pwd1=""; //密码String pwd2=""; //确认密码String getsdept=""; //院系String name=""; //姓名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel note3=new JLabel("*");JLabel jlID=new JLabel("学号:"); //创建文本框对象 JLabel jlName=new JLabel("姓名:");JLabel jlPwd=new JLabel("密码:");JLabel jlPwd2=new JLabel("确认密码:");JLabel sdept=new JLabel("学院:");JTextField jtID=new JTextField();JTextField jtName=new JTextField();JPasswordField jtPwd=new JPasswordField ();JPasswordField jtPwd2=new JPasswordField ();JTextField jtsdept=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_student(){this.setTitle("添加学生账号信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlID); //将控件添加到窗体this.add(title);this.add(jlName);this.add(jlPwd);this.add(jlPwd2);this.add(sdept);this.add(jtID);this.add(jtName);this.add(jtPwd);this.add(jtPwd2);this.add(jtsdept);this.add(note1);this.add(note2);this.add(note3);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);note3.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note3.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加学生账号信息");title.setBounds(222,20,150,20);jlID.setBounds(180,60,100,20);jlName.setBounds(180,100,100,20);jlPwd.setBounds(180,140,100,20);jlPwd2.setBounds(180,180,100,20);sdept.setBounds(180,220,100,20);jtID.setBounds(250,60,140,20);jtName.setBounds(250,100,140,20);jtPwd.setBounds(250,140,140,20);jtPwd2.setBounds(250,180,140,20);jtsdept.setBounds(250,220,140,20);note1.setBounds(400,60,140,20);note2.setBounds(400,140,140,20);note3.setBounds(400,180,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,100,150,20);submit.addActionListener(this);reset.addActionListener(this);this.setSize(600,400);centerShell(this);this.setVisible(true);this.setResizable(false); //设置窗体不可变大小this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(pwd1);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入内容pwd1=jtPwd.getText();pwd2=jtPwd2.getText();getsdept=jtsdept.getText();name=jtName.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){if(userID.equals("") || pwd1.equals("") || pwd2.equals("")){ //判断是否已输入必填信息warning.setText("请输入必填信息");}else if(!pwd1.equals(pwd2)){ //判断两次输入密码是否相同warning.setText("两次输入密码不相同");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Stu_ID from Student_Info");while(rs.next()){if(rs.getString(1).equals(userID)){warning.setText("用户ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Name,Stu_Pwd,Depart)values('"+userID+"','"+name+"','"+pwd1+"','"+getsdept+"')");}else if(!name.equals("") && getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Name,Stu_Pwd) values('"+userID+"','"+name+"','"+pwd1+"')");}else if(name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Pwd,Depart) values('"+userID+"','"+pwd1+"','"+getsdept+"')");}else{temp=stat.executeUpdate("insert intoStudent_Info(Stu_ID,Stu_Pwd) values('"+userID+"','"+pwd1+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){ //重置所有控件warning.setText("");jtID.setText("");jtName.setText("");jtPwd.setText("");jtPwd2.setText("");jtsdept.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}//public static void main(String args[]){// new add_student();//}}4.添加教师package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_teacher extends JFrame implements ActionListener{static add_teacher ss;String userID=""; //用户名String pwd1=""; //密码String pwd2=""; //确认密码String getsdept=""; //院系String name=""; //姓名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel note3=new JLabel("*");JLabel jlID=new JLabel("教工号:"); //使用文本框创建标签对象 JLabel jlName=new JLabel("姓名:");JLabel jlPwd=new JLabel("密码:");JLabel jlPwd2=new JLabel("确认密码:");JLabel sdept=new JLabel("学院:");JTextField jtID=new JTextField(); //创建文本框对象JTextField jtName=new JTextField();JPasswordField jtPwd=new JPasswordField ();JPasswordField jtPwd2=new JPasswordField ();JTextField jtsdept=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_teacher(){ //添加教师账号信息this.setTitle("添加教师账号信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlID); //将控件添加到窗体this.add(title);this.add(jlName);this.add(jlPwd);this.add(jlPwd2);this.add(sdept);this.add(jtID);this.add(jtName);this.add(jtPwd);this.add(jtPwd2);this.add(jtsdept);this.add(note1);this.add(note2);this.add(note3);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);note3.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note3.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加教师账号信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlID.setBounds(180,60,100,20);jlName.setBounds(180,100,100,20);jlPwd.setBounds(180,140,100,20);jlPwd2.setBounds(180,180,100,20);sdept.setBounds(180,220,100,20);jtID.setBounds(250,60,140,20);jtName.setBounds(250,100,140,20);jtPwd.setBounds(250,140,140,20);jtPwd2.setBounds(250,180,140,20);jtsdept.setBounds(250,220,140,20);note1.setBounds(400,60,140,20);note2.setBounds(400,140,140,20);note3.setBounds(400,180,140,20);submit.setBounds(200,270,60,20);reset.setBounds(300,270,60,20);warning.setBounds(420,100,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(pwd1);}return false;}public void actionPerformed(ActionEvent e){userID=jtID.getText(); //获取用户输入内容pwd1=jtPwd.getText();pwd2=jtPwd2.getText();getsdept=jtsdept.getText();name=jtName.getText();int temp=0,flag=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(userID.equals("") || pwd1.equals("") || pwd2.equals("")){warning.setText("请输入必填信息");}else if(!pwd1.equals(pwd2)){ //判断两次输入密码是否一致warning.setText("两次输入密码不相同");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Tea_ID from Teacher_Info");while(rs.next()){if(rs.getString(1).equals(userID)){warning.setText("用户ID已存在");flag=1; //判断用户名唯一break;}}if(flag!=1){if(!name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Names,T ea_Pwd,Depart)values('"+userID+"','"+name+"','"+pwd1+"','"+getsdept+"')");}else if(!name.equals("") && getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Names,T ea_Pwd)values('"+userID+"','"+name+"','"+pwd1+"')");}else if(name.equals("") && !getsdept.equals("")){temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Pwd,Depart) values('"+userID+"','"+pwd1+"','"+getsdept+"')");}else{temp=stat.executeUpdate("insert intoTeacher_Info(Tea_ID,Tea_Pwd) values('"+userID+"','"+pwd1+"')");}}if(temp==1){JOptionPane.showMessageDialog(ss,"添加成功");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch(Exception ex){ex.getStackTrace();}}}else if(e.getSource()==reset){warning.setText("");jtID.setText("");jtName.setText("");jtPwd.setText("");jtPwd2.setText("");jtsdept.setText("");}}private void centerShell(JFrame shell) //窗口在屏幕中间显示{//得到屏幕的宽度和高度int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;//得到Shell窗口的宽度和高度int shellHeight = shell.getBounds().height;int shellWidth = shell.getBounds().width;//如果窗口大小超过屏幕大小,让窗口与屏幕等大if(shellHeight > screenHeight)shellHeight = screenHeight;if(shellWidth > screenWidth)shellWidth = screenWidth;//让窗口在屏幕中间显示shell.setLocation(((screenWidth - shellWidth)/ 2),((screenHeight - shellHeight)/2));}// public static void main(String[] args){// new add_teacher();// }}5.添加授课信息package SIMS;import javax.swing.*;import java.sql.*;import java.awt.*;import java.awt.event.*;public class add_tc extends JFrame implements ActionListener{static add_tc ss;String courseID=""; //课程名String teachername=""; //课程名JLabel warning=new JLabel(); //输入信息提示框JLabel title=new JLabel();JLabel note1=new JLabel("*");JLabel note2=new JLabel("*");JLabel jlcourseID=new JLabel("课程号:"); //使用文本框创建标签对象JLabel jlteachername=new JLabel("教师号:");JTextField jtcourseID=new JTextField(); //创建文本框对象JTextField jtteachername=new JTextField();JButton submit=new JButton("添加"); //创建按钮对象JButton reset=new JButton("重置");public add_tc(){ //添加授课信息this.setTitle("添加授课信息"); //设置窗口标题this.setLayout(null); //设置窗口布局管理器this.add(jlcourseID); //将控件添加到窗体this.add(jlteachername);this.add(title);this.add(jtcourseID);this.add(jtteachername);this.add(note1);this.add(note2);this.add(submit);this.add(reset);this.add(warning);title.setFont(new Font("red",Font.BOLD,15)); //设置提示字体title.setForeground(Color.red);note1.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note1.setForeground(Color.red);note2.setFont(new Font("red",Font.BOLD,20)); //设置提示字体note2.setForeground(Color.red);warning.setFont(new Font("red",Font.BOLD,12)); //设置提示字体warning.setForeground(Color.red);title.setText("添加授课信息"); //设置控件及窗体位置大小title.setBounds(222,20,150,20);jlcourseID.setBounds(180,80,100,20);jlteachername.setBounds(180,140,100,20);jtcourseID.setBounds(250,80,140,20);jtteachername.setBounds(250,140,140,20);note1.setBounds(400,80,140,20);note2.setBounds(400,140,140,20);submit.setBounds(200,250,60,20);reset.setBounds(300,250,60,20);warning.setBounds(420,140,150,20); //设置提示框位置大小submit.addActionListener(this); //添加监听器reset.addActionListener(this);this.setSize(600,400); //设置窗体大小centerShell(this); //设置窗口位置在屏幕中央this.setResizable(false); //设置窗体不可变大小this.setVisible(true); //设置窗口可见性this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}public boolean equals(Object obj){ //重写equals方法判断字符串相等if(obj==null)return false;if(this == obj){return true;}if(obj instanceof String) {String str = (String)obj;return str.equals(courseID);}return false;}public void actionPerformed(ActionEvent e){courseID=jtcourseID.getText(); //获取用户输入内容teachername=jtteachername.getText();int temp=0,flag1=0,flag2=0,flag3=0;Connection con=null;if(e.getSource()==submit){ //判断是否已输入必填信息if(courseID.equals("") || teachername.equals("")){warning.setText("请输入必填信息");}else{try{String url="jdbc:odbc:SIMS"; //连接数据库con=DriverManager.getConnection(url,"",""); //获取连接字符串Statement stat=con.createStatement();ResultSet rs=stat.executeQuery("select Course_ID from Course");while(rs.next()){if(rs.getString(1).equals(courseID)){flag1=1; //判断课程ID存在break;}}ResultSet rss=stat.executeQuery("select Tea_ID fromTeacher_Info");while(rss.next()){if(rss.getString(1).equals(teachername)){flag2=1; //判断教师ID存在break;}}if(flag1!=1){warning.setText("课程ID不存在");}else if(flag2!=1){warning.setText("教师ID不存在");}ResultSet rsss=stat.executeQuery("select Course_ID,T ea_ID from tc");while(rsss.next()){if(rsss.getString(1).equals(courseID) &&rsss.getString(2).equals(teachername)){flag3=1;warning.setText("授课信息重复");。
c语言课程设计报告+学生成绩信息管理系统+源代码
![c语言课程设计报告+学生成绩信息管理系统+源代码](https://img.taocdn.com/s3/m/a29ea979fab069dc51220176.png)
实验报告一、问题陈述及其需求分析(一)问题陈述学生信息管理系统是对学生信息的基本管理,其中包括以下及模块:(1)增加一个学生的信息(需输入要增加学生的所有信息);(2)统计本班学生总人数及男女生人数。
(3)分别按照学号查找学生的信息;若找到则输出该学生全部信息,否则输出查找不到的提示信息。
(4)按学号对所有学生信息排序,并输出结果;(5)删除一个学生的信息(需指定要删除学生的学号);同时显示删除后的结果。
(二)功能需求分析学生信息管理系统设计学生信息包括:学号,姓名,性别,出生年月,电话使之提供以下功能:1、系统以菜单方式工作2、建立链表并显示3、插入新的学生信息4、删除某学号的学生信息5、查找某学号的学生信息6、对学生信息排序7、统计学生人数8、输出学生信息二总体设计(一)模块依据程序的数据结构,描述该程序的层次结构,如下图:1、建立链表并显示voidcreatelist(structstucode**r);2、插入新的学生信息voidinsert(structstucode**r);3、删除某学号的学生信息voiddel(structstucode**r);4、查找某学号的学生信息voidsearch1(structstucode*r);5、对学生信息排序voidsort(structstucode**r);6、统计学生人数voidsearch2(structstucode*r);7、输出学生信息voidout(structstucode*r);(二)程序总体框架模块层次结构,只确定了模块之间的关系和函数原型,不是程序的执行步骤。
程序总体框架是该程序的总体流程图。
改程序不是顺序连续地执行全部功能,而是在某一时刻有选择地执行一种或多种功能。
因此选用菜单方式是较佳的方案,程序总体框架如下图:(三)运行环境(软,硬件环境)硬件:CPU,内存,主板,硬盘,显卡,键盘,显示器等等。
软件:WindowsXPtruboc应用软件。
学生成绩管理系统的设计与实现代码
![学生成绩管理系统的设计与实现代码](https://img.taocdn.com/s3/m/4021a362a9956bec0975f46527d3240c8447a1a8.png)
学生成绩管理系统的设计与实现代码本系统有增加学生记录、修改学生记录、删除学生记录、按姓名查询学生记录、按C语言成绩对学生进行排序、退出系统6大功能。
能够对学生的姓名,学号,c语言成绩做相应的操作。
在检测到输入成绩大于55时,会自动加上5。
该管理系统设计功能模块图:下面是源代码:#include "stdio.h"#include "string.h"/*定义学生结构体*/struct Student{char ID[20]; //学号char Name[20]; //姓名float C_Mark; //C语言成绩};/*声明学生数组及学生数量*/struct Student students[1000];int num=0;/*通过学号返回数组下标*/int Student_SearchByIndex(char id[]) {int i;for (i=0;i<num;i++){if (strcmp(students[i].ID,id)==0) {return i;}}return -1;}/*通过姓名返回数组下标*/int Student_SearchByName(char name[]) {int i;for (i=0;i<num;i++){if (strcmp(students[i].Name,name)==0){return i;}}return -1;}/*显示单条学生记录*/void Student_DisplaySingle(int index){printf("%10s%10s%8s\n","学号","姓名","C语言成绩");printf("-------------------------------------------------------------\n");printf("%10s%10s%8.2f\n",students[index].ID,students[index] .Name,students[index].C_Mark);}/****1、增加学生记录*****/void Student_Insert(){while(1){printf("请输入学号:");scanf("%s",&students[num].ID);getchar();printf("请输入姓名:");scanf("%s",&students[num].Name);getchar();printf("请输入C语言成绩:");scanf("%f",&students[num].C_Mark);getchar();if (54<students[num].C_Mark && students[num].C_Mark< 60) //把55~59分之间的成绩都加上5分{students[num].C_Mark += 5;}num++;printf("是否继续?(Y/N),继续请按任意键,否则输入N:");if (getchar()=='N'){break;}}}/******2、修改学生信息**********/void Student_Modify(){while(1){char id[20];int index;printf("请输入要修改的学生的学号:");scanf("%s",&id);getchar();index=Student_SearchByIndex(id);if (index==-1){printf("该学生不存在!\n");}else{printf("你要修改的学生信息为:\n");Student_DisplaySingle(index);printf("-- 请输入新值--\n");printf("请输入学号:");scanf("%s",&students[index].ID);getchar();printf("请输入姓名:");scanf("%s",&students[index].Name);getchar();printf("请输入C语言成绩:");scanf("%f",&students[index].C_Mark);getchar();}printf("是否继续?(Y/N),继续请按任意键,否则输入N:");if (getchar()=='N'){break;}}}/****3、删除学生信息****/void Student_Delete(){int i;while(1){char id[20];int index;printf("请输入要删除的学生的学号:");scanf("%s",&id);getchar();index=Student_SearchByIndex(id);if (index==-1){printf("学生不存在!\n");}else{printf("你要删除的学生信息为:\n");Student_DisplaySingle(index);printf("是否真的要删除?(Y/N)");if (getchar()=='Y'){for (i=index;i<num-1;i++){students[i]=students[i+1];//把后边的对象都向前移动}num--;}getchar();printf("已删除\n");}printf("是否继续删除?(Y/N),继续请按任意键,否则输入N:");if (getchar()=='N'){break;}}}/****4、按姓名查询******/void Student_Select(){while(1){char name[20];int index;printf("请输入要查询的学生的姓名:");scanf("%s",&name);getchar();index=Student_SearchByName(name);if (index==-1){printf("学生不存在!\n");}else{printf("你要查询的学生信息为:\n");Student_DisplaySingle(index);}printf("是否继续?(Y/N),继续请按任意键,否则输入N:");if (getchar()=='N'){break;}}}/******5、按C语言成绩排序*******/void Student_SortByAverage(){int i,j;struct Student tmp;for (i=0;i<num;i++){for (j=1;j<num-i;j++){if (students[j-1].C_Mark<students[j].C_Mark){tmp=students[j-1];students[j-1]=students[j];students[j]=tmp;}}}}/*显示学生信息*/void Student_Display(){int i;printf("%10s%10s%8s\n","学号","姓名","成绩");printf("-------------------------------------------------------------\n");for (i=0;i<num;i++){printf("%10s%10s%8.2f\n",students[i].ID,students[i].Name ,students[i].C_Mark);}}/*将学生信息从文件(Database.txt)中读出*/void IO_ReadInfo(){FILE *fp;int i;if ((fp=fopen("Database.txt","rb"))==NULL){printf("不能打开文件!\n");return;}if (fread(&num,sizeof(int),1,fp)!=1){num=-1;}else{for(i=0;i<num;i++){fread(&students[i],sizeof(struct Student),1,fp);}}fclose(fp);}/*将学生信息写入文件(Database.txt)*/void IO_WriteInfo(){FILE *fp;int i;if ((fp=fopen("Database.txt","wb"))==NULL){printf("不能打开文件!\n");return;}if (fwrite(&num,sizeof(int),1,fp)!=1){printf("写入文件错误!\n");}for (i=0;i<num;i++){if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1){printf("写入文件错误!\n");}}fclose(fp);}/***********主程序*********/void main(){int choice;IO_ReadInfo(); //读取文件while(1){/*主菜单*/printf("\n------ 学生成绩管理系统------\n");printf("1. 增加学生记录\n");printf("2. 修改学生记录\n");printf("3. 删除学生记录\n");printf("4. 按姓名查询学生记录\n");printf("5. 按C语言成绩排序\n");printf("6. 退出\n");printf("请选择(1-6):");scanf("%d",&choice);getchar();switch(choice){case 1:Student_Insert();break;case 2:Student_Modify();break;case 3:Student_Delete();break;case 4:Student_Select();break;case 5:Student_SortByAverage();Student_Display();break;case 6:exit(0);break;}IO_WriteInfo();}}1234567891011121415161718192021222324252627282930313233343637383940414243444546474849505152535455565859606162636465666768697071727374757677788081828384858687888990919293949596979899 100102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320322323324325326327328329330331332333334335336337338运行结果:测试第一个功能,输入四个学生的成绩:测试第二个功能,修改学生记录:测试第三个功能,删除学生记录:测试第四个功能,按姓名查询学生记录:测试第五个功能,显示所有学生的成绩,按照C语言成绩由高到底排序:我们可以看到,各项功能的实现,在第2个步骤中,将赵的成绩改为80,而第3个步骤删除了李的成绩。
学生信息管理系统c语言版源代码
![学生信息管理系统c语言版源代码](https://img.taocdn.com/s3/m/fdae52d7bb68a98270fefa35.png)
学生信息管理系统c语言版源代码#include <stdio.h> #include <string.h> #include <stdlib.h> #include <conio.h> #define N 1000typedef struct student {int number;char name[20];int grade;int gaoshu;int yingyu;int jisuanji;int sum;}STUDENT;STUDENT student[N]; int shuliang=0;void menu();void fhzjm(){char biaozhi[20];printf("\n");printf("还需要操作么,如果需要操作请输入:yes,否则请输入:no\n");scanf("%s",biaozhi);if(strcmp(biaozhi,"yes")==0){menu();}else if(strcmp(biaozhi,"no")==0)exit(0);else{printf("请输入正确的字符,谢谢~\n"); fhzjm();}}void DengJi(){int rs;int i,k=1;system("CLS");printf("请输入需要输入几个学生信息:"); scanf("%d",&rs);for(i=shuliang;i<shuliang+rs;i++,k++) {printf("请输入第%d个学生的学号:",k); scanf("%d",&student[i].number);printf("请输入学生的姓名:");scanf("%s",student[i].name);printf("请输入学生3门课的成绩:"); printf("请输入第1门课的成绩:");scanf("%d",&student[i].gaoshu);printf("请输入第2门课的成绩:");scanf("%d",&student[i].yingyu);printf("请输入第3门课的成绩:");scanf("%d",&student[i].jisuanji);}shuliang=shuliang+rs;fhzjm();}void ShanChu(){char shanchuinfo[10];system("CLS");printf("删除全部学生信息请输入\"all\",删除指定学号的学生信息请输入\"one\"\n");scanf("%s",shanchuinfo);if(strcmp(shanchuinfo,"all")==0){int j;printf("你删除的学生信息如下:\n");printf("-----------学号-------------姓名-------------高数--------------英语--------------计算机\t\n");for(j=0;j<shuliang;j++)printf("----%d-------%s-------%d-------%d-------%d\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].jisuanji);shuliang=0;printf("删除成功\n\n");}else if(strcmp(shanchuinfo,"one")==0){struct student *p=NULL;int choice;int i,j,k=0;printf("请输入你要删除的人的学号:");scanf("%d",&choice);for(i=0;i<shuliang;i++){if(choice==student[i].number){k=1;j=i;break;}}if(k){if(shuliang==1){p=&student[0];free(p);shuliang=0;}else{for(i=j;i<shuliang;i++) {student[i]=student[i+1];}shuliang=shuliang-1;}printf("删除成功\n\n");}else{printf("输入数据错误~\n"); }}fhzjm();}void LiuLan(){int i;system("CLS");if(shuliang==0){printf("系统里面没有任何学生的信息~\n");}else{for(i=0;i<shuliang;i++){printf("第%d个学生的学号为:%d\n",i+1,student[i].number);printf("第%d个学生的姓名为:%s\n",i+1,student[i].name);printf("第%d个学生的第一门课的成绩为:%d\n",i+1,student[i].gaoshu);printf("第%d个学生的第二门课的成绩为:%d\n",i+1,student[i].yingyu);printf("第%d个学生的第三门课的成绩为:%d\n",i+1,student[i].jisuanji);student[i].sum=student[i].gaoshu+student[i].yingyu+student[i].jisuan ji;printf("第%d个学生的总成绩为:%d\n",i+1,student[i].sum);}}fhzjm();}void ChaZhao(){int xx;char choice,yy[20];int i,j,k=0;system("CLS");if(shuliang==0){printf("系统里面没有任何学生的信息~\n");fhzjm();}printf("三种查找方式:学号,姓名,成绩\n");printf("如果按学号查找请输1,如果按姓名查找请输2,如果按成绩查找请输3\n");printf("请输入您查找的方式:");scanf("%s",&choice);if(choice=='1'){printf("请输入需要查找学生的学号:");scanf("%d",&xx);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数成绩----英语成绩----计算机成绩----\t\n");for(i=0;i<shuliang;i++){if(xx==student[i].number){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].yingyu,student[i].jis uanji);}}if(k==0)printf("输入信息有误:\n");}else if(choice=='2'){printf("请输入需要查找学生的姓名:\n");scanf("%s",yy);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数成绩----英语成绩----计算机成绩----\t\n");for(i=0;i<shuliang;i++){if(strcmp(yy,student[i].name)==0){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].yingyu,student[j].jis uanji);}}if(k==0)printf("输入信息有误:\n");}else if(choice=='3'){printf("请输入需要查找学生的成绩:\n");scanf("%d",&xx);printf("您所查找的学生的信息为:\n");printf("----学号----姓名----高数----英语----计算机----\t\n");for(i=0;i<shuliang;i++){if(xx==student[i].grade){j=i;k=1;printf("----%d-------%s-------%d-------%d-------%d----\t\n",student[j].number,student[j].name,student[j].gaoshu,student[j].yingyu,student[i].jis uanji);}}if(k==0)printf("输入信息有误:\n");}fhzjm();}void PaiXu(){struct student *p1[N],**p2,*temp;int i,j;system("CLS");p2=p1;for( i=0;i<shuliang;i++){p1[i]=student+i;}for( i=0;i<shuliang;i++){for( j=i+1;j<shuliang;j++){if((*(p2+i))->sum<(*(p2+j))->sum){temp=*(p2+i);*(p2+i)=*(p2+j);*(p2+j)=temp;} }}printf("按照总成绩排序之后的信息为:\n");printf("----学号----姓名----总成绩----\t\n");for( i=0;i<shuliang;i++){student[i].sum=student[i].gaoshu+student[i].yingyu+student[i].jisuan ji;printf("----%d-----%s----%d-----\n",(*(p2+i))->number,(*(p2+i))->name,(*(p2+i))->sum);}fhzjm();}void CunChu(){int i;FILE *rs;if((rs=fopen("student.txt","w"))==NULL){printf("not open");exit(0);}for(i=0;i<shuliang;i++){fwrite(&student[i], sizeof(student[i]), 1, rs); }if(ferror(rs)){fclose(rs);perror("写文件失败~\n");return;}printf("存储文件成功~\n");fclose(rs);fhzjm();}void DaoChu(){struct student t;int i=0;FILE* fp = fopen("student.txt", "r");shuliang=0;if(NULL==fp){perror("读取文件打开失败~\n");return;}memset(student,0x0,sizeof(student));while(1){fread(&t,sizeof(t),1,fp);if(ferror(fp)){fclose(fp);perror("读文件过程失败~\n");return;}if(feof(fp)){break;}student[i]=t;i++;}fclose(fp);shuliang=i; printf("导出文件成功~\n"); fhzjm();}void menu(){int n=0;system("CLS");printf(" 学生信息管理系统\n");printf(" 作者:陈椿\n");printf("-------------------MENU-----------------\n"); printf(" 1.登记学生信息\n");printf(" 2.删除学生信息\n");printf(" 3.浏览所有已经登记的学生\n");printf(" 4.查找\n");printf(" 4.1按学号查找\n");printf(" 4.2按姓名查找\n");printf(" 4.3按成绩查找\n");printf(" 5.根据总成绩排序\n");printf(" 6.存储到文件\n");printf(" 7.从文件导出\n");printf(" 8.退出系统\n");a: printf(" 请选择:");scanf("%d",&n);switch (n){case 1:DengJi();break;case 2:ShanChu();break;case 3:LiuLan();break;case 4:ChaZhao();break;case 5:PaiXu();break;case 6:CunChu();break;case 7:DaoChu();break;case 8:exit(0);break;default:{printf("请输入1-8之间的数字,谢谢~\n"); goto a;}}}main() {menu();}。
学生管理系统c语言源代码
![学生管理系统c语言源代码](https://img.taocdn.com/s3/m/3b1c2f0cf02d2af90242a8956bec0975f465a4b4.png)
学生管理系统c语言源代码学生管理系统c语言源代码#include stdio.h#include dos.h#include string.h#include stdlib.h#include malloc.h#define SIZE 8struct student{char name;char num;int score;float ave;struct student *next;}stu[SIZE],temp,s;void shuru(){int i,j,sum,length,flag=1,a;FILE *fp;while(flag==1){printf(“Define a rangeclass number:");scanf("%d",printf("Input the total number of the class(a):"); scanf("%d",length);if(lengtha)flag=0;}for(i=0;ilength;i++){printf("\n请输入学生的信息:");printf("\n输入姓名:");scanf("%s",stu[i].name);printf("\n输入序号.:");scanf("%s",stu[i].num);printf("\n输入成绩:\n");sum=0;for(j=0;jj++){printf("score %d:",j+1);scanf("%d",stu[i].score[j]);sum+=stu[i].score[j];}stu[i].ave=sum/3.0;}学生管理系统c语言源代码fp=fopen("stu1.txt","w");for(i=0;ilength;i++)if(fwrite(stu[i],sizeof(struct student),1,fp)!=1)printf("File write error\n");fclose(fp);fp=fopen("stu1.txt","r");printf("\name\ NO. score1 score2 score3 sum ave\n");for(i=0;ilength;i++){fread(stu[i],sizeof(struct student),1,fp);printf("%3s%5s%7d%7d%7d%7d%10.2f\n",stu[i].name,stu[i].num,stu[i ].score,stu[i].score,stu[i].score,sum=stu[i].score+stu[i].score+stu[i].score,stu[i].ave);}}void chaxun(){ FILE *fp, *fp1;char n,name;int i,j,k,t,m,flag=1;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\noriginal data:\n");k=i;printf("\nPlease select the menu(1.number ):"); scanf("%d",switch(m){case 1:printf("\nchaxun number:");scanf("%s",n);for(flag=1,i=0;ii++){if(strcmp(n,stu[i].num)==0){j=i;flag=0;break;}}break;case 2:printf("\nchaxun name:");scanf("%s",name);for(flag=1,i=0;ii++){if(strcmp(name,stu[i].name)==0){j=i;flag=0;break;学生管理系统c语言源代码}}}if(!flag){printf("\nYou can find:\n");fp1=fopen("stu2.txt","w");printf(" name NO. score1 score2 score3ave\n");fwrite(stu[j],sizeof(struct student),1,fp1);printf("%-15s%11s%7d%7d%7d%10.2f",stu[j].name,stu[j].num,stu[j].score,stu[j].score,stu[j].score,stu[j].ave);}else printf("\nNot found!");fclose(fp);fclose(fp1);}xiugai(){ int a;printf("\nplease select the menu(1.CHARU 2.__ ):");scanf("%d",switch(a){case 1:Insert(); break;case 2:Delete(); break;}}Insert(){ FILE *fp;int i,j,t,n;printf("\nNO.:");scanf("%s",s.num);printf("name:");scanf("%s",);printf("score1,score2,score3:");scanf("%d,%d,%d",s.score,s.score,s.score);s.ave=(s.score+s.score+s.score)/3.0;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\noriginal data:\n");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++) {printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)学生管理系统c语言源代码printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;for(t=0;stu[t].aves.avett++);printf("\nnow:\n");fp=fopen("stu1.txt","w");for(i=0;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fwrite(s,sizeof(struct student),1,fp);printf("\n%-15s%11s%7d%7d%7d%10.2f",,s.num,s.score,s.score, s.score,s.ave);for(i=t;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);}Delete(){ FILE *fp;int i,j,t,n,flag;char number;if((fp=fopen("stu1.txt","rb"))==NULL){printf("Can not open the file.");exit(0);}printf("\noriginal data:");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++) {printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;学生管理系统c语言源代码printf("\nInput number deleted:");scanf("%s",number);for(flag=1,i=0;flagii++){if(strcmp(number,stu[i].num)==0){for(t=i;tt++){strcpy(stu[t].num,stu[t+1].num);strcpy(stu[t].name,stu[t+1].name);for(j=0;jj++)stu[t].score[j]=stu[t+1].score[j];stu[t].ave=stu[t+1].ave;}n=n-1;elseprintf("\n Not found!");printf("\nNow,the content of file:\n");fp=fopen("stu1.txt","wb");for(i=0;ii++)fwrite(stu[i],sizeof(struct student),1,fp);fclose(fp);fp=fopen("stu1.txt","r");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++)printf("%-15s%11s%7d%7d%7d%10.2f\n",stu[i].name,stu[i].num,stu[i].score, stu[i].score,stu[i].score,stu[i].ave);fclose(fp);}paixu(){FILE *fp;int i,j,n;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\nfile'stu1.txt':");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++) {printf("\n%-15s%11s",stu[i].name,stu[i].num);for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);n=i;for(i=0;ii++)for(j=i+1;jj++)学生管理系统c语言源代码if(stu[i].avestu[j].ave){temp=stu[i];stu[i]=stu[j];stu[j]=temp;}printf("\nnow:");fp=fopen("stu1.txt","w");for(i=0;ii++){fwrite(stu[i],sizeof(struct student),1,fp);printf("\n%-15s%11s",stu[i].name,stu[i].num);tongji(){ FILE *fp;int i,j,k,labe1,b;int a5=0;int a6=0;int a7=0;int a8=0;int a9=0; int a10=0; float t;if((fp=fopen("stu1.txt","r"))==NULL){printf("Can not open the file.");exit(0);}printf("\nfile'stu1.txt':");for(i=0;fread(stu[i],sizeof(struct student),1,fp)!=0;i++){printf("\n%-15s%11s",stu[i].name,stu[i].num); for(j=0;jj++)printf("%7d",stu[i].score[j]);printf("%10.2f",stu[i].ave);}fclose(fp);k=i;for(i=0;ii++){labe1=0;if(stu[i].ave60){labe1++;t=labe1/(float)k*100;}}printf("\nbujigelv:");printf("%f%",t);printf("\n");for(j=0;jj++){a5=0;a6=0;a7=0;a8=0;a9=0;a10=0;k=i;printf("kemu is %d:\n",j);for(i=0;ii++)学生管理系统c语言源代码{b=stu[i].score[j]/10;if(b6)a5++;elseif(b=6b7)a6++;elseif(b=7b8)a7++;elseif(b=8b9)a8++;if(b=9b10)a9++;elseif(b==10)a10++;}printf(" 不及格is %d\n",a5);printf(" 60--69 is %d\n",a6);printf(" 70--79 is %d\n",a7);printf(" 80--89 is %d\n",a8);printf(" 90--99 is %d\n",a9);printf(" 100 is %d\n",a10);}}main(){int a;printf(" ____\n"); printf(" 欢迎进入学生成绩管理系统\n");printf(" ____\n"); while(1){printf("\n选择菜单:\n");printf("\n");printf(" 1.输入 2.查询 3.排序 4.修改 5.统计 6.退出\n"); scanf("%d",switch(a){case 1: shuru();break;case 2: chaxun(); break;case 3: paixu(); break;case 4: xiugai(); break;学生管理系统c语言源代码case 5: tongji();break; case 6: exit(0); }。
学生管理系统 C语言代码
![学生管理系统 C语言代码](https://img.taocdn.com/s3/m/b0b67079168884868762d6b5.png)
#include"stdio.h"#include"stdlib.h"#include"string.h"struct stu_info1{char num[13];//学号char name[10];//姓名char sex[5];//性别char cls[20];//班级}stu1[6];struct stu_info2{char counum[6];//课程号char counam[20];//课程名称int credit;//学分}stu2[6];struct stu_info3{char num[13];//学号char counum[6];//课程号float results;//分数}stu3[12];struct stu_info4{char num[13];//学号char counum[6];//课程号float results;//分数}stu4[12];int n=11;void main(){void gengxin();void input1();void input2();void input3();void output();void xianshi();void chaxun();void printf1();void printf2();input1();input2();output();int i;loop: ;printf("*************欢迎使用分数查询系统*************\n");printf("** 请选择**\n");printf("** 1.录入2.删除无用信息(管理员功能) **\n");printf("** 3.显示4.查询(学生功能) **\n");printf("** 5.显示学生信息6.显示课程信息**\n");printf("** 7.退出**\n");printf("**********************************************\n");scanf("%d",&i);switch(i){case 1: input3();break;case 2:gengxin();break;case 3:xianshi();goto loop;case 4: chaxun();goto loop;case 5: printf1();goto loop;case 6: printf2();goto loop;case 7:break;default:printf("error");break;}}void input1()//录入结构体stu1[]{int i;FILE *fp;if((fp=fopen("A.txt","r"))==NULL){printf("can not open file\n");exit(0);}/* printf(" 学号姓名性别班级\n");*/for(i=0;i<=5;i++){fscanf(fp,"%s%s%s%s",&stu1[i].num,&stu1[i].name,&stu1[i].sex,&stu1[i].cls);/*printf("%-13s %-10s %-5s %-20s\n",stu1[i].num,stu1[i].name,stu1[i].sex,stu1[i] .cls);*/}fclose(fp);}void input2()//录入结构体stu2[]{int i;FILE *fp;if((fp=fopen("B.txt","r"))==NULL){printf("can not open file\n");exit(0);}for(i=0;i<=5;i++){fscanf(fp,"%s%s%d",&stu2[i].counum,&stu2[i].counam,&stu2[i].credit);}fclose(fp);}void input3()//录入成绩{FILE *fp;fp=fopen("C.txt","w");int a,i,j,k;float cetss;char number[13],cnum[6],mima[10];printf("请输入管理员密码\n");scanf("%s",mima);if(strcmp(mima,"abc111")==0){printf("请输入要录入学生成绩的个数\n");scanf("%d",&a);for(i=1;i<=a;i++){printf("请输入要录入的第%d同学的学号:",i);scanf("%s",number);printf("请输入要录入的第%d同学的课程号:",i);scanf("%s",cnum);for(j=0;j<=5;j++)//学号{if((strcmp(number,stu1[j].num)==0))break;}if(j<=5){for(k=0;k<=5;k++)//课程号{if(strcmp(cnum,stu2[k].counum)==0){printf("请输入要录入同学的成绩:");scanf("%f",&cetss);fprintf(fp,"%s %s %f\n",number,cnum,cetss);break;}}}if(j>5||k>5){printf("Error,please input again");i=i-1;}printf("录入成功\n");}}else{printf("密码错误\n");}}void output()// 录入结构体stu3[]{int i;FILE *fp=fopen("C.txt","r");for(i=0;i<n;i++){fscanf(fp,"%s%s%f",&stu3[i].num,&stu3[i].counum,&stu3[i].results);/*printf("%s%s%f\n",stu3[i].num,stu3[i].counum,stu3[i].results);*/ }fclose(fp);}void xianshi()// 显示成绩{int i,j;for(i=0;i<n;i++){for(j=0;j<6;j++){if((strcmp(stu3[i].num,stu1[j].num))==0)printf("%s\t",stu1[j].name);}for(j=0;j<6;j++){if(strcmp(stu3[i].counum,stu2[j].counum)==0)printf("%s\t",stu2[j].counam);}printf("%3.1f\n",stu3[i].results);}}void chaxun()//查询功能{char number[13],c;int i,j,k,a,b,d;while((c=getchar())!='Q'){a=0,b=0;//a记录学分b记录学科printf("请输入要查询同学的学号\n");scanf("%s",number);for(i=0;i<n;i++){if(strcmp(number,stu3[i].num)==0){printf("学号:%s\t",stu3[i].num);for(j=0;j<6;j++){if(strcmp(stu3[i].num,stu1[j].num)==0){printf("姓名:%s\n",stu1[j].name);}}break;}}d=i;for(i=0;i<n;i++)if(strcmp(number,stu3[i].num)==0){b=b+1;for(j=0;j<6;j++){if(strcmp(stu3[i].num,stu1[j].num)==0){for(k=0;k<6;k++){if(strcmp(stu3[i].counum,stu2[k].counum)==0)break;}break;}}if(stu3[i].results>=60){a=a+stu2[k].credit;printf("课程号:%s\t课程名称:%s\t成绩:%3.1f\t实得学分:%d\n",stu3[i].counum,stu2[k].counam,stu3[i].results,stu2[k].credit);}elseprintf("课程号:%s\t课程名称:%s\t成绩:%3.1f\t实得学分:%d\n",stu3[i].counum,stu2[k].counam,stu3[i].results,0);}if(d<n){printf("共修%d科\t\t实得总学分:%d\n",b,a);}else{printf("学号输入错误\n");}getchar();printf("退出请按Q+回车,继续查询请按回车键");}}void gengxin()//更新信息,删除C.txt中无用信息{FILE *fp;int i,j,k;char mima[10];printf("请输入管理员密码\n");scanf("%s",mima);if(strcmp(mima,"abc111")==0){fp=fopen("C.txt","w");for(i=0;i<n;i++){for(j=0;j<6;j++)if(strcmp(stu3[i].num,stu1[j].num)==0){for(k=0;k<=5;k++)if(strcmp(stu3[i].counum,stu2[k].counum)==0)break;if(k<=5){fprintf(fp,"%s %s %f\n",stu3[i].num,stu3[i].counum,stu3[i].results);}}}printf("更新C.txt成功\n");fclose(fp);}else{printf("密码错误\n");}}void printf1()//显示学生信息{int i;printf(" 学号姓名性别班级\n");for(i=0;i<=5;i++){printf("%-13s%-10s%-5s %-20s\n\n",stu1[i].num,stu1[i].name,stu1[i].sex,stu1[i].cls);}}void printf2()//显示课程信息{int i;printf(" 课程编号课程名称学分\n");for(i=0;i<=5;i++){printf("%-6s%-20s %-4d\n\n",stu2[i].counum,stu2[i].counam,stu2[i].credit);}}。
课程设计:学生学籍管理系统源代码
![课程设计:学生学籍管理系统源代码](https://img.taocdn.com/s3/m/c72b8ff2581b6bd97e19eab8.png)
#include”stdio。
h”#include"conio。
h”#include"stdlib。
h”#include”string。
h"#define N 1000 //N为可输入的学生总人数,可根据需要更改#define M 2 //M为宏定义的(在创建密码函数中)可建立的登陆用户个数,可更改struct student //定义学生信息结构体数组{char num[9]; //学号char name[20]; //姓名char depar[15]; //院系char zhuanye[15];//专业char classes[5]; //班级char age[3];//年龄char sex[4]; //性别char nation[5]; //民族char birth[9]; //出生日期char add[10];//籍贯};struct code //定义密码结构体数组{char name[20];char code[7];}co[M],s0;//确认是否新创建密码文件模块int code(){FILE *fp;if((fp=fopen("学生学籍管理系统__code。
txt","rt"))==NULL){printf(”密码文件不存在,请输入新的用户名及密码:\n");//若不存在此密码文件,则提示用户创建密码printf("请输入任意键继续!”);getch();system("cls");return 1; //无密码文件返回1 }elsereturn 0; //已有密码文件返回0 }//新创建初始密码void code_input(){FILE *fp;int i;if((fp=fopen(”学生学籍管理系统__code。
txt”,"wt"))==NULL);//当建立密码文件成功时,进入for循环for(i=0;i〈M;i++) //M为宏定义的可建立的登陆用户个数,可更改{printf("请录入第%d个用户名:",i+1);//创建不同的用户名及密码scanf(”%s",co[i]。
学生成绩管理系统(数据结构C语言版源代码)
![学生成绩管理系统(数据结构C语言版源代码)](https://img.taocdn.com/s3/m/ebbeb91333d4b14e852468f2.png)
学生成绩管理系统(数据结构C语言版源代码)-标准化文件发布号:(9556-EUATWK-MWUB-WUNN-INNUL-DDQTY-KII#include<stdio.h>#include<string.h>#include<stdlib.h>struct students{char Num[10]; /*字符型学生学号*/char Name[20]; /*字符型学生姓名*/char Sex[3]; /*字符型学生性别*/double English; /*双精度实型英语成绩*/double Java; /*双精度实型Java成绩*/double Sjjg; /*双精度实数据结构*/double Szdl; /*双精度实型数字电路*/double Jsj; /*计算机组成原理*/struct students *next; /*用与构建连表指向下一结点*/};FILE *fp; /*定义全局变量fp*/void Revisemenu();/*修改菜单*/void Sortmenu();/*排序菜单*/void menu();/*主菜单*/void secret();/*安全验证*/struct students * Input();/*新建学生信息*/void fprint(struct students *head);/*将信息导入文件可追加*/void fprint_(struct students *head);/*将信息导入文件并覆盖*/void Browse(struct students *head);/*浏览全部学生信息*/struct students * create(struct students *head,int *n);/*从tushu_list中读取数据构建链表*/void FindofNum(struct students *head);/*按学号查询学生信息*/void FindofNname(struct students *head);/*按姓名查询学生信息*/void SortEnglish(struct students * head);/*按英语成绩排序*/void SortJava(struct students * head);/*按Java成绩排序*/void SortSjjg(struct students * head);/*按数据结构成绩排序*/void SortSzdl(struct students * head);/*按数字逻辑电路成绩排序*/void SortJsj(struct students * head);/*按计算机组成原理成绩排序*/struct students * Delete(struct students * head,char m[15]);/*按学号删除学生成绩信息*/struct students * Revise();/*修改学生信息(按编号修改)*//*主菜单*/void menu(){printf("\n\n");printf("***************************************************\n");printf(" 学生成绩管理系统 \n");printf("---------------------------------------------------\n");printf(" 1-添加新同学 2-浏览学生信息 \n");printf(" 3-按学号查询 4-按姓名查询 \n");printf(" 5-按成绩排序 6-修改学生信息 \n");printf(" 7-删除学生信息 0-退出系统 \n");printf("---------------------------------------------------\n");printf("___________________________________________________\n");}/*排序菜单*/void Sortmenu(){printf("\n\n");printf("***************************************************\n");printf(" 按成绩排序 \n");printf(" 1-大学英语 2-JAVA编程 \n");printf(" 3-数据结构 4-数字逻辑电路 \n");printf(" 5-计算机组成原理 0-返回上级菜单 \n");printf("***************************************************\n");}/*修改菜单*/void Revisemenu(){printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");printf(" 1--修改学生姓名 2--修改学生学号 \n");printf(" 3--修改学生性别 4--修改英语成绩 \n");printf(" 5--修改JAVA成绩 6--修改数据结构 \n");printf(" 7--修改数字电路 8--修改计算计 \n");printf(" 0--返回上级菜单 \n");printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");}/*安全验证*/void secret(){char a[20];printf("**欢迎来到学生信息管理系统,进入系统前请先进行密码验证---");printf(" ");do{gets(a); /*输入密码*/system("cls"); /*调用库函数清屏*/printf("对不起!您输入的密码有误,请重新输入---");}while(strcmp(a,"0605")!=0); /*单一密码"0605"*/system("cls");}/*新建学生信息*/struct students * Input(){struct students *p1,*p2,*head; /*建立辅助结点及头结点*/char Name;int n=0,x;printf("\n请按对应项输入学生信息以#结束:\n");printf("姓名学号性别英语 Java 数据结构数字电路计算机组成原理\n");p1=(struct students *)malloc(sizeof(struct students));head=p2=p1;do{ /*使用do while语句输入学生信息*/scanf("%s",&p1->Name);if(strcmp(p1->Name,"#")==0)break; /*判断结束符*/elsescanf("%s%s%lf%lf%lf%lf%lf",p1->Num,p1->Sex,&p1->English,&p1->Java,&p1->Sjjg,&p1->Szdl,&p1->Jsj);Name='#';p1=(struct students *)malloc(sizeof(struct students));p2->next=p1;p2=p1;n++;}while(1);p1->next=NULL;printf("学生信息输入结束!\n");getchar();printf("是否保存学生信息(1.是/2.否):");scanf("%d",&x);if(x==1)fprint(head); /*调用函数保存至文件*/elseprintf("\n文件没有被保存!\n");return head; /*返回头指针*/}/*将信息导入文件可追加*/void fprint(struct students *head){struct students *p1;if((fp=fopen("students_list.txt","a"))==NULL){printf("File open error!\n");exit(0);}for(p1=head;p1->next!=NULL;p1=p1->next) /*遍历*/fprintf(fp,"%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n", p1->Name,p1->Num,p1->Sex,p1->English,p1->Java,p1->Sjjg,p1->Szdl,p1->Jsj);/*将学生信息写入文件*/fclose(fp); /*关闭文件*/printf("\n学生信息已成功保存到文件 students_list.txt 中!\n");getchar();}/*将信息导入文件并覆盖*/void fprint_(struct students *head){struct students *p1;if((fp=fopen("students_list.txt","w"))==NULL){printf("File open error!\n");exit(0);}for(p1=head;p1!=NULL;p1=p1->next) /*遍历*/fprintf(fp,"%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n", p1->Name,p1->Num,p1->Sex,p1->English,p1->Java,p1->Sjjg,p1->Szdl,p1->Jsj);/*将学生信息写入文件*/fclose(fp); /*关闭文件*/;getchar();}/*浏览全部学生信息*/void Browse(struct students *head){char Num[10]; /*字符型学生学号*/char Name[20]; /*字符型学生姓名*/char Sex[3]; /*字符型学生性别*/double English; /*双精度实型英语成绩*/double Java; /*双精度实型Java成绩*/double Sjjg; /*双精度实数据结构*/double Szdl; /*双精度实型数字电路*/double Jsj; /*计算机组成原理*/if((fp=fopen("students_list.txt","a+"))==NULL){printf("File open error!\n");exit(0);}printf("-------------------------------------------------------------\n");printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");while(!feof(fp))/*读取并输出*/{fscanf(fp,"%s%s%s%lf%lf%lf%lf%lf",Name,Num,Sex,&English,&Java,&Sjjg,&Sz dl,&Jsj);printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",Name,Num,Sex,English,Java,Sjjg,Szdl,Jsj);};if(fclose(fp)){printf("Can not close the file!\n");exit(0);}}/*从tushu_list中读取数据构建链表*/struct students * create(struct students * head,int *n){FILE *fp;struct students*p,*p1,*p2;if((fp=fopen("students_list.txt","a+"))==NULL){printf("File open error!\n");exit(0);}while(!feof(fp)){(*n)++;p=(struct students *)malloc(sizeof(struct students));fscanf(fp,"%s%s%s%lf%lf%lf%lf%lf",p->Name,p->Num,p->Sex,&p->English,&p->Java,&p->Sjjg,&p->Szdl,&p->Jsj);if(head==NULL){head=p;p1=p;}else{p1->next=p;p2=p1;p1=p;}}p2->next=NULL;free(p);(*n)--;fclose(fp);return head;}/*按姓名查询学生信息*/void FindofName(struct students *head){int i=0,n=0;char b[20];struct students *p;head=create(head,&n);p=head;printf("\n请输入要查询的学生姓名:");scanf("%s",b);while(p!=NULL){if(strcmp(p->Name,b)==0){printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);i++;}p=p->next;}if(i==0)printf("\n对不起!没有找到名为“%s”的学生信息!\n",b);}/*按学号查询学生信息*/void FindofNum(struct students *head){int i=0,n;char b[20];struct students *p;head=create(head,&n);p=head;printf("\n请输入要查询的学生学号:");scanf("%s",b);while(p!=NULL){if(strcmp(p->Num,b)==0){printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);i++;}p=p->next;}if(i==0)printf("\n对不起!没有找到学号为“%s”学生信息!\n",b);}/*按英语成绩排序*/void SortEnglish(struct students * head){struct students *p,*tail; /*定义中间变量*/int n;double English;p=(struct students *)malloc(sizeof(struct students));head=create(head,&n);printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");while(head->next!=NULL) /*利用选择法排序*/{tail=NULL;p=head;English=p->English; /*将链表中第一个成绩赋给English*/while(p!=NULL){if((p->English)>English)/*比较*/English=p->English;tail=p;p=p->next;}tail=NULL;p=head;while(p->next!=NULL){if(p->English==English){printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);if(p==head)head=head->next;elsetail->next=p->next;}tail=p;p=p->next;}if(p->English==English){ /*分数相同时无需比较*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);tail->next=NULL;}}p=head; /*将链表赋给结构体指针*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);/*浏览排序后的信息*/printf("按英语成绩排序后输出如上(注:此过程不保存至文件):\n");return;}/*按JAVA成绩排序*/void SortJava(struct students * head){struct students *p,*tail; /*定义中间变量*/int n;double Java;p=(struct students *)malloc(sizeof(struct students));head=create(head,&n);printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");while(head->next!=NULL) /*利用选择法排序*/{tail=NULL;p=head;Java=p->Java; /*将链表中第一个成绩赋给Java*/while(p!=NULL){if((p->Java)>Java)/*比较*/Java=p->Java;tail=p;p=p->next;}tail=NULL;p=head;while(p->next!=NULL){if(p->Java==Java){printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);if(p==head)head=head->next;elsetail->next=p->next;}tail=p;p=p->next;}if(p->Java==Java){ /*成绩相同时无需比较*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);tail->next=NULL;}}p=head; /*将链表赋给结构体指针*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);/*浏览排序后的信息*/printf("按Java成绩排序后输出如上(注:此过程不保存至文件):\n");return;}/*按数据结构排序*/void SortSjjg(struct students * head){struct students *p,*tail; /*定义中间变量*/int n;double Sjjg;p=(struct students *)malloc(sizeof(struct students));head=create(head,&n);printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");while(head->next!=NULL) /*利用选择法排序*/{tail=NULL;p=head;Sjjg=p->Sjjg; /*将链表中第一个成绩赋给Sjjg*/while(p!=NULL){if((p->Sjjg)>Sjjg)/*比较*/Sjjg=p->Sjjg;tail=p;p=p->next;}tail=NULL;p=head;while(p->next!=NULL){if(p->Sjjg==Sjjg){printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);if(p==head)head=head->next;elsetail->next=p->next;}tail=p;p=p->next;}if(p->Sjjg==Sjjg){ /*成绩相同时无需比较*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);tail->next=NULL;}}p=head; /*将链表赋给结构体指针*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);/*浏览排序后的信息*/printf("按数据结构成绩排序后输出如上(注:此过程不保存至文件):\n");return;}/*按数字电路排序*/void SortSzdl(struct students * head){struct students *p,*tail; /*定义中间变量*/int n;double Szdl;p=(struct students *)malloc(sizeof(struct students));head=create(head,&n);printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");while(head->next!=NULL) /*利用选择法排序*/{tail=NULL;p=head;Szdl=p->Szdl; /*将链表中第一个成绩赋给Szdl*/while(p!=NULL){if((p->Szdl)>Szdl)/*比较*/Szdl=p->Szdl;tail=p;p=p->next;}tail=NULL;p=head;while(p->next!=NULL){if(p->Szdl==Szdl){printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);if(p==head)head=head->next;elsetail->next=p->next;}tail=p;p=p->next;}if(p->Szdl==Szdl){ /*成绩相同时无需比较*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);tail->next=NULL;}}p=head; /*将链表赋给结构体指针*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);/*浏览排序后的信息*/printf("按数字电路成绩排序后输出如上(注:此过程不保存至文件):\n");return;}/*按计算机组成原理排序*/void SortJsj(struct students * head){struct students *p,*tail; /*定义中间变量*/int n;double Jsj;p=(struct students *)malloc(sizeof(struct students));head=create(head,&n);printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");while(head->next!=NULL) /*利用选择法排序*/{tail=NULL;p=head;Jsj=p->Jsj; /*将链表中第一个成绩赋给Jsj*/while(p!=NULL){if((p->Jsj)>Jsj)/*比较*/Jsj=p->Jsj;tail=p;p=p->next;}tail=NULL;p=head;while(p->next!=NULL){if(p->Jsj==Jsj){printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);if(p==head)head=head->next;elsetail->next=p->next;}tail=p;p=p->next;}if(p->Jsj==Jsj){ /*成绩相同时无需比较*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);tail->next=NULL;}}p=head; /*将链表赋给结构体指针*/printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);/*浏览排序后的信息*/printf("按计算机组成原理成绩排序后输出如上(注:此过程不保存至文件):\n");return;}/*按学号删除学生成绩信息*/struct students * Delete(struct students * head,char m[15]){struct students *ptr1,*ptr2;int n;printf("\n所有学生信息如下:\n");Browse(head);printf("\n请输入想要删除的学生学号:");scanf("%s",m);head=create(head,&n);if(head==NULL){printf("无学生信息!\n");return head;}if((strcmp(head->Num,m)==0)&&head!=NULL){ptr2=head;head=head->next;free(ptr2);}if(strcmp(head->Num,m)!=0){ptr1=head;ptr2=head->next;while(ptr2!=NULL){if(strcmp(ptr2->Num,m)==0){ptr1->next=ptr2->next;free(ptr2);}elseptr1=ptr2;ptr2=ptr1->next;}}fprint_(head);printf("\n学号为' %s '学生信息已被删除,并保存至文件!\n",m);return head;}/*修改学生信息(按编号修改)*/struct students * Revise(){int n=0,t;char num[10];char Num[10]; /*字符型学生学号*/char Name[20]; /*字符型学生姓名*/char Sex[3]; /*字符型学生性别*/double English; /*双精度实型英语成绩*/double Java; /*双精度实型Java成绩*/double Sjjg; /*双精度实数据结构*/double Szdl; /*双精度实型数字电路*/double Jsj; /*计算机组成原理*/struct students *head=NULL;struct students *p;printf("\n所有学生信息如下:\n");Browse(head);head=create(head,&n);printf("\n输入需要修改的学生的学号:");scanf("%s",num);p=head;while(head!=NULL){if(strcmp(p->Num,num)==0){system("cls");Revisemenu();printf("编号为%s的学生信息如下:\n",num);printf("姓名学号性别英语 Java 数据结构数字电路计算机\n");printf("%s\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->Name,p->Num,p->Sex,p->English,p->Java,p->Sjjg,p->Szdl,p->Jsj);while(1){printf("请选择需要修改的信息:");scanf("%d",&t);switch(t){case 1:printf("请输入新姓名:");scanf("%s",Name);strcpy(p->Name,Name);break;case 2:printf("请输入新学号:");scanf("%s",&Num);strcpy(p->Num,Num);break;case 3:printf("请输入新性别:");scanf("%s",Sex);strcpy(p->Sex,Sex);break;case 4:printf("请输入新英语成绩:");scanf("%lf",&English);p->English=English;break;case 5:printf("请输入新Java成绩:");scanf("%lf",&Java);p->Java=Java;break;case 6:printf("请输入新数据结构成绩:");scanf("%lf",&Sjjg);p->Sjjg=Sjjg;break;case 7:printf("请输入新数字电路成绩:");scanf("%lf",&Szdl);p->Szdl=Szdl;break;case 8:printf("请输入新计算机组成原理成绩:");scanf("%lf",&Jsj);p->Jsj=Jsj;break;case 0:system("cls");menu();goto lab;break;default:printf("对不起,输入有误!");break;}}}elsep=p->next;}lab:fprint_(head);printf("修改完成,并储存至文件!\n");return head;}/*主函数*/void main(){int choice,ch;char m[15];struct students *head=NULL;secret();menu();while(1){printf("请输入选项:");scanf("%d",&choice);switch(choice){case 1:Input();break;case 2:system("cls");menu();Browse(head);break;case 3:system("cls");menu();FindofNum(head);break;case 4:system("cls");menu();FindofName(head);break;case 5:system("cls");Sortmenu();do{printf("请输入您的选择:");scanf("%d",&ch);switch(ch){case 1:system("cls");Sortmenu();SortEnglish(head);break;case 2:system("cls");Sortmenu();SortJava(head);break;case 3:system("cls");Sortmenu();SortSjjg(head);break;case 4:system("cls");Sortmenu();SortSzdl(head);break;case 5:system("cls");Sortmenu();SortJsj(head);break;}}while(ch!=0);system("cls");menu();break;case 6:system("cls");menu();Revise();break;case 7:system("cls");menu();head=Delete(head,m);break;case 0:system("cls");printf("\t\t欢迎下次再来!");exit(0);default:printf("对不起,输入有误!");break;}}return ;}。
c课课程设计以及源代码
![c课课程设计以及源代码](https://img.taocdn.com/s3/m/6da64292a0c7aa00b52acfc789eb172dec639967.png)
c 课课程设计以及源代码一、教学目标本课程的教学目标是使学生掌握C语言的基本语法、数据结构和算法,培养学生编程思维和解决问题的能力。
具体目标如下:1.知识目标:(1)理解C语言的基本语法,包括变量、数据类型、运算符、表达式等;(2)掌握函数的定义和调用,了解作用域规则;(3)熟悉数组的声明和使用,理解字符串的基本操作;(4)了解指针的概念和应用,掌握指针与数组、指针与函数的关系;(5)学习结构体和联合体,掌握文件操作的基本方法。
2.技能目标:(1)能够运用C语言编写简单的程序,实现输入输出、数据处理等功能;(2)学会使用调试工具,能够发现和解决程序中的错误;(3)掌握常用的算法,如排序、查找、递归等,并能够灵活运用;(4)具备一定的编程规范和编程习惯,能够阅读和理解他人的代码。
3.情感态度价值观目标:(1)培养学生对计算机科学的兴趣和好奇心,激发学生主动学习的动力;(2)培养学生团队合作的精神,学会与他人交流和分享;(3)培养学生勇于面对困难和挑战,培养解决问题的能力;(4)培养学生具有良好的职业操守,注重诚信和责任心。
二、教学内容根据课程目标,本课程的教学内容主要包括以下几个方面:1.C语言的基本语法:变量、数据类型、运算符、表达式、函数等;2.数据结构:数组、字符串、指针、结构体、联合体等;3.算法:排序、查找、递归等常用算法;4.文件操作:文件的打开、关闭、读写等基本操作;5.编程实践:编写简单的程序,锻炼编程能力和解决问题的能力。
三、教学方法为了达到课程目标,本课程将采用多种教学方法,包括:1.讲授法:通过讲解和演示,使学生掌握C语言的基本语法和数据结构;2.讨论法:学生进行小组讨论,培养学生的团队合作能力和解决问题的能力;3.案例分析法:分析典型的编程案例,使学生了解C语言在实际应用中的重要性;4.实验法:让学生动手编写程序,培养学生的编程能力和实践能力。
四、教学资源为了支持教学内容和教学方法的实施,本课程将准备以下教学资源:1.教材:选用权威、实用的C语言教材,为学生提供系统的学习资料;2.参考书:提供相关的参考书籍,丰富学生的知识体系;3.多媒体资料:制作课件、教学视频等,增强课堂教学的趣味性和生动性;4.实验设备:提供计算机实验室,让学生进行编程实践和实验操作。
用C语言编写的一个学生信息管理系统
![用C语言编写的一个学生信息管理系统](https://img.taocdn.com/s3/m/7faf251533687e21ae45a936.png)
用C语言实现线性表的基本操作,能创建一个基于学生信息管理的链表,至少包含数据输入、数据输出、数据处理等操作。
在主函数里能实现以下功能。
运行后出现一个选择提示。
可选择的功能有1)创建新的学生信息链表2)增加一个新的学生信息3)按学号删除某个学生信息4)按学号查找某个学生信息5)可以按照学生成绩对链表排序6)退出系统#include "stdio.h"#include "stdlib.h"#include "string.h"#include "conio.h"jiemian();struct student{char name[50];char sex[5];int age;char num[50];float score1;float score2;float score3;float sum;float ave;}stu[50],del;void gn1(){int i=0;char num1;for(i=0;i<50;i++){printf("请输入要添加的学生资料:\n");printf("学号:");scanf("%s",stu[i].num);printf("姓名:");scanf("%s",stu[i].name);printf("性别:");scanf("%s",&stu[i].sex);printf("年龄:");scanf("%d",&stu[i].age);printf("请输入学生的三门成绩:\n");printf("语文:");scanf("%f",&stu[i].score1);printf("数学:");scanf("%f",&stu[i].score2);printf("英语:");scanf("%f",&stu[i].score3);printf("是否继续添加:y/n\n");scanf("%c",&num1);scanf("%c",&num1);if(num1=='N' || num1=='n'){system("cls");jiemian();}}}void gn2(){int i;char num[50];printf("请输入要查找的学生学号:\n");scanf("%s",num);for(i=0;i<50;i++)if(strcmp(stu[i].num,num)==0){stu[i].sum=stu[i].score1+stu[i].score2+stu[i].score3;stu[i].ave=stu[i].sum/3;printf("%s\t%s\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f:\n",stu[i].num,stu[i].name,stu[i].sex,stu[i] .age,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].sum,stu[i].ave);break;}if(i==50)printf("查找不到!请重新输入!\n");getch();system("cls");jiemian();}void gn3(){char num1,i=0;printf("请输入要修改的学生学号:\n");scanf("%s",stu[i].num);printf("%s\t%s\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f:\n",stu[i].num,stu[i].name,stu[i].sex,stu[i] .age,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].sum,stu[i].ave);printf("姓名:");scanf("%s",stu[i].name);printf("性别:");scanf("%s",stu[i].sex);printf("年龄:");scanf("%d",&stu[i].age);printf("请输入学生的三门成绩:\n");printf("语文:");scanf("%f",&stu[i].score1);printf("数学:");scanf("%f",&stu[i].score2);printf("英语:");scanf("%f",&stu[i].score3);printf("是否继续修改:y/n?\n");scanf("%c",&num1);scanf("%c",&num1);if(num1=='N' || num1=='n')system("cls");jiemian();}void gn4(){int i;char num[50];printf("请输入要删除的学生学号:\n");scanf("%s",num);for(i=0;i<50;i++)if(strcmp(num,stu[i].num)==0){printf("%s\t%s\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f:\n",stu[i].num,stu[i].name,stu[i].sex,stu[i] .age,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].sum,stu[i].ave);stu[i]=del;printf("信息已删除,按任意键返回..\n");break;}if(i==50)printf("您输入的信息不存在!\n");getch();system("cls");jiemian();}void gn5(){int i=0;stu[i].sum=stu[i].score1+stu[i].score2+stu[i].score3;stu[i].ave=stu[i].sum/3;printf("学号\t姓名\t性别\t年龄\t语文\t数学\t英语\t总成绩\t 平均成绩\n"); for(i=0;i<50;i++){if(stu[i].age==0)break;printf("%s\t%s\t%s\t%d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f:\n",stu[i].num,stu[i].name,stu[i].sex,stu[i] .age,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].sum,stu[i].ave);}printf("按任意键返回...");getch();system("cls");jiemian();}void gn6(){FILE *fp;int i;char [50];printf("\n");printf("\n");printf("请输入要保存的文件名:");scanf("%s",);if((fp=fopen(,"wb"))==NULL)printf("文件名为空,不能保存!\n");for(i=0;i<50;i++){if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)printf("文件保存失败!\n");}fclose(fp);printf("文件已保存!\n");printf("按任意键返回...\n");getch();system("cls");jiemian();}void gn7(){FILE *fp;int i=0; //打开文件流char [50];printf("请输入文件名:");scanf("%s",); //输入要载入的文件名if((fp=fopen(,"rb"))==0) //如果当前目录下不存在相对应的文件,输出文件不存在,退出系统。
学生管理系统源代码
![学生管理系统源代码](https://img.taocdn.com/s3/m/5dd29978492fb4daa58da0116c175f0e7cd119b2.png)
#include<iostream>#include<stdlib.h>#include<string.h>#include<malloc.h>#define INIT_SIZE 10#define INCRE_SIZE 10#define SUBJECT_NUM 3#define LEN 3void show_Start();void show_Table();void addRecord();void Info_delete();void deleteRecord();void delete_Num(int);void delete_Name(char tarName[]);void Info_modify();void modifyRecord();void modify_Num(int);void modify_Name(char[]);void Info_query();void queryRecord();void query_Num(int);void query_Name(char[]);void display();void quit();void menu_CMD();char *subject[SUBJECT_NUM] =struct STUDENT{int num;char name[20];char sex;float score[SUBJECT_NUM];};//struct STUDENT stu[LEN + 1];//STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);int static stuNum = 0;//STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);;int main(){//record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);//STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);/*record[1].num = 1001;strcpy(record[1].name,"Jason");record[1].sex = 'M';record[1].score[0] = 85.0;record[1].score[1] = 90.0;record[1].score[2] = 95.0;record[2].num = 1002;strcpy(record[2].name,"Jerry");record[2].sex = 'M';record[2].score[0] = 85.0;record[2].score[1] = 90.0;record[2].score[2] = 95.0;record[3].num = 1003;strcpy(record[3].name,"Jessie");record[3].sex = 'F';record[3].score[0] = 85.0;record[3].score[1] = 90.0;record[3].score[2] = 95.0;*//*Info_modify();int key;cout<cin>>key;if(key == 1){int targetNum;coutcin>>targetNum;modify_Num(targetNum);cout<<endl;display();}if(key == 2){char targetName[20];cout<cin>>targetName;modify_Name(targetName);cout<<endl;display();}if(key == 3){exit(0);}*/show_Start();menu_CMD();return 0;}void show_Start(){//cout<<endl;cout<<" **************************************** "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" Made by Jason "<<endl; cout<<" **************************************** "<<endl;}//.void show_Table(){cout<<" <<"\t"<<" "<<"\t"<<"cout<<"\t"<<subject[0]<<"\t"<<subject[1]<<"\t"<<subject[2];cout<<endl;}void menu_CMD(){int key;while(1){cout<<"1. <<endl; cout<<"2. <<endl; cout<<"3. <<endl; cout<<"4. <<endl; cout<<"5. <<endl; cout<<"6. <<endl; cout<<"cin>>key;while(1){if((key < 1)||(key > 6)){int key;cout<< "<<endl; cout<< (1 - 5) : "; cin>>key;}else{break;}}switch(key){case 1:addRecord();break;case 2:deleteRecord();break;case 3:modifyRecord();break;case 4:queryRecord();break;case 5:display();break;case 6:quit();break;}}}/////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////void addRecord(){if(stuNum == 0){cout<< <<endl;stuNum++;}else{cout<<" <<endl;stuNum++;}//if(stuNum > INIT_SIZE){cout<< "<<endl;record = (STUDENT*)realloc(record,(INIT_SIZE + INCRE_SIZE)*sizeof(STUDENT));cout<<" !"<<endl;}cout<<" <<endl;cout<<" (Y/N) : ";char choi;cin>>choi;if((choi == 'Y')||(choi == 'y')){cout<<" : ";cin>>record[stuNum].num;cout<<" : ";cin>>record[stuNum].name;cout<<"(M , F) : ";cin>>record[stuNum].sex;int i;for(i = 0;i < SUBJECT_NUM;i++){cout<<" "<<subject[i]<< : ";cin>>record[stuNum].score[i];}}if((choi == 'N')||(choi == 'n')){cout<<" <<endl;cout<<endl;}cout<< <<stuNum<<" !"<<endl; cout<<endl;}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// \//deleteRecordvoid Info_delete(){cout<<" : "<<endl;cout<<"1. "<<endl;cout<<"2. <<endl;cout<<"3. "<<endl; }//void deleteRecord(){int key;cout<<endl;Info_delete();cout<<" : "; cin>>key;if(key == 1){int targetNum;cout<<" : ";cin>>targetNum;//delete_Num(targetNum);cout<<endl;}if(key == 2){char targetName[20];cout<<" : "; cin>>targetName;delete_Name(targetName); cout<<endl;}if(key == 3){while(1){menu_CMD();}}}//void delete_Num(int tarNum){int i;for(i = 1;i <= stuNum;i++){if(record[i].num == tarNum){////1.//2.if(i = stuNum){cout<<" : "<<endl;show_Table();cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"<<record[i].score[0]<<record[i].score[1]<<"\t"<<record[i].score[2];cout<<endl;cout<<endl<<" : "<<endl;show_Table();for(int i = 1;i <= stuNum - 1;i++){cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;for(int j = 0;j < SUBJECT_NUM;j++){cout<<"\t"<<record[i].score[j];}cout<<endl;}stuNum--;cout<<" <<stuNum<<";cout<<endl;*/}//2.if(i != stuNum){cout<<" : "<<endl;show_Table();cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];for(int j = i+1;j <= stuNum;j++){record[j-1] = record[j];}//cout<<endl;cout<<" : "<<endl;show_Table();for(int i = 1;i <= stuNum-1;i++){cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;for(int j = 0;j < SUBJECT_NUM;j++){cout<<"\t"<<record[i].score[j];}cout<<endl;}/*stuNum--;cout<<" "<<stuNum<<"cout<<endl;*/}stuNum--;cout<<" "<<stuNum<<cout<<endl;}}}/*//void delete_Name(char tarName[]){int i;for(i = 1;i <= stuNum;i++){if(strcmp(record[i].name,tarName) == 0){////1.//2.//if(i = stuNum){cout<<" : "<<endl;show_Table();cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"<<record[i].score[0]<<record[i].score[1]<<"\t"<<record[i].score[2];cout<<endl;cout<<endl<<" : "<<endl;show_Table();for(int i = 1;i <= stuNum - 1;i++){cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;for(int j = 0;j < SUBJECT_NUM;j++){cout<<"\t"<<record[i].score[j];}cout<<endl;}}/if(i != stuNum){cout<<" : "<<endl;show_Table();cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];//for(int j = i+1;j <= stuNum;j++){record[j-1] = record[j];}cout<<endl;//cout<<" : "<<endl;show_Table();for(int i = 1;i <= stuNum-1;i++){cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;for(int j = 0;j < SUBJECT_NUM;j++){cout<<"\t"<<record[i].score[j];}cout<<endl;}cout<<endl;void delete_Name(char tarName[]){int i;for(i = 1;i <= stuNum;i++){////1.//2.// if(strcmp(record[i].name,tarName) == 0){if(i == stuNum){cout<<" : "<<endl;show_Table();cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];cout<<endl;cout<<" : "<<endl;show_Table();for(int i = 1;i <= stuNum-1;i++){cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;for(int j = 0;j < SUBJECT_NUM;j++){cout<<"\t"<<record[i].score[j];}cout<<endl;}/*stuNum--;cout<<" "<<stuNum<<" ";cout<<endl;}/if(i != stuNum){cout<<" "<<endl;show_Table();cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t";cout<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];cout<<endl;for(int j = i+1;j <= stuNum;j++){record[j-1] = record[j];}//. cout<<endl;cout<<" : "<<endl;show_Table();for(int i = 1;i <= stuNum-1;i++){cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;for(int j = 0;j < SUBJECT_NUM;j++){cout<<"\t"<<record[i].score[j];}cout<<endl;}/*stuNum--;cout<<" "<<stuNum<<cout<<endl;*/}stuNum--;cout<<" <<stuNum<< ";cout<<endl;}}}/***************************************************************************** ******************************************************************************/void Info_modify(){cout<<"\ : "<<endl;cout<<"1. "<<endl;cout<<"2. "<<endl;cout<<"3. "<<endl;}void modifyRecord(){int key;cout<<endl;Info_modify();cout<<" : ";cin>>key;//if(key == 1){int targetNum;cout<< : ";cin>>targetNum;modify_Num(targetNum);cout<<endl;//display();//if(key == 2){char targetName[20];cout<< : ";cin>>targetName;modify_Name(targetName); cout<<endl;//display();}if(key == 3){while(1){menu_CMD();}}}//void modify_Num(int tarNum) {int i;for(i = 1;i <= stuNum;i++) {if(record[i].num == tarNum) {cout<<endl<<" "<<endl;cout<<" : ";cin>>record[i].num;cout<<" : ";cin>>record[i].name;cout<<";cin>>record[i].sex;cout<<" "<<subject[0]<<" ";cin>>record[i].score[0];cout<<" "<<subject[1]<<" : ";cin>>record[i].score[1];cout<<" "<<subject[2]<< ";cin>>record[i].score[2];}}}void modify_Name(char tarName[]){int i;for(i = 1;i <= stuNum;i++){if(strcmp(record[i].name,tarName) == 0) {cout<<endl<<" : "<<endl;cout<<" : ";cin>>record[i].num;cout<<" : ";cin>>record[i].name;cout<<" : ";cin>>record[i].sex;cout<<" "<<subject[0]<<" : ";cin>>record[i].score[0];cout<<" "<<subject[1]<<" : ";cin>>record[i].score[1];cout<<" "<<subject[2]<<" : ";cin>>record[i].score[2];}}}void Info_query(){cout<<" : "<<endl; cout<<"1. "<<endl; cout<<"2. "<<endl; cout<<"3. "<<endl; }//queryRecordvoid queryRecord(){int key;cout<<endl;Info_query();cout<<" ";cin>>key;if(key == 1){int targetNum;cout<<" : ";cin>>targetNum;query_Num(targetNum);cout<<endl;}if(key == 2){char targetName[20];cout<<" : ";cin>>targetName;query_Name(targetName);cout<<endl;}// .if(key == 3){while(1){menu_CMD();}void query_Num(int tarNum){int i;for(i = 1;i <= stuNum;i++){if(record[i].num == tarNum){// cout<<" : "<<endl;//show_Table();// cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;cout<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[ 2];cout<<endl;}}}//void query_Name(char tarName[]){int i;for(i = 1;i <= stuNum;i++){if(strcmp(record[i].name,tarName) == 0){cout<<" : "<<endl;show_Table();cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;cout<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[ 2];cout<<endl;}}}//void display(){show_Table();int i,j;for(i = 1;i <= stuNum;i++){//cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别";cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;for(j = 0;j < SUBJECT_NUM;j++){cout<<"\t"<<record[i].score[j];}cout<<endl;}cout<<endl;}//void quit(){char choi;cout<<" "<<endl;cout<<" (Y/N) : ";cin>>choi;if((choi == 'Y')||(choi == 'y')){cout<< "<<endl;exit(0);}/ else{cout<<endl; menu_CMD();。
C语言上机实验报告--学生信息管理系统设计__内附源代码
![C语言上机实验报告--学生信息管理系统设计__内附源代码](https://img.taocdn.com/s3/m/5cd698c189eb172dec63b706.png)
C语言上机实验报告------学生信息管理系统设计姓名:学号:班级:指导老师:学院:学校:C语言上机实验报告------学生信息管理系统设计一、实验题目学生信息管理系统设计学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话,E-mail 等。
试设计一学生信息管理系统,使之能提供以下功能:(1)系统以菜单方式工作(2)学生信息录入功能(学生信息用文件保存)---输入(3)学生信息浏览功能---输出(4)查询、排序功能---算法(5)按学号查询(6)按姓名查询(7)学生信息的删除与修改(可选项)二、本课程的地位、作用与目的为综合应用C语言程序设计理论知识、进一步提高学生综合解决问题、协调工作的能力和良好的软件开发习惯,特安排本实验内容。
希望通过该实习能够进一步激发学生的学习热情,培养学生初步编程的能力,为后续的学习和发展奠定基础。
三、分析过程1、能够实现对学生基本信息数据的增加和删除2、实现对录入保存后的学生基本信息进行格式化浏览3、提供学号和姓名两种方式对学生基本信息数据的查询4、能够对随机输入的学生基本信息数据按学号进行排序5、学生信息数据保存在文件中,方便数据的多次使用为了实现以上功能,必须设计的函数如下:录入函数、查询函数(分为姓名查询和学号查询)、删除函数、排序函数和几个菜单绘制函数等四、实验源代码:#include <stdio.h>#include<string.h>#include<conio.h>#include<stdlib.h>#include<time.h>#define num 12//定义学生结构体typedef struct student{int id;char name[num];int age;char sex[4];struct birth{int year;int month;int day;}date;char add[30];int phone;}stu;//功能选择菜单void menu(){printf("\n");printf("\n");printf(" 学生信息管理系统\n");printf("\n");printf("********************************************************************* **\n");printf(" ==============1.学生信息录入 2.学生信息浏览===============\n");printf("\n");printf(" ==============3.学号查询信息 4.姓名查询信息===============\n");printf("\n");printf(" ==============5.按学号排序 6.删除学生信息===============\n");printf("\n");printf(" ============== 0.退出系统===============\n");printf("\n");printf("\n");printf("********************************************************************* *\n");printf("\n");printf(" 按编号选择对应功能\n");printf("\n");printf(" +++++++++++++++++++ XXXXXXX制作+++++++++++++++++++++\n");printf("\n");}//修改菜单void printmenu(){printf("********************************************************* **\n");printf("-------1.完全修改 2.学号修改---------");printf("-------3.姓名修改 4.性别修改---------");printf("-------5.生日修改 6.地址修改---------");printf("-------7.电话修改 0.退出修改---------");printf("********************************************************* **\n");}//取当前时间int nowtime(){struct tm *local;time_t t;t=time(NULL);local=localtime(&t);return local->tm_year+1900;//求出当前时间的年份}//输出文件中学生信息void print(char *file){stu temp;FILE *fp=fopen(file,"r");if(fp==NULL){printf("打开文件%s失败!\n",file);return;}printf("文件%s中学生信息如下:\n",file);printf("%8s%8s%6s%6s%8s%4s%4s%16s%12s\n","学号","姓名","年龄","性别","出生年","月","日","地址","电话");fseek(fp,0,SEEK_SET);//从文件开始为之读取while(fread(&temp,sizeof(stu),1,fp))printf("%8d%8s%6d%6s%8d%4d%4d%16s%12d\n",temp.id,,temp.age,t emp.sex,temp.date.year,temp.date.month,temp.date.day,temp.add,temp.ph one);//格式化输出学生信息fclose(fp);//关闭文件}void luru(char *file){int count,sexnum,i=0,m;stu temp,temp1;FILE *fp=fopen(file,"a+");//追加方式打开文件if(fp==NULL){printf("打开文件%s失败!",file);return;}printf("请确定本次需要录入几名学生信息:");scanf("%d",&count);for (i=0;i<count ;i++ ){printf("录入要写入文件%s的第%d名学生信息\n",file,i+1); Repeat:printf("请输入学号:");m=scanf("%d",&temp.id);if (m==0){printf("输入的数据不是整型数据!\n");fflush(stdin);//清除缓存goto Repeat;}fseek(fp,0,SEEK_SET);//从文件开始位置读取while(fread(&temp1,sizeof(stu),1,fp)){if (temp1.id==temp.id)//判断学号是否已存在{printf("学号已存在!\n");goto Repeat;}//若学号已存在,返回继续读取学号}printf("请输入姓名:");scanf("%s",);printf("请输入性别:0为女生,1为男生:");{scanf("%d",&sexnum);if (sexnum==1) strcpy(temp.sex,"男");else strcpy(temp.sex,"女");}printf("请输入出生年月日:");scanf("%d%d%d",&temp.date.year,&temp.date.month,&temp.date.day);temp.age=nowtime()-temp.date.year;printf("请输入地址:");scanf("%s",&temp.add);printf("请输入联系电话11位:");scanf("%d",&temp.phone);if(!fwrite(&temp,sizeof(stu),1,fp)){printf("向文件%s写入信息失败!\n",file);return;}}printf("向文件%s写入信息成功!\n",file);fclose(fp);}int IsEmpty(FILE *fp){int len;fseek(fp,0,SEEK_END);//指针移动到文件尾len=ftell(fp);//取指针的文职获取长度return(len==0)?1:0;//0代表文件为空}void idsearch(char *file){int findid;stu temp;FILE *fp=fopen(file,"r");if (fp==NULL){printf("文件无法打开!");return;}if(IsEmpty(fp)){printf("文件为空,请先录入信息!");return;}printf("输入要查找学生的学号:");scanf("%d",&findid);fseek(fp,0,SEEK_SET);while(fread(&temp,sizeof(stu),1,fp)){if(temp.id==findid){printf("%8s%8s%6s%6s%8s%4s%4s%16s%11s\n","学号","姓名","年龄","性别","出生年","月","日","地址","电话");printf("%8d%8s%6d%6s%8d%4d%4d%16s%11d\n",temp.id,,temp.a ge,temp.sex,temp.date.year,temp.date.month,temp.date.day,temp.add,tem p.phone);//格式化输出学生信息return;}}printf("没有找到学号为%d的学生的信息!",findid);return;fclose(fp);}void namesearch(char *file){char name[num];stu temp;FILE *fp=fopen(file,"r");if (fp==NULL){printf("文件无法打开!");return;}if(IsEmpty(fp)){printf("文件为空,请先输入学生信息!");return;}printf("输入要查找的学生的姓名:");scanf("%s",name);fseek(fp,0,SEEK_SET);while(fread(&temp,sizeof(stu),1,fp)){if (!strcmp(,name)){printf("下面是姓名为%s的学生的信息:\n",name);printf("%8s%8s%6s%6s%8s%4s%4s%16s%11s\n","学号","姓名","年龄","性别","出生年","月","日","地址","电话");printf("%8d%8s%6d%6s%8d%4d%4d%16s%11d\n",temp.id,,temp.a ge,temp.sex,temp.date.year,temp.date.month,temp.date.day,temp.add,tem p.phone);//格式化输出学生信息return;}}printf("没有找到姓名为%s的学生的信息!",name);fclose(fp);}//排序函数void paixu(char *file){int i,j,k,len;stu s[num],temp;FILE *fp=fopen(file,"r");if(fp==NULL){printf("文件无法打开!");return;}if(IsEmpty(fp)){printf("文件为空,请先录入信息!");return;}fseek(fp,0,SEEK_END);//指针移动到文件末尾len=ftell(fp)/sizeof(stu);fseek(fp,0,SEEK_SET);for(i=0;i<len;i++)fread(s+i,sizeof(stu),1,fp);fclose(fp);for(i=0;i<len;i++){k=i;for(j=i+1;j<len;j++){if(s[j].id<s[k].id)k=j;}if(k!=i){temp=s[i];s[i]=s[k];s[k]=temp;}}printf("下面是按学号从小到大顺序排序后的学生的信息:\n");printf("%8s%8s%6s%6s%8s%4s%4s%16s%11s\n","学号","姓名","年龄","性别","出生年","月","日","地址","电话");for(i=0;i<len;i++)printf("%8d%8s%6d%6s%8d%4d%4d%16s%11d\n",s[i].id,s[i].name,s[i].a ge,s[i].sex,s[i].date.year,s[i].date.month,s[i].date.day,s[i].add,s[i ].phone);//格式化输出学生信息remove("学生信息表.txt");//删除以前存放数据的文件fp=fopen(file,"w");for(i=0;i<len;i++)fwrite(s+i,sizeof(stu),1,fp);fclose(fp);}//删除函数void shanchu(char *file){int i=0,len,del;stu s[num];FILE *fp=fopen(file,"r");if(fp==NULL){printf("文件无法打开!");return;}if(IsEmpty(fp)){printf("文件为空,请先录入学生信息!");return;}printf("输入需要删除的学生的学号:");scanf("%d",&del);fseek(fp,0,SEEK_SET);while(fread(s+i,sizeof(stu),1,fp)){if(s[i].id==del){printf("下面是按学号为%d的学生的信息:\n",del);printf("%8s%8s%6s%6s%8s%4s%4s%16s%11s\n","学号","姓名","年龄","性别","出生年","月","日","地址","电话");printf("%8d%8s%6d%6s%8d%4d%4d%16s%11d\n",s[i].id,s[i].name,s[i].a ge,s[i].sex,s[i].date.year,s[i].date.month,s[i].date.day,s[i].add,s[i ].phone);//格式化输出学生信息i=i-1;}i++;}fclose(fp);len=i;fp=fopen(file,"w");fseek(fp,0,SEEK_SET);for(i=0;i<len;i++) //删除后重写文件fwrite(s+i,sizeof(stu),1,fp);fclose(fp);}void main(){int key;char file[]={"学生信息表.txt"};do{menu();printf("选择对应功能操作:");scanf("%d",&key);switch(key){case 1:luru(file);break;case 2:print(file);break;case 3:idsearch(file);break;case 4:namesearch(file);break;case 5:paixu(file);break;case 6:shanchu(file);break;case 0:exit(0);default:printf("选择错误,请重新选择!");}printf("\n");printf("按任意键返回上级菜单!");getch();fflush(stdin);system("cls");}while (key!=0);}五.实验过程及结果:1.程序主菜单运行界面2.学生信息录入运行界面3.学生信息浏览运行界面4.学生学号查询运行界面5.学生姓名查询运行界面6.按学号排序运行界面第一次出现乱码,改正后运行如第二张图片所示7.删除学生信息运行界面六、感想在本次实验的过程中,出现了各种各样的问题。
学生成绩管理系统c语言代码(供参考)
![学生成绩管理系统c语言代码(供参考)](https://img.taocdn.com/s3/m/ce53703766ec102de2bd960590c69ec3d5bbdb40.png)
C程序学生管理系统以下是用c语言编写的学生成绩管理系统的简单代码,可以用vc运行(供参考)#include"stdio.h”#include”stdlib.h”#include”string.h”typedef struct student//定义学生{char name[10];int number;char sex[2];int math;int eglish;int clanguge;int average;}student;typedef struct unit//定义接点{student date;struct unit *next;}unit;unit* build()//建立链表并返回指针{unit *p;if((p=(unit*)malloc(sizeof(unit)))==NULL){ printf(”=〉初始化失败!”);return 0;}else{p->next=NULL;p-〉date.number=0;//头结点存放学生人数printf(”初始化成功!\n”);return p;}}void add(unit *head)//增加学生{unit *p,*q;int m,n=0;q=head-〉next;p=(unit*)malloc(sizeof(unit));printf(”=>请输入新生姓名!\n”);gets(p—〉);fflush(stdin);printf("=〉请输入学号!\n");while(n==0){scanf("%d”,&m);fflush(stdin);if(q==NULL) n=1;while(q){if(q—〉date。
number==m){printf("=>你输入的学号与已有同学的学号相同,请重新输入!\n”);q=head-〉next;break;}else{q=q->next;if(q==NULL) n=1;}}}p—〉date。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//===================================================================== ============================================//student.h 定义了抽象类Person,派生了student(及为信息类)、定义了节点类Node、定义了链表类List//===================================================================== ============================================#ifndef STUDATA_H#define STUDATA_H#include <fstream.h>//================================================================int GetID();class List;//-------------------------------------class Person{ //抽象类protected:int ID; //学号char Name[15]; //姓名public:virtual bool operator<(Person&)=0; //<运算符重载virtual bool operator>=(Person&)=0; //>=运算符重载};//---------------------------------------------------------------------------------------class Student:public Person{ //学生类int Score[4]; //成绩void SwapData(Student*); //交换数据public:Student(int =0,char* =NULL,int* =NULL); //构造函数bool operator<(Person&); //<运算符重载bool operator>=(Person&); //>=运算符重载friend ofstream&operator<<(ofstream&,Student*); //<<运算符重载输出到文件friend ifstream&operator>>(ifstream&,Student*); //>>运算符重载从文件输入friend ostream_withassign& operator<<(ostream_withassign&,Student*); //<<运算符重载输出到显示器friend istream_withassign& operator>>(istream_withassign&,Student*); //>>运算符重载从键盘输入friend class List;};//---------------------------------------------------------------------------------------------------------------- class Node{ //结点类Student *Stup; //指向学生对象指针Node *Prev,*Next; //指向前后结点指针public:Node(); //构造函数Node(Student*); //构造函数Node(Node&); //拷贝构造函数~Node(); //析构函数friend class List;};//----------------------------------------------------------------------------------------------------------------- class List{Node *Head,*Tail; //链表头尾指针void InitList(); //初始化函数public:List(); //构造函数~List(); //析构函数void ClearList(); //清空链表Node *FindID(int&); //根据学号寻找学生所在结点指针型函数void Insert(Node*); //插入一个学生Node *CreateNode(Student*); //建立一个学生结点指针型函数void Add(); //增加一个学生void Update(); //修改学生成绩void Delete(); //删除一个学生void Query(); //查找一个学生void SortID(); //按学号排序void SortScore(); //按学生总成绩排序void SaveBin(); //以二进制形式保存数据void PrintList(); //显示链表void PrintTitle(); //显示标题void PrintOne(Student*); //显示一个学生数据};#endif//===================================================================== =====//student.cpp的实现//===================================================================== =====#include <iostream.h>#include <iomanip.h>#include <string.h>#include "student.h"//===================================================================== =====Student::Student(int id,char *name,int *score){ //构造函数ID=id;if(name!=NULL)strcpy(Name,name);if(score!=NULL)for(int i=0;i<=3;i++)Score[i]=score[i];}bool Student::operator<(Person& per){Student &stu=(Student&)per;return (Score[3]<stu.Score[3]);}bool Student::operator>=(Person& per){return (!operator<(per));//return (Score[3]>=stu.Score[3])}void Student::SwapData(Student* stup){ //学生数据交换this指针指向调用成员函数的对象Student t=*this;*this=*stup;*stup=t;}ifstream& operator>>(ifstream& in,Student* stup){ //>>运算符重载从文件输入in.read((char*)stup,sizeof(Student)); //从相应的流中提取sizeof(Student)个字节,并把它们放入stup所指的缓冲区中return in;}ofstream& operator<<(ofstream& out,Student* stup){ //<<运算符重载输出至文件out.write((char*)stup,sizeof(Student)); //从stup所指的缓冲区把sizeof(Student)个字节插入到相应的流上return out;}istream_withassign& operator>>(istream_withassign& in,Student *stup){ //>>运算符重载从标准文件输入int i;cout<<"Input Name,Score1-Score3"<<endl;cout<<"Name=";in>>stup->Name;stup->Score[3]=0;for(i=0;i<3;i++){cout<<"Score"<<i<<"=";in>>stup->Score[i];stup->Score[3]+=stup->Score[i];}return in; //输入流对象in返回的到调用处}ostream_withassign& operator<<(ostream_withassign& out,Student *stup){ //<<运算符重载输出至标准文件out<<stup->ID<<setw(8)<<stup->Name<<setw(8)<<stup->Score[0]<<setw(10)<<stup->Score[1]<<setw(10)<<stup->Score[2]<<setw(10)<<stup->Score[3]<<endl;out<<endl;return out; //输处流对象out返回的调用处/*int i;out<<stup->ID<<"\t"<<stup->Name<<"\t" ;for (i=0;i<4;i++){out<<stup->Score[i]<<"\t";}out<<endl;return out; */}//================================================================//node.cpp的实现//================================================================#include<iostream.h>#include"student.h"//---------------------------------------------------------------Node::Node(){Stup=NULL;Prev=Next=NULL;}Node::Node(Student *stup){//默认的构造函数,完成建立一个空节点Stup=stup;Prev=Next=NULL;}Node::Node(Node &node){ //复制构造函数的实现OKStup=node.Stup;Prev=node.Prev;Next=node.Next;}Node::~Node(){ //释放空间delete Stup;}//===================================================================== ============================//list.cpp的实现//===================================================================== ===========================#include <iostream>#include <string>#include "student.h"//===================================================================== ============================List::List(){ //构造函数Head=Tail=new Node(); //建立链表头结点Head->Next=NULL;Head->Prev=NULL;InitList(); //从文件读取数据在下面调用此函数}List::~List(){ //析构函数ClearList(); //在下面调用此函数delete Head; //释放空间}void List::InitList() //从文件读取数据{ifstream inStudent;ofstream outStudent;inStudent.open("gx.dat",ios::binary); //打开学生文件if(!inStudent) //文件不存在,建立该文件{inStudent.close();outStudent.open("gx.dat",ios::binary);outStudent.close(); //关闭文件}else //文件存在,读取学生数据{Student *stup=new Student();Node *nodep;inStudent>>stup;while(!inStudent.eof()){ //未达到文件尾端则执行循环,否则退出循环nodep=CreateNode(stup); //调用GreateNode()函数建立一个学生结点指针型函数Insert(nodep);stup=new Student();inStudent>>stup;}delete stup;}inStudent.close();}void List::Add(){ //增加一个学生Student *stup;Node *nodep;int id=GetID();if((nodep=FindID(id))!=NULL)throw(1); //输入学号相同,抛出异常stup=new Student();stup->ID=id;cin>>stup; //>>运算符重载nodep=CreateNode(stup);Insert(nodep);PrintTitle();PrintOne(stup);}void List::Update(){ //修改学生成绩int id=GetID();Node *nodep;if (FindID(id)!=NULL)nodep=FindID(id);else{cout<<"该学生不存在!";return ;}nodep->Stup->Score[3]=0;for(int i=0;i<3;i++){cout<<"score"<<i<<"=";cin>>nodep->Stup->Score[i];nodep->Stup->Score[3]+=nodep->Stup->Score[i];}PrintTitle();PrintOne(nodep->Stup);}void List::Delete(){ //删除一个学生int id=GetID();Node *nodep;if ((nodep=FindID(id))!=NULL){nodep->Prev->Next=nodep->Next;if(nodep==Tail)Tail=nodep->Prev;elsenodep->Next->Prev=nodep->Prev;delete nodep;}PrintList();}void List::Query(){ //查询学生数据int id=GetID();Node *nodep;if (FindID(id)!=NULL){nodep=FindID(id);PrintTitle();PrintOne(nodep->Stup);}else{cout<<"该学生不存在!";return ;}}void List::ClearList(){ //清空链表Node*nodep;while(Head->Next!=NULL){nodep=Head->Next;Head->Next=Head->Next->Next;delete nodep;}Tail=Head;}Node*List::FindID(int& id){ //查找学号Node *nodep=Head->Next;while(nodep!=NULL&&nodep->Stup->ID!=id)nodep=nodep->Next;return nodep;}void List::Insert(Node *nodep){ //在链表尾插入一个学生*****我有问题*********Tail->Next=nodep;nodep->Prev=Tail;Tail=nodep;}void List::SortID(){ //按学号排序*******我有问题*********Node *nodef,*nodel=Tail;if(Head!=Tail){while(Head->Next!=nodel){nodef=Head->Next;while(nodef!=nodel){if(nodef->Stup->ID>nodef->Next->Stup->ID)nodef->Stup->SwapData(nodef->Next->Stup);nodef=nodef->Next;}nodel=nodel->Prev;}PrintList();}}void List::SortScore(){ //按总成绩排序//学生设计Node*nodef,*nodel=Tail;if(Head!=Tail){while(Head->Next!=nodel){nodef=Head->Next;while(nodef!=nodel){if(nodef->Stup->Score[3]<nodef->Next->Stup->Score[3])nodef->Stup->SwapData(nodef->Next->Stup);nodef=nodef->Next;}nodel=nodel->Prev;}PrintList();}}void List::SaveBin(){ //链表数据保存在二进制文件ofstream outStudent;outStudent.open("gx.dat",ios::binary);Node *nodep=Head->Next;while(nodep!=NULL){outStudent<<nodep->Stup;nodep=nodep->Next;}outStudent.close();}Node*List::CreateNode(Student*stup){ //建立一个学生对象Node *nodep=new Node(stup);return nodep;}void List::PrintList(){ //显示链表中数据Node *nodep=Head->Next ;if(Head!=Tail){//学生设计PrintTitle();while(nodep!=NULL){PrintOne(nodep->Stup);nodep=nodep->Next;}cout<<endl;}elsecout<<"No student"<<endl;}void List::PrintTitle(){cout<<"ID Name Score1 Score2 Score3 Score"<<endl;}void List::PrintOne(Student*stup){cout<<stup; //<<运算符重载}//===================================================================== =============//main.cpp主函数的实现//===================================================================== ============#include <iostream.h>#include "student.h"//===================================================================== =============int EnterChoice(); //输入选项int GetID(); //输入学号enum Choices{ADD=1,UPDATE,DELETE,QUERY,DISPLAY,SORTID,SORTSCORE,END};void main(){List ls;int choice;while((choice=EnterChoice())!=END){switch(choice){case ADD:try{ls.Add();}catch(int){cout<<"Wrong!This ID is equal to other ID"<<endl;}break;case UPDA TE: //修改学生成绩ls.Update();break;case DELETE: //删除一个学生ls.Delete();break;case QUERY: //查询一个学生数据ls.Query();break;case DISPLAY: //显示全部学生数据ls.PrintList();break;case SORTID: //根据学号排序ls.SortID();break;case SORTSCORE: //根据总成绩排序ls.SortScore();default:cerr<<"Incorrect choice\n";}}ls.SaveBin(); //保存学生数据}int EnterChoice(){cout<<"\nEnter your Choice\n"<<"1:Add student 2:Update student\n"<<"3:Delete student 4:Query student\n"<<"5:Display students 6:Sort student by ID\n"<<"7:Sort student by score 8:End\n";int menuChoice;cin>>menuChoice;return menuChoice;}int GetID() //输入学号{int id;do{cout<<"Input student's ID(>0)"<<endl;cin>>id;}while (id<=0);return id;}。