C++学生管理系统课程设计 源代码
学生管理系统c语言源代码

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语言学生管理系统源代码#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语言学籍管理系统(内含源代码)

学籍管理系统一、系统简介设计一个基于结构体数组的学生学籍管理系统,能实现对学生学籍信息进行录入,修改,删除,查询和输出等基本操作二、需求分析学籍管理系统应该实现以下功能: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语言简单版学生管理系统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语言课程设计—学生成绩管理系统

#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语言教务管理系统一、程序结构图二、程序运行截图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,这将是您的登录账号。
学生信息管理系统 系统源代码
系统源代码一、登录界面代码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。
[工学]学生信息管理系统完整源码
学生信息管理系统完整源代码注:本系统采用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语言课程设计报告+学生成绩信息管理系统+源代码
实验报告一、问题陈述及其需求分析(一)问题陈述学生信息管理系统是对学生信息的基本管理,其中包括以下及模块:(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应用软件。
学生成绩管理系统的设计与实现代码
学生成绩管理系统的设计与实现代码本系统有增加学生记录、修改学生记录、删除学生记录、按姓名查询学生记录、按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个步骤删除了李的成绩。
- 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;}。