简单学生管理信息系统源代码

合集下载

学生信息管理系统源代码

学生信息管理系统源代码

#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,st u[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].score 2,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].n um,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 filename[50];printf("\n");printf("\n");printf("请输入要保存的文件名:");scanf("%s",filename);if((fp=fopen(filename,"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 filename[50];printf("请输入文件名:");scanf("%s",filename); //输入要载入的文件名if((fp=fopen(filename,"rb"))==0) //如果当前目录下不存在相对应的文件,输出文件不存在,退出系统。

学生管理系统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);

简易学生管理系统代码

简易学生管理系统代码

简易学生信息管理系统代码分享供有兴趣的未来IT精英参考!因本人知识有限!代码有很多漏洞!望大家去粗取精!#include<stdio.h>#include<string.h>#include<stdlib.h>//账号与密码的初始值const char *zhang0="123";const char *mima0 ="123";int ren = 0,flag = 0, flag0 =0; //全局变量//学生信息结构体struct student{char name[12];char phone[12];int id;int age;int score;}stu[100]={0};//登录int pipei(){int i = 3;char zhang[10]={0};char mima[10] ={0};while(i>0){ system("clear");printf("请输入账号与密码\n");scanf("%s",zhang);scanf("%s",mima);if(strcmp(zhang0,zhang)==0 && strcmp(mima0,mima)==0)return 1;printf("登录失败! 慎重输入\n");printf("还有%d次机会输入!\n",--i);}return 0;}int request(struct student *stup,char *name,char *phone,int id,int age,int score){//遍历结构体确保这里输入的ID号唯一的int i=0;system("clear");for(i=0;i<ren;i++){if(stu[i].id == id){printf("该ID已经存在了,注册失败\n");flag0 = 0;return 0;}}//对结构体地址进行初始化,注册该用户strcpy((stu+i)->name,name);strcpy((stu+i)->phone,phone);(stu+i)->id = id;(stu+i)->age = age;(stu+i)->score =score;//printf("login was successful\n");//注册成功后,人数就要+1ren++;flag0 = 1;return ren; //返回当前的用户数}//找学号int check(int id){int i=0 ;//遍历for(i=0;i<ren;i++){if(stu[i].id == id){flag = 1;return i;}else{flag=0;}}}//注销函数int select(int id){ int i,j;system("clear");for(i=0;i<ren;i++){if(stu[i].id==id){flag = 1;memset(&stu[i],0,sizeof(struct student));for(j=i;j<ren-1;j++){stu[j]=stu[j+1];}ren--;}else{flag = 0;}}if(flag==0){printf("该学号不存在!请重新确认再输入!\n"); }}//修改int change(struct student *stup){char newname[12];char newphone[12];int newid;int newage;int newscore;int n=0,i=0;system("clear");if(flag){printf("修改学生的信息为:\n");printf("姓名:%s\n 电话:%s\n 学号:%d\n年龄:%d\n 成绩:%d\n",stup->name,stup->phone,stup->id,stup->age,stup->score);printf("修改项目: 1.姓名\t 2.电话\t 3.学号\t 4.年龄\t 5.成绩\n ");scanf("%d",&n);switch(n){case 1:{printf("请输入新名字:\n");scanf("%s",newname);strcpy(stup->name,newname);}break;case 2:{printf("请输入新电话:\n");scanf("%s",newphone);strcpy(stup->phone,newphone);}break;case 3:{printf("请输入新学号:\n");scanf("%d",&newid);for(i=0;i<ren;i++){if(stu[i].id == newid){printf("该ID已经存在了,修改失败\n");flag = 0;return 0;}elseflag = 1;}if(flag)stup->id=newid;}break;case 4:{printf("请输入新年龄:\n");scanf("%d",&newage);stup->age=newage;}break;case 5:{printf("请输入新成绩:\n");scanf("%d",&newscore);stup->score=newscore;}break;default :{printf("没有此操作!请认真选择!\n");}}}else{printf("该学号不存在!请重新确认再输入!\n");return 0;flag =0;}}//查询int show(struct student *stup){system("clear");if(flag){printf("该学生的信息为:\n");printf("姓名:%s\n 电话:%s\n 学号:%d\n年龄:%d\n 成绩:%d\n",stup->name,stup->phone,stup->id,stup->age,stup->score);}else{printf("该学号不存在!请重新确认再输入!\n");return 0;}}int maindows(){ int n = 0,i=0,j=0;char name[12];char phone[12];int id;int age;int score;system("clear");printf("****************\n");printf("请选择用户功能1.注册 2.注销 3.修改 4. 查询 5.整体信息\n ");scanf("%d",&n);switch(n){case 1:{while(1){struct student stu1;system("clear");printf("请继续注册!\n");printf("请输入名字\n");scanf("%s",name);printf("请输入电话\n");scanf("%s",phone);printf("请输入学号\n");scanf("%d",&id);printf("请输入年龄\n");scanf("%d",&age);printf("请输入成绩\n");scanf("%d",&score);request(&stu1,name,phone,id,age,score);if(flag0){printf("注册成功!\n");printf("姓名:%s\n 电话:%s\n 学号:%d\n年龄:%d\n 成绩:%d\n",stu[i].name,stu[i].phone,stu[i].id,stu[i].age,stu[i].score);flag0 = 0;}printf("当前的有效用户%d\n",ren);printf("非零继续注册,零则退出注册!\n");scanf("%d",&i);system("clear");if(i==0)return maindows();}}case 2 :{while(1){ system("clear");printf("请输入注销学生学号:\n");scanf("%d",&id);select(id);printf("当前的有效用户%d\n",ren);printf("非零继续注销,零则退出注销!\n");scanf("%d",&i);if(i==0)return maindows();}}case 3:{system("clear");printf("请输入修改学生学号:\n");scanf("%d",&id);while(1){change(&stu[check(id)]);if(flag){printf("修改后学生的信息为:\n");printf("姓名:%s\n 电话:%s\n 学号:%d\n年龄:%d\n 成绩:%d\n",stu[i].name,stu[i].phone,stu[i].id,stu[i].age,stu[i].score);}printf("非零继续修改,零则退出修改!\n");scanf("%d",&i);if(i==0)return maindows();}}case 4:{while(1){system("clear");printf("请输入查询学生学号:\n");scanf("%d",&id);show(&stu[check(id)]);printf("非零继续查询,零则退出查询!\n");scanf("%d",&i);if(i==0)return maindows();}}case 5:{system("clear");for(i=0;i<ren;i++){printf("第%d位学生信息为:",i+1);printf("姓名:%s\t 电话:%s\t 学号:%d\t年龄:%d\t 成绩:%d\n",stu[i].name,stu[i].phone,stu[i].id,stu[i].age,stu[i].score);}return maindows();}break;}}int main(){if(pipei()){printf("登陆成功!\n");printf("******欢迎进入学生信息管理系统******\n");maindows();}elsereturn 0;}。

c语言学生管理系统源代码

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);。

学生信息管理系统完整源代码+mysql文件

学生信息管理系统完整源代码+mysql文件

数据库所用的数据自己导入MYSQL5.5,Navicat8就可以用了。

下面是具体的数据资料/*MySQL Data TransferSource Host: localhostSource Database: simsTarget Host: localhostTarget Database: simsDate: 2013-6-25 9:24:26*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for manager-- ----------------------------DROP TABLE IF EXISTS `manager`;CREATE TABLE `manager` (`id` varchar(10) NOT NULL,`name` varchar(30) NOT NULL,`Mima` varchar(20) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Table structure for studentinfo-- ----------------------------DROP TABLE IF EXISTS `studentinfo`;CREATE TABLE `studentinfo` (`Sname` varchar(30) NOT NULL,`Ssex` varchar(10) NOTNULL,`Snumber` varchar(10) NOT NULL,`Sprofession` varchar(30) NOT NULL,`Sclass`varchar(20) NOT NULL,`Sdate` varchar(30) character set utf8 collate utf8_unicode_ciNOT NULL,PRIMARY KEY (`Snumber`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='InnoDBfree: 4096 kB';-- ------------------------------ Table structure for userinfo-- ----------------------------DROP TABLE IF EXISTS `userinfo`;CREATE TABLE `userinfo` (`id` varchar(10) NOT NULL,`name` varchar(30) NOT NULL,`Mima` varchar(20) character set utf8 collate utf8_unicode_ci NOT NULL, PRIMARY KEY(`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;-- ------------------------------ Records-- ----------------------------INSERT INTO `manager` VALUES ('1', '1', '2');INSERT INTO `manager` VALUES ('2', '恩恩', '123456');INSERT INTO `manager` VALUES ('3', '大大', '123456');INSERT INTO `manager` VALUES ('4', '啊啊', '123456');INSERT INTO `manager` VALUES ('5', '5', '5');INSERT INTO `manager` VALUES ('6', '孙霞', '123456');INSERT INTO `studentinfo` V ALUES ('张三', '男', '2010303755', '数学', '2', '2010-02- 12');INSERT INTO `studentinfo` V ALUES ('李四', '男', '2010303760', '物理', '1', '1995.9.6'); INSERT INTO `studentinfo` V ALUES ('王二', '女', '2010303761', '应数', '2','1990.9.11');INSERT INTO `studentinfo` V ALUES ('麻子', '女', '2010303762', '信计', '1','1999.9.10');INSERT INTO `userinfo` V ALUES ('1', '1', '1');INSERT INTO `userinfo` V ALUES ('13', '13', '1');INSERT INTO `userinfo` V ALUES ('2', '2', '2');INSERT INTO `userinfo` V ALUES ('3', '3', '3');INSERT INTO `userinfo` V ALUES ('6', '6', '6');INSERT INTO `userinfo` V ALUES ('7', '7', '6');下面是相应的程序:package MS;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Add implements ActionListener {JFrame f1;Container ct;JPanel jp,jp1,jp2,jp3;JButton btn1,btn2;JLabel label;JTextField tf1,tf2,tf3,tf4,tf5,tf6;Add(){f1=new JFrame();ct=f1.getContentPane();//初始化面板jp=new JPanel();jp1=new JPanel(new GridLayout(6,1));jp2=new JPanel(new GridLayout(6,1));jp3=new JPanel();btn1=new JButton("确定");btn2=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>添加学生信息</font>",SwingConstants.CENTER);label.setForeground(Color.gray);tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);tf6.setText("例:2000-02-02");//文本框加入提示语tf6.addFocusListener(new FocusListener(){public void focusGained(FocusEvent e) {tf6.setText("");}public void focusLost(FocusEvent e) {}});jp.add(label);ct.add(jp,"North");jp1.add(new JLabel("姓名",SwingConstants.CENTER));jp2.add(tf1);jp1.add(new JLabel("性别",SwingConstants.CENTER));jp2.add(tf2);jp1.add(new JLabel("学号",SwingConstants.CENTER));jp2.add(tf3);jp1.add(new JLabel("专业",SwingConstants.CENTER));jp2.add(tf4);jp1.add(new JLabel("班级",SwingConstants.CENTER));jp2.add(tf5);jp1.add(new JLabel("入学时间",SwingConstants.CENTER));jp2.add(tf6);jp3.add(btn1);jp3.add(btn2);ct.add(jp1,"West");ct.add(jp2,"East");ct.add(jp3,"South");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f1.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f1.setLocation(xcenter, ycenter);f1.setVisible(true);//f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);}public void insert(){if(tf1.getText().equals("")||tf2.getText().equals("")||tf3.getText().equals("")||tf4.getText().equals("")||tf5.getText().equals("")||tf6.getText().equals("")){JOptionPane.showMessageDialog(f1,"请填写完整信息");return;}try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connectioncon=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String s="insert into studentinfo values('"+tf1.getText()+"','"+tf2.getText()+"','"+tf3.getText()+"','"+tf4.getText()+"','"+tf5.getText()+"','"+tf6.getText()+"');";String query="select * from studentinfo where Snumber='"+tf3.getText().trim()+"'";ResultSet res=st.executeQuery(query);if(res.next()){JOptionPane.showMessageDialog(f1,"学号信息已经存在!");con.close();tf3.setText("");}else if(tf6.getText().length()!=10){JOptionPane.showMessageDialog(f1,"入学时间格式有误!");con.close();tf6.setText("");}int insert=st.executeUpdate(s);if(insert==1){JOptionPane.showMessageDialog(f1,"录入信息成功!");tf1.setText("");tf2.setText("");tf3.setText("");tf4.setText("");tf5.setText("");tf6.setText("");}}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){insert();}else if(cmd.equals("取消")){f1.hide();}}public Container getCt(){return ct;}public void setCt(Container ct){this.ct = ct;}}package MS;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Delete implements ActionListener {JFrame f2;Container ct;JPanel jp1,jp2,jp3,jp4;JLabel label;JTextField text;JTable table;//接收数据库中返回的信息JButton btn1,btn2,btn3;Object columnName[]={"姓名","性别","学号","专业","班级","入学时间"};Object ar[][]=new Object[80][6];Delete(){f2=new JFrame();ct=f2.getContentPane();jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();label=new JLabel();text=new JTextField();btn1=new JButton("查询");btn2=new JButton("删除");btn3=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>请输入要删除的学生姓名:</font>",SwingConstants.CENTER);label.setBackground(Color.blue);table=new JTable(ar,columnName);JScrollPane scroll=new JScrollPane(table);text=new JTextField(20);jp2.add(btn1);jp2.add(btn2);jp2.add(btn3);jp1.add(label);jp1.add(text);ct.add(jp1,"North");jp3.setLayout(new BorderLayout());jp3.add(new JLabel("学生信息如下"));jp3.add(scroll);ct.add(jp2,"South");ct.add(jp3,"Center");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f2.setSize(450, 400);int xcenter=(x-450)/2;int ycenter=(y-400)/2;f2.setLocation(xcenter, ycenter);f2.setVisible(true);//f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);btn3.addActionListener(this);}int i=0;public void show(String s){while(i>=0){ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String sql="select * from studentinfo where Sname='"+s+"'";ResultSet res=st.executeQuery(sql);/*if(!(res.next())){JOptionPane.showMessageDialog(f,"所要查询的信息不存在");} */while(res.next()){String sName=res.getString(1);String sSex=res.getString(2);String sNumber=res.getString(3);String sProfession=res.getString(4);String sClass=res.getString(5);String sDate=res.getString(6);ar[i][0]=sName;ar[i][1]=sSex;ar[i][2]=sNumber;ar[i][3]=sProfession;ar[i][4]=sClass;ar[i][5]=sDate;i++;}f2.repaint();con.close();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}public void delete(int line){try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String name=(String)(ar[line][2]);String sql="delete from studentinfo where Snumber ='"+name+"'";int del=st.executeUpdate(sql);if(del==1){ar[line][0]="";ar[line][1]="";ar[line][2]="";ar[line][3]="";ar[line][4]="";ar[line][5]="";JOptionPane.showMessageDialog(null,"删除成功!","信息", JOptionPane.YES_NO_OPTION);}con.close();f2.repaint();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("查询")){String qu=text.getText().trim();show(qu);}if(cmd.equals("删除")){int de=table.getSelectedRow();if(de==-1){JOptionPane.showMessageDialog(null,"请选定要删除的行","错误信息", JOptionPane.YES_NO_OPTION);}else{delete(de);}}if(cmd.equals("取消")){f2.hide();}}}package MS;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTable;import javax.swing.SwingConstants;public class Liulan implements ActionListener {JFrame f4;Container ct;JPanel jp1,jp2,jp3,jp4;JLabel label;JButton btn1,btn2;JTable table;Object[][] ar=new Object[80][6];Object[] columnName={"姓名","性别","学号","专业","班级","入学时间"};Liulan(){f4=new JFrame();ct=f4.getContentPane();jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jp4=new JPanel();btn1=new JButton("点击浏览");btn2=new JButton(" 取消");label=new JLabel("<html><font color=#00FF22 size='4'>学生信息浏览<font>",SwingConstants.CENTER);label.setBackground(Color.blue);table=new JTable(ar, columnName);JScrollPane scroll=new JScrollPane(table);jp1.add(label);jp2.add(btn1);jp2.add(btn2);jp3.add(scroll);ct.add(jp1,"North");ct.add(jp3,"Center");ct.add(jp2,"South");Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f4.setSize(500,530);int xcen=(x-500)/2;int ycen=(y-530)/2;f4.setLocation(xcen,ycen);f4.setVisible(true);btn1.addActionListener(this);btn2.addActionListener(this);}int i=0;public void select(){while(i>=0){ar[i][0]="";ar[i][1]="";ar[i][2]="";ar[i][3]="";ar[i][4]="";ar[i][5]="";i--;}i=0;try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String s="select * from studentinfo";ResultSet res=st.executeQuery(s);while(res.next()){String sName=res.getString(1);String sSex=res.getString(2);String sNumber=res.getString(3);String sProfession=res.getString(4);String sClass=res.getString(5);String sDate=res.getString(6);ar[i][0]=sName;ar[i][1]=sSex;ar[i][2]=sNumber;ar[i][3]=sProfession;ar[i][4]=sClass;ar[i][5]=sDate;i++;}f4.repaint();con.close();}catch(SQLException e){System.out.println("错误代码:"+e.getErrorCode());System.out.println("错误信息:"+e.getMessage());}}@SuppressWarnings("deprecation")public void actionPerformed(ActionEvent e){// TODO Auto-generated method stubString cmd=e.getActionCommand();if(cmd.equals("点击浏览")){select();}else if(cmd.equals(" 取消")){f4.hide();}}}package MS;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.sql.Connection;import java.sql.DriverManager;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.SwingConstants;@SuppressWarnings("serial")public class Login extends JFrame implements ActionListener {Container cp=null;JFrame f=null;JButton button1,button2,button3;JTextField t1;JPasswordField t2;JLabel jlable1,jlable2;JRadioButton rabtn1,rabtn2;Color c;JPanel jp1,jp2,jp3;String table=null;Login(){f=new JFrame("学生信息管理系统");button1=new JButton("确定");button2=new JButton("取消");button3=new JButton("注册");//button3.setOpaque(false);button3.setBorder(null);button3.setBackground(Color.getColor("#292421"));rabtn1=new JRadioButton("普通用户");rabtn1.setBackground(Color.getColor("#292421"));rabtn2=new JRadioButton("管理员");rabtn2.setBackground(Color.getColor("#292421"));ButtonGroup group=new ButtonGroup();group.add(rabtn1);group.add(rabtn2);cp=f.getContentPane();jlable1=new JLabel("输入用户号");jlable2=new JLabel("输入密码");jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();t1=new JTextField(20);t2=new JPasswordField(20);//jp3.add(group);jp1.add(jlable1);jp1.add(t1);jp1.add(jlable2);jp1.add(t2);jp1.add(rabtn1);jp1.add(rabtn2);jp1.add(button3);JLabel JL=new JLabel("<html><font color=#292421 size='7'><i>欢迎登陆" + "</i></font>",SwingConstants.CENTER);cp.add(JL,"North");jp2.add(button1);jp2.add(button2);cp.add(jp1,"Center");cp.add("South",jp2);cp.setBackground(new Color(127, 255, 212 ));jp2.setBackground(new Color(127, 255, 212 ));jp1.setBackground(new Color(127, 255, 212 ));Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width;int y=screen.height;f.setSize(250,300);int xcenter=(x-300)/2;int ycenter=(y-300)/2;f.setLocation(xcenter,ycenter);/*显示在窗口中央*/f.setVisible(true);//f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//------------------------------------------------------------///*监听事件*/button1.addActionListener(this);button2.addActionListener(this);button3.addActionListener(this);rabtn1.addItemListener(new ItemListener(){public void itemStateChanged(ItemEvent e){JRadioButton jop=(JRadioButton) e.getSource();if (jop.isSelected())table="userinfo";}});rabtn2.addItemListener(new ItemListener(){public void itemStateChanged(ItemEvent e){JRadioButton jop=(JRadioButton) e.getSource();if (jop.isSelected())table="manager";}});f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});}@SuppressWarnings("deprecation")public void confirm(String tableName){try{Class.forName("com.mysql.jdbc.Driver");}catch(ClassNotFoundException e){System.out.print("加载驱动程序失败");}String conURL="jdbc:mysql://localhost:3306/sims";try{Connection con=DriverManager.getConnection(conURL,"root","123456");Statement st=con.createStatement();String id=t1.getText().trim();String Mima=t2.getText().trim();String queryMima="select * from "+tableName+" where id='"+id+"' and mima='"+Mima+"'";ResultSet res=st.executeQuery(queryMima);if(res.next()){if(tableName.equals("manager"))new Mstudent(id);else if(tableName.equals("userinfo"))new Ustudent(id);f.hide();con.close();}else{JOptionPane.showMessageDialog(null,"密码错误请重输!!!","提示!",JOptionPane.YES_NO_OPTION);}t1.setText("");t2.setText("");}catch(SQLException g){System.out.println("错误代码:"+g.getErrorCode());System.out.println("错误内容:"+g.getMessage());}}ItemListener listen=new ItemListener(){public void itemStateChanged(ItemEvent e) {// TODO Auto-generated method stub}};public void actionPerformed(ActionEvent e){String cmd=e.getActionCommand();if(cmd.equals("确定")){if(table==null){JOptionPane.showMessageDialog(f,"请选择用户类型");}confirm(table);}else if(cmd.equals("取消")){f.dispose();}else if(cmd.equals("注册")){new Regist();}}public static void main(String []arg){new Login();}}package MS;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenuBar;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.SwingConstants;import javax.swing.border.TitledBorder;@SuppressWarnings("serial")public class Mstudent extends JFrame implements ActionListener {JButton Query = new JButton("查询信息");JButton add = new JButton("添加信息");JButton delete = new JButton("删除信息");JButton xiugai = new JButton("浏览全部信息");JButton liulan = new JButton("修改密码");JMenuBar mb = new JMenuBar();// 菜单栏JPanel jp = new JPanel();Container cp = getContentPane();String userName;Mstudent(){}Mstudent(String userName){erName = userName;mb.add(Query);mb.add(add);mb.add(delete);mb.add(xiugai);mb.add(liulan);JPanel j=new JPanel();j.add(mb,"Center");cp.add(j, "North");// 设置边框jp.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue, 2), null, TitledBorder.CENTER,TitledBorder.TOP));jp.setLayout(new BorderLayout());JLabel label1 = new JLabel("欢迎使用学生信息管理系统",SwingConstants.CENTER);jp.add(label1);JScrollPane scrollpane = new JScrollPane(jp);cp.add(scrollpane,"Center");setTitle("欢迎登陆" + "--" + "你好:" + userName);Toolkit kit = Toolkit.getDefaultToolkit();Dimension screen = kit.getScreenSize();int x = screen.width; /* 取得显示器窗口的宽度*/int y = screen.height; /* 取得显示器窗口的高度*/setSize(600, 600);int xcenter = (x - 600) / 2;int ycenter = (y - 600) / 2;setLocation(xcenter, ycenter);/* 显示在窗口中央*/setVisible(true);//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 注册临听器Query.addActionListener(this);add.addActionListener(this);delete.addActionListener(this);xiugai.addActionListener(this);liulan.addActionListener(this);}public void actionPerformed(ActionEvent e){String cmd = e.getActionCommand();if (cmd.equals("查询信息")){new QueryWays();}if (cmd.equals("添加信息")){new Add();}if (cmd.equals("删除信息")){new Delete();}if (cmd.equals("浏览全部信息")){new Liulan();}if (cmd.equals("修改密码")){new UpdateCode();}}public static void main(String[] args){new Mstudent("");}}package MS;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingConstants;public class Query implements ActionListener {String sql =null;int a;String info;JFrame f3;// Container cp;JPanel jp1,jp2,jp3,jp4,jp,jpwest;JButton btn1,btn2;//确定,取消JLabel label,label2;//标签,请输入姓名(label)JTextField tf,tf1,tf2,tf3,tf4,tf5,tf6;//文本框Query(int a){this.a=a;f3=new JFrame();Container cp=f3.getContentPane();//初始化面板,按钮,标签,文本框jp=new JPanel();jp1=new JPanel();jp2=new JPanel(new GridLayout(6,1));jp3=new JPanel();jp4=new JPanel(new GridLayout(6,1));jpwest=new JPanel();btn1=new JButton("确定");btn2=new JButton("取消");label=new JLabel("<html><font color=#CC00FF size='4'>请输入姓名:" + "</font>",SwingConstants.CENTER);label2=new JLabel("<html><font color=#CC00FF size='4'>请输入学号:" + "</font>",SwingConstants.CENTER);label.setForeground(Color.gray);tf=new JTextField(20);//------------------------------------------------tf1=new JTextField(20);tf2=new JTextField(20);tf3=new JTextField(20);tf4=new JTextField(20);tf5=new JTextField(20);tf6=new JTextField(20);//布局,添加控件if(a==0){jp.add(label);jp.add(tf);}else if(a==1){jp.add(label2);jp.add(tf);}cp.add(jp,"North");jp4.add(new JLabel("姓名",SwingConstants.CENTER));jp2.add(tf1);jp4.add(new JLabel("性别",SwingConstants.CENTER));jp2.add(tf2);jp4.add(new JLabel("学号",SwingConstants.CENTER));jp2.add(tf3);jp4.add(new JLabel("专业",SwingConstants.CENTER));jp2.add(tf4);jp4.add(new JLabel("班级",SwingConstants.CENTER));jp2.add(tf5);jp4.add(new JLabel("入学时间",SwingConstants.CENTER));jp2.add(tf6);jp3.add(btn1);jp3.add(btn2);cp.add(jp4,"West");cp.add(jp2,"East");cp.add(jp3,"South");cp.add(jp1);Toolkit kit=Toolkit.getDefaultToolkit();Dimension screen=kit.getScreenSize();int x=screen.width; //显示窗口宽度int y=screen.height;//窗口高度f3.setSize(350,330);int xcenter=(x-350)/2;int ycenter=(y-330)/2;f3.setLocation(xcenter,ycenter);f3.setVisible(true);//f3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);btn1.addActionListener(this);btn2.addActionListener(this);/*f3.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});*/。

学生信息管理系统C语言源代码

学生信息管理系统C语言源代码

#include<stdio.h>#include<malloc.h>#include<string.h>#include<stdlib.h>#define len sizeof(struct student)FILE *fp;struct student{long num;char name[15];int age;char sex[3];char chushen[10];char dizhi[20];char phone[11];char email[20];struct student *next;};void menu(){printf("===========学生信息管理系统==========\n\n");printf(" 1、录入学生信息\n");printf(" 2、浏览学生信息\n");printf(" 3、查询学生信息\n");printf(" 4、删除学生信息\n");printf(" 5、插入学生信息\n");printf(" 6、修改学生信息\n");printf(" 7、排序学生信息\n");printf(" 8、退出管理系统\n");printf("=====================================\n");}struct student *creat() //录入学生信息{int n;struct student *head;struct student *p1,*p2;n=0;p1=p2=(struct student *) malloc(len);scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p1->num,&p1->age,p1->name,p1->sex,p1->chushen ,p1->dizhi,p1->phone,p1->email);head=NULL;while(p1->num!=0){n=n+1;if(n==1) head=p1;else p2->next=p1;p2=p1;p1=(struct student *)malloc(len);scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p1->num,&p1->age,p1->name,p1->sex,p1->chu shen,p1->dizhi,p1->phone,p1->email);}p2->next=NULL;return(head);}void insert(struct student *head) //插入学生信息{int search_num;struct student *p,*q,*s;p=head;printf("在哪个学生前插入请输入学号:\n");scanf("%d",&search_num);while((p!=NULL)&&(p->num!=search_num)){q=p;p=p->next;}s=(struct student *)malloc(len);q->next=s;system("cls");printf("请输入学生信息:\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&s->num,&s->age,s->name,s->sex,s->chushen,s->diz hi,s->phone,s->email);s->next=p;}void printList(struct student *head) //浏览全部学生信息{struct student *p;p=head;if(head==NULL)printf("没有学生信息!!\n");else{do{fread(p,len,1,fp);printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->diz hi,p->phone,p->email);p=p->next;}while(p!=NULL);}}void findList_num(struct student *head,long search_num) //按学号查找{struct student *p;p=head;while((p!=NULL)&&(p->num!=search_num))p=p->next;if(p!=NULL)printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->diz hi,p->phone,p->email);elseprintf("没有该学生信息!!\n");}void findList_name(struct student *head,char *search_name) //按姓名查找{struct student *p;int cmp1=0,cmp=0;p=head;while(p!=NULL)if(strcmp(p->name,search_name)!=0){p=p->next;cmp++;}else{printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->dizhi,p->phone,p->email);p=p->next;cmp1=1;}if(cmp!=0&&cmp1==0)printf("没有该学生信息!!\n");}void xiugai(struct student *p1,long xiu_num) //修改学生信息{struct student *p2;p2=p1;while((p2!=NULL)&&(p2->num!=xiu_num))p2=p2->next;if(p2!=NULL){scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p2->num,&p2->age,p2->name,p2->sex,p2->chu shen,p2->dizhi,p2->phone,p2->email);}elseprintf("没有该学生信息!!\n");}struct student *delList(struct student *head,long del_num) // 删除学生信息{struct student *p,*q;p=head;q=head;while(p &&(p->num != del_num)){q=p;p=p->next;}if(p==NULL)printf("无此学号!\n");else{if(p == head){head = p->next;free(p);}else{q->next = p->next;free(p);}}return head;}void paixu(struct student *head) //按学号排序{struct student *p,*f,*t;char ch[100];int i;t=f=p=head;for(p=head;p->next!=NULL;p=p->next){for(t=head,f=t->next;t->next!=NULL;t=t->next,f=f->next){if(t->num>f->num>0){i=t->num;t->num=f->num;f->num=i;i=t->age;t->age=f->age;f->age=i;strcpy(ch,t->name);strcpy(t->name,f->name);strcpy(f->name,ch);strcpy(ch,t->sex);strcpy(t->sex,f->sex);strcpy(f->sex,ch);strcpy(ch,t->chushen);strcpy(t->chushen,f->chushen);strcpy(f->chushen,ch);strcpy(ch,t->dizhi);strcpy(t->dizhi,f->dizhi);strcpy(f->dizhi,ch);strcpy(ch,t->phone);strcpy(t->phone,f->phone);strcpy(f->phone,ch);strcpy(ch,t->email);strcpy(t->email,f->email);strcpy(f->email,ch);}}}// return head;}void save(struct student *head) //保存为磁盘文件{struct student *p;if((fp=fopen("keshe","w"))==NULL){printf("cannot open this file\n");exit(0);}p=head;while(p!=NULL){fprintf(fp,"%d\n",p->num);fprintf(fp,"%d\n",p->age);fprintf(fp,"%s\n",p->name);fprintf(fp,"%s\n",p->sex);fprintf(fp,"%s\n",p->chushen);fprintf(fp,"%s\n",p->dizhi);fprintf(fp,"%s\n",p->phone);fprintf(fp,"%s\n",p->email);p=p->next;}fclose(fp);}struct student *read() //从磁盘读取文件{struct student *head=NULL;struct student *p=NULL;struct student *t=NULL;int a;// fp=fopen("keshe","r");if((fp=fopen("keshe","r"))==NULL){printf("cannot open this file\n");exit(0);}while(1){t=(struct student *)malloc(len);a=fscanf(fp,"%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&t->num,&t->age,t->name,t->sex,t->chush en,t->dizhi,t->phone,t->email);if(a==0||a==-1)return head;t->next=NULL;if(p==NULL){p=t;head=t;}else{p->next=t;p=p->next;p->next=NULL;}}fclose(fp);}void main(){int code=0;struct student *pt = NULL;while(code!=8){menu();printf("请输入上述序号进行操作:\n");scanf("%d",&code);system("cls");switch(code){case 1:{system("cls");printf("每个学生的信息之间用Tab键分隔\n");printf("===========================录入学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=creat();save(pt);system("cls");printf("===========================录入学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("************录入学生信息成功***********!!\n");printf("按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 2:{system("cls");printf("===========================学生信息表================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=read();printList(pt);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 3:{int search=0;system("cls");printf("===========================查询学生信息==============================\n");printf("---------------------------------------------------------------------\n");while(search!=3){printf("1、按学号查询\n2、按姓名查询\n3、退出查询\n");scanf("%d",&search);switch(search){case 1:{long search_num;system("cls");printf("请输入学生学号\n");scanf("%d",&search_num);system("cls");printf("===========================查询结果==================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");findList_num(read(),search_num);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回查询菜单\n");getchar();getchar();system("cls");};break;case 2:{char search_name[15];system("cls");printf("请输入学生姓名\n");scanf("%s",search_name);system("cls");printf("===========================查询结果==================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");findList_name(read(),search_name);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回查询菜单\n");getchar();getchar();system("cls");};}}system("cls");};break;case 4:{long del_num;system("cls");printf("===========================删除学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("请输入要删除学生信息的学号:\n");scanf("%d",&del_num);system("cls");pt=delList(read(),del_num);save(pt);printf("===========================删除结果================================\n");printf("-------------------------------------------------------------------\n");printf("学号为%d的学生信息成功删除\n",del_num);printf("\n按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 5:{system("cls");printf("每个学生的信息之间用Tab键分隔\n");printf("===========================插入学生信息==============================\n");printf("---------------------------------------------------------------------\n");insert(pt);save(pt);system("cls");printf("===========================插入学生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("****插入学生信息成功***!!\n\n");printf("按回车键返回主菜单\n");getchar();getchar();system("cls");}break;case 6:{long search_num;system("cls");printf("请输入要修改的学生学号:\n");scanf("%d",&search_num);system("cls");printf("每个学生的信息之间用Tab键分隔\n");printf("===========================修改学生信息==================================\n");printf("-------------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");findList_num(read(),search_num);printf("\n");printf("请输入修改信息:\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=read();xiugai(pt,search_num);save(pt);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("****修改学生信息成功***!!\n\n");printf("\n按回车键返回查询菜单\n");getchar();getchar();system("cls");};break;case 7:{system("cls");printf(" 按学号从小到大排序\n\n");printf("===========================学生信息表================================\n");printf("---------------------------------------------------------------------\n");printf("学号\t年龄\t姓名\t性别\t出生\t地址\t电话\te-mail\n");pt=read();paixu(pt);printList(pt);save(pt);printf("================================================================ =====\n");printf("---------------------------------------------------------------------\n");printf("\n按回车键返回主菜单\n");getchar();getchar();system("cls");};break;case 8:read();break;}}}。

C语言学生信息管理系统(源代码)

C语言学生信息管理系统(源代码)

#include <stdio.h>#include <string.h>/* 谭法建立单链表和输出单链表*/#include <malloc.h>#include <stdlib.h>typedef struct node{ int num;char name[20];struct node *next;}STD;#define LEN sizeof(STD)int menu_select();void handle_menu1();void game4();void game2();STD *insert(STD *head,STD *stud);STD *insert2(STD *head,STD *stud); void game3();void game5();STD *delete(STD*head,long num);void game1();void game6();STD *search(STD*head,long num);STD *head1,*head2;int n=0;/*追加法建表*/void creat1(void){ STD *p1,*p2;system("CLS");head1=NULL;p1=(STD *)malloc(LEN);p2=p1;printf("建表方法1追加法建表!\n");printf("输入学号姓名,若输入学号为0则退出建表!\n");scanf("%d%s",&p1->num,p1->name);while(p1->num!=0){ n++;if(n==1)head1=p1;elsep2->next=p1;p2=p1;p1=(STD *)malloc(LEN);scanf("%d%s",&p1->num,p1->name);}free(p1); p2->next=NULL;scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");return ;}/* 插入法建表*/void creat2(void){ STD *p1;head2=NULL;system("CLS");p1=(STD *)malloc(LEN);printf("建表方法2插入法建表!\n");printf("输入学号姓名(输入学号以0结束)!\n");scanf("%d%s",&p1->num,p1->name);while(p1->num!=0){ p1->next=head2;head2=p1;p1=(STD *)malloc(LEN);scanf("%d%s",&p1->num,p1->name);}scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");free(p1);return ;}/* 链表输出*/void print(STD *head){ STD *p;p=head;while (p!=NULL){ printf("学号%3d 姓名%s\n",p->num,p->name); p=p->next;} printf("链表为空!\n");scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");}/*-------------------------------------------------*//*--------------表1插入结点函数-------*//*-------------------------------------------------*/void game4(){char ch;STD *stud,*head=head1;system("CLS");printf("\t仅限在表1中插入!\n");printf("\t输入要插入结点的学号和姓名(以空格隔开):");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);if(stud->num<0){ printf("\t输入的学号不能为负数,请重新选择插入!\n");return;}while(stud->num>=0){head1=insert(head,stud);printf("\t继续插入新结点吗?(y/n):");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入新结点学号姓名:(输入n结束插入)");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2插入结点函数-------*//*-------------------------------------------------*/void game2(){char ch;STD *stud,*head=head2;system("CLS");printf("\t仅限在表2中插入!\n");printf("\t输入要插入结点的学号和姓名(以空格隔开):");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);if(stud->num<0){ printf("\t输入的学号不能为负数,请重新选择插入!\n");return;}while(stud->num>=0){head2=insert2(head,stud);printf("\t继续插入新结点吗?(y/n):");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入新结点学号姓名:(输入n结束插入)");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 插入模块*//**************************************/STD *insert(STD *head,STD *stud){STD *p0,*p1,*p2;p1=head;p0=stud;if(head==NULL){head=p0;p0->next=NULL;}else{while((p0->num>p1->num)&&(p1->next!=NULL)){p2=p1; p1=p1->next;}if(p0->num<=p1->num){if(head==p1)head=p0;else p2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}}n=n+1;printf("按回车键继续!\n");getchar();system("CLS");return (head);}/**************************************//* 插入模块2 *//**************************************/STD *insert2(STD *head,STD *stud){STD *p0,*p1,*p2;p1=head;p0=stud;if(head==NULL){head=p0;p0->next=NULL;}else{while((p0->num<p1->num)&&(p1->next!=NULL)){p2=p1; p1=p1->next;}if(p0->num>=p1->num){if(head==p1)head=p0;else p2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}}n=n+1;printf("按回车键继续!\n");getchar();system("CLS");return (head);}/*-------------------------------------------------*//*--------------表1删除学生信息-------*//*-------------------------------------------------*/void game3(){ int num;char ch;STD *head=head1;printf("\t仅限在表1中删除!\n");printf("\t输入要删除的学号:");scanf("%*c");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新选择删除!\n");return;}while(num>=0){head=head1;head1=delete(head,num);printf("\t继续删除吗?(y/n):");scanf("%*c");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要删除的学号:(输入n结束删除!)");scanf("%*c");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2删除学生信息-------*//*-------------------------------------------------*/void game5(){ int num;char ch;STD *head=head2;printf("\t仅限在表2中删除!\n");printf("\t输入要删除的学号:");scanf("%*c");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新选择删除!\n");return;}while(num>=0){head=head2;head2=delete(head,num);printf("\t继续删除吗?(y/n):");scanf("%*c");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要删除的学号:(输入n结束删除!)");scanf("%*c");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 删除模块*//**************************************/STD *delete(STD*head,long num){STD *p1,*p2;if (head==NULL) {printf("\n没有找到该学号!\n");return head;} p1=head;while(num!=p1->num&&p1->next!=NULL){p2=p1;p1=p1->next;}if(num==p1->num){if(p1==head)head=p1->next;else p2->next=p1->next;printf("\n删除:%ld\n",num);n=n-1;}elseprintf("\n 没有发现此项! \n",num);system("CLS");return(head);}/*-------------------------------------------------*//*--------------表1查找学生信息-------*//*-------------------------------------------------*/void game1(){ int num;char ch;STD *head=head1;printf("\t仅限在表1中查找!\n");printf("\t输入要查找的学号:");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新查找!\n");return;}while(num>=0){head=head1;head1=search(head,num);printf("\t继续查找吗?(y/n):");scanf("%d",&num);ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要查找的学号:(输入n结束查找)");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2查找学生信息-------*//*-------------------------------------------------*/void game6(){ int num;char ch;STD *head=head2;printf("\t仅限在表2中查找!\n");printf("\t输入要查找的学号:");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新查找!\n");return;}while(num>=0){head=head2;head2=search(head,num);printf("\t继续查找吗?(y/n):");scanf("%d",&num);ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要查找的学号:(输入n结束查找)");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 查找模块*//**************************************/STD *search(STD*head,long num){STD *p1,*p2;if (head==NULL) {printf("\n没有找到该学号!\n");return head;} p1=head;while(num!=p1->num&&p1->next!=NULL){p2=p1;p1=p1->next;}if(num==p1->num)printf("\n%d %s\n",p1->num,p1->name);elseprintf("\n 没有发现此项! \n",num);return(head);}/* void main(){printf(" *** 运行结果***\n");printf("输入学号姓名(输入学号以0结束)!\n");creat1();print(head1);creat2();print(head2);} *///******************************//* select.cpp:主程序文件*//******************************void main(){handle_menu1();}//*****************************//* 菜单处理函数*//*****************************void handle_menu1(){int h;for(;;){h=menu_select();switch(h){ case 1:/* printf("\t进入追加法建表\n"); */creat1();break; /* 调用功能模块*/case 2:/* printf("\t进入插入法建表\n"); */creat2();break;case 3:/* printf("\t输出追加法链表的结果\n"); */print(head1);break;case 4:/* printf("\t输出插入法链表的结果\n"); */print(head2);break;case 5:/* printf("\t链表1插入\n"); */game4();break;case 6:/* printf("\t链表2插入\n"); */game2();break;case 7:/* printf("\t链表1删除\n"); */game3();break;case 8:/* printf("\t链表2删除\n"); */game5();break;case 9:/* printf("\t链表1查找\n"); */game1();break;case 10:/* printf("\t链表2查找\n"); */game6();break;case 11:printf("\t再见,欢迎再次使用本系统!谢谢!\n");return;}}}//**********************************//* 菜单选择函数: int menu_select()*//**********************************int menu_select(){int cn;for(;;){printf("\ \n");printf("\t1.追加法建表\n");printf("\ \n");printf("\t2.插入法建表\n");printf("\ \n");printf("\t3.输出链表1\n");printf("\ \n");printf("\t4.输出链表2\n");printf("\ \n");printf("\t5.插入链表1 \n");printf("\ \n");printf("\t6.插入链表2 \n");printf("\ \n");printf("\t7.删除链表1 \n");printf("\ \n");printf("\t8.删除链表2 \n");printf("\ \n");printf("\t9.查找链表1 \n");printf("\ \n");printf("\t10.查找链表2 \n");printf("\ \n");printf("\t11.退出系统\n");printf("\ \n");printf("\t请您选择1-11:");scanf("%d",&cn);//gets(s);//cn=atoi(s);if(cn<1||cn>11)printf("\n\t输入错误,重选1-11:");elsebreak;}return cn;}。

学生信息管理系统源代码

学生信息管理系统源代码

#include<stdio.h>#include <stdlib.h>#include <string.h>typedef struct{long class_1; //班级long number; //学号char name[20]; //姓名float math; //数学float c_program; //C语言float physics; //大学物理float english; //大学英语float polity; //政治float sport; //体育float summary; //总分float average; //平均分}Student;Student stud[100]; //定义结构体数组变量的大小int i=0; //i用于记录输入的学生的个数int menu() //菜单函数{int a;printf("***********************学生信息管理系统*************************\n");//菜单选择printf("\t\t【1】输入学生信息\n");printf("\t\t【2】显示所有学生的信息\n");printf("\t\t【3】按平均分升降排序\n");printf("\t\t【4】根据学生的学号查找学生的信息\n");printf("\t\t【5】插入学生的信息\n");printf("\t\t【6】删除学生的信息\n");printf("\t\t【7】修改学生的信息\n");printf("\t\t【8】从文件中读入数据\n");printf("\t\t【9】将所有记录写入文件\n");printf("\t\t【0】退出本系统\n");printf("***********************学生信息管理系统*************************\n");printf("请选择你要的操作【0-9】:");scanf("%d",&a); //读入一个数while(a<0 || a>9){printf("输入错误!请重新输入。

学生管理系统程序源代码

学生管理系统程序源代码

学生管理系统程序源代码简介:学生管理系统是一种用于学校或者教育机构管理学生信息的软件系统。

它可以匡助学校管理学生的个人信息、课程信息、成绩信息等。

本文将提供一个标准格式的学生管理系统程序源代码,用于展示如何设计和实现一个简单的学生管理系统。

源代码:```python# 导入所需库import csv# 定义学生类class Student:def __init__(self, id, name, age, grade):self.id = id = nameself.age = ageself.grade = grade# 定义学生管理系统类class StudentManagementSystem:def __init__(self):self.students = []# 添加学生def add_student(self, student):self.students.append(student)# 删除学生def delete_student(self, student):self.students.remove(student)# 根据学生ID查找学生def find_student_by_id(self, id):for student in self.students:if student.id == id:return studentreturn None# 根据学生姓名查找学生def find_student_by_name(self, name):for student in self.students:if == name:return studentreturn None# 导出学生信息到CSV文件def export_to_csv(self, filename):with open(filename, 'w', newline='') as file:writer = csv.writer(file)writer.writerow(["ID", "Name", "Age", "Grade"])for student in self.students:writer.writerow([student.id, , student.age, student.grade]) # 从CSV文件导入学生信息def import_from_csv(self, filename):with open(filename, 'r') as file:reader = csv.reader(file)next(reader) # 跳过标题行for row in reader:id = row[0]name = row[1]age = row[2]grade = row[3]student = Student(id, name, age, grade)self.add_student(student)# 示例用法if __name__ == "__main__":# 创建学生管理系统对象sms = StudentManagementSystem()# 添加学生student1 = Student("001", "Alice", 18, "A")student2 = Student("002", "Bob", 17, "B")sms.add_student(student1)sms.add_student(student2)# 根据ID查找学生found_student = sms.find_student_by_id("001")if found_student:print("Found student:", found_)else:print("Student not found.")# 根据姓名查找学生found_student = sms.find_student_by_name("Bob") if found_student:print("Found student:", found_)else:print("Student not found.")# 导出学生信息到CSV文件sms.export_to_csv("students.csv")# 从CSV文件导入学生信息sms.import_from_csv("students.csv")```以上是一个简单的学生管理系统程序的源代码示例。

学生信息管理系统代码

学生信息管理系统代码

主要代码如下:1、登录界面代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB.RecordsetPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.RecordsetStatic i%cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表where 用户名='" & usna & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "用户名不存在!"cn.CloseText1.Text = ""Text2.Text = ""Text1.SetFocusElseIf Trim(rst("密码")) = Trim(Text2.Text) Then管理界面.ShowElsei = i + 1If i < 3 ThenMsgBox "用户名或密码错误!", vbOKOnly + vbExclamation, "警告"cn.CloseText2.Text = ""Text1.Text = ""Text1.SetFocusElseMsgBox "该用户已被锁定!", vbOKOnly + vbExclamation, "警告"End IfEnd IfEnd IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub2、管理界面代码:Private Sub Sinsert_Click()添加学生信息.Show. End SubPrivate Sub Sselect_Click()查询学生信息.ShowEnd SubPrivate Sub sustu_Click()查询更新学生信息.ShowEnd SubPrivate Sub xgmm_Click()修改密码.ShowEnd SubPrivate Sub yhzc_Click()用户注册.ShowEnd Sub3、查询学生信息代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB.RecordsetPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenIf Combo1.Text <> "" Thenmysql = "select * from 学生信息表where 系别='" & Trim(Combo1.Text) & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "没有学生!", vbOKOnly + vbExclamation, "警告"Combo1.Text = ""ElseWith MSFlexGrid1.TextMatrix(0, 1) = "学号".TextMatrix(0, 2) = "姓名".TextMatrix(0, 3) = "性别".TextMatrix(0, 4) = "年龄".TextMatrix(0, 5) = "系别".TextMatrix(0, 6) = "班级"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("学号").TextMatrix(.Rows - 1, 2) = rst.Fields("姓名").TextMatrix(.Rows - 1, 3) = rst.Fields("性别").TextMatrix(.Rows - 1, 4) = rst.Fields("年龄").TextMatrix(.Rows - 1, 5) = rst.Fields("系别").TextMatrix(.Rows - 1, 6) = rst.Fields("班级")rst.MoveNextLoopEnd WithEnd IfElseIf Combo2.Text <> "" Thenmysql = "select * from 学生信息表where 班级='" & Trim(Combo2.Text) & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "没有学生!", vbOKOnly + vbExclamation, "警告"Combo1.Text = ""ElseWith MSFlexGrid1.TextMatrix(0, 1) = "学号".TextMatrix(0, 2) = "姓名".TextMatrix(0, 3) = "性别".TextMatrix(0, 4) = "年龄".TextMatrix(0, 5) = "系别".TextMatrix(0, 6) = "班级"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("学号").TextMatrix(.Rows - 1, 2) = rst.Fields("姓名").TextMatrix(.Rows - 1, 3) = rst.Fields("性别").TextMatrix(.Rows - 1, 4) = rst.Fields("年龄").TextMatrix(.Rows - 1, 5) = rst.Fields("系别").TextMatrix(.Rows - 1, 6) = rst.Fields("班级")rst.MoveNextLoopEnd WithEnd IfElseIf Text1.Text <> "" Thenmysql = "select * from 学生信息表where 学号='" & Trim(Text1.Text) & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "没有学生!", vbOKOnly + vbExclamation, "警告"Combo1.Text = ""ElseWith MSFlexGrid1.TextMatrix(0, 1) = "学号".TextMatrix(0, 2) = "姓名".TextMatrix(0, 3) = "性别".TextMatrix(0, 4) = "年龄".TextMatrix(0, 5) = "系别".TextMatrix(0, 6) = "班级"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("学号").TextMatrix(.Rows - 1, 2) = rst.Fields("姓名").TextMatrix(.Rows - 1, 3) = rst.Fields("性别").TextMatrix(.Rows - 1, 4) = rst.Fields("年龄").TextMatrix(.Rows - 1, 5) = rst.Fields("系别").TextMatrix(.Rows - 1, 6) = rst.Fields("班级")rst.MoveNextLoopEnd WithEnd IfElseMsgBox "请输入查询条件!", vbOKOnly + vbExclamation, "警告"End IfEnd SubPrivate Sub Command2_Click() Combo1.Text = ""Combo2.Text = ""Text1.Text = ""End SubPrivate Sub Command3_Click()修改学生信息.ShowEnd Sub '修改学生信息Private Sub Command4_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openmysql = "delete from 学生信息表where 学号='" & Text1.Text & "'"rst.Open mysql, cnMsgBox "删除成功!", vbOKOnly + vbExclamation, "警告"End SubPrivate Sub Form_Load()Combo1.AddItem "信息服务学院"Combo1.AddItem "电子信息工程系"Combo2.AddItem "40821P" Combo2.AddItem "40811P" Combo2.AddItem "40822P" Combo2.AddItem "40721P"End Sub4、添加学生信息代码Dim cn As New ADODB.Connection Dim rst As New ADODB.RecordsetPrivate Sub Form_Load()Combo1.AddItem "信息服务学院" Combo1.AddItem "电子信息工程系" Combo2.AddItem "40821P" Combo2.AddItem "40811P" Combo2.AddItem "40822P" Combo2.AddItem "40721P"End SubPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenDim sex As Stringusna = Trim(Text1.Text)mysql = "select * from 学生信息表where 学号='" & usna & "'"rst.Open mysql, cnIf rst.EOF Thenrst.CloseElserst.CloseMsgBox "该学生信息已存在!", vbOKOnly + vbExclamation, "警告"Text1.Text = ""Text2.Text = ""Text3.Text = ""Combo1.Text = ""Combo2.Text = ""Option1.Value = FalseText1.SetFocusEnd IfIf Text1.Text = "" ThenMsgBox "请输入学号!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入姓名!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请输入年龄!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd IfIf Option1.Value Thensex = "男"Elsesex = "女"End Ifxh = Trim(Text1.Text)xm = Trim(Text2.Text)xb = sexnl = Trim(Text3.Text)xofy = Trim(Combo1.Text)bj = Trim(Combo2.Text)mysql = "insert into 学生信息表(学号,姓名,性别,年龄,系别,班级) values ('" & xh & "','" & xm & "','" & xb & "','" & nl & "','" & xofy & "','" & bj & "')"rst.Open mysql, cnMsgBox ("信息添加成功!")Text1.Text = ""Text2.Text = ""Text3.Text = ""Combo1.Text = ""Combo2.Text = ""Option1.Value = FalseEnd Sub5、修改密码:Dim rst As New ADODB.RecordsetDim cn As New ADODB.ConnectionPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenIf Text1.Text = "" ThenMsgBox "请输入密码!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入新密码!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请确认输入的新密码!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd IfIf Text2.Text = Text3.Text Thenxmm = Trim(Text2.Text)mysql = "update 用户表set 密码= '" & xmm & "' where 用户名= '" & 登陆.Text1.Text & "'"rst.Open mysql, cnMsgBox ("密修改成功!")End IfEnd SubPrivate Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub6、修改学生信息代码:Dim cn As New ADODB.ConnectionDim rst As New ADODB.RecordsetPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 学生信息表where 学号='" & usna & "'"rst.Open mysql, cnrst.Closemysql = "delete from 学生信息表where 学号='" & Text1.Text & "'"rst.Open mysql, cnIf Text1.Text = "" ThenMsgBox "请输入学号!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入姓名!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请输入年龄!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd IfIf Option1.Value Thensex = "男"Elsesex = "女"End Ifxh = Trim(Text1.Text)xm = Trim(Text2.Text)xb = sexnl = Trim(Text3.Text)xofy = Trim(Combo1.Text)bj = Trim(Combo2.Text)mysql = "insert into 学生信息表(学号,姓名,性别,年龄,系别,班级) values ('" & xh & "','" & xm & "','" & xb & "','" & nl & "','" & xofy & "','" & bj & "')"rst.Open mysql, cnMsgBox ("信息修改成功!")Text1.Text = ""Text2.Text = ""Text3.Text = ""Combo1.Text = ""Combo2.Text = ""Option1.Value = False End SubPrivate Sub Form_Load()Combo1.AddItem "信息服务学院" Combo1.AddItem "电子信息工程系" Combo2.AddItem "40821P" Combo2.AddItem "40811P" Combo2.AddItem "40822P" Combo2.AddItem "40721P"End Sub7、用户注册代码:Dim rst As New ADODB.RecordsetDim cn As New ADODB.ConnectionPrivate Sub Command1_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.OpenIf Text1.Text = "" ThenMsgBox "请输入用户名!", vbOKOnly + vbExclamation, "警告"Text1.SetFocusExit SubEnd IfIf Text2.Text = "" ThenMsgBox "请输入密码!", vbOKOnly + vbExclamation, "警告"Text2.SetFocusExit SubEnd IfIf Text3.Text = "" ThenMsgBox "请再次输入密码!", vbOKOnly + vbExclamation, "警告"Text3.SetFocusExit SubEnd Ifsryhm = Trim(Text1.Text)srmm = Trim(Text2.Text)mysql = "insert into 用户表(用户名,密码) values ('" & sryhm & "','" & srmm & "')"rst.Open mysql, cnMsgBox ("用户添加成功!")Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub '添加用户Private Sub Command2_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub '重置按钮Private Sub Command3_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表where 用户名='" & usna & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "用户名可用!"ElseMsgBox "用户名已存在!", vbOKOnly + vbExclamation, "警告"Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusExit SubEnd IfEnd Sub '检查用户名Private Sub Command4_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist SecurityInfo=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openusna = Trim(Text1.Text)mysql = "select * from 用户表where 用户名='" & usna & "'"rst.Open mysql, cnIf rst.EOF ThenMsgBox "无此用户名,删除不成功!", vbOKOnly + vbExclamation, "警告"Elserst.Closeusna = Trim(Text1.Text)mysql = "delete from 用户表where 用户名='" & usna & "'"rst.Open mysql, cnMsgBox "删除成功!", vbOKOnly + vbExclamation, "警告"Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd IfEnd Sub '删除用户Private Sub Command5_Click()Set cn = New ADODB.ConnectionSet rst = New ADODB.Recordsetcn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=students info;Data Source=C1847"cn.Openmysql = "select * from 用户表"rst.Open mysql, cnIf rst.EOF ThenMsgBox "出错!", vbOKOnly + vbExclamation, "警告"End IfWith MSFlexGrid1.TextMatrix(0, 1) = "用户名".TextMatrix(0, 2) = "密码"MSFlexGrid1.Rows = 1 '每次查询自动定位到第一行Do While Not rst.EOF.Rows = .Rows + 1.CellAlignment = 8.TextMatrix(.Rows - 1, 1) = rst.Fields("用户名").TextMatrix(.Rows - 1, 2) = rst.Fields("密码")rst.MoveNextLoopEnd Withrst.CloseEnd Sub '查询用户表如有侵权请联系告知删除,感谢你们的配合!。

[工学]学生信息管理系统完整源码

[工学]学生信息管理系统完整源码

学生信息管理系统完整源代码注:本系统采用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("授课信息重复");。

简单学生管理信息系统源代码

简单学生管理信息系统源代码

package xsgl;import java.awt。

*;import java.awt。

event。

*;import java。

sql。

*;import java。

util.*;import javax。

swing。

*;import java。

util。

Vector;import javax.swing。

table.*;import java。

awt。

event.*;public class Xsglxt extends JFrame implements ActionListener//继承JFrame 并实现接口ActionListener{JPanel mb1,mb2;JLabel bq1;JTextField wbk1;JButton an1,an2,an3,an4;JTable bg1; //定义表格对象JScrollPane gd1;Xsxx xsxx2;//定义Xsxx类的一个对象xsxx2 public static void main(String[] args){Xsglxt xs=new Xsglxt();}public Xsglxt() //XSGLXT构造方法,用于对象初始化。

{mb1=new JPanel();bq1=new JLabel(”请输入姓名”);wbk1=new JTextField(10);an1=new JButton(”查询”);an1.addActionListener(this); //对按钮1添加监听an1。

setActionCommand(”chaxun”);//设置按钮1的监听信息mb1.add(bq1);mb1.add(wbk1); mb1.add(an1);mb2=new JPanel();an2=new JButton("添加”);an2。

addActionListener(this);an2。

setActionCommand("tianjia”);an3=new JButton(”修改”);an3.addActionListener(this);an3。

学生信息管理系统c语言版源代码

学生信息管理系统c语言版源代码

学生信息管理系统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();}。

学生信息系统源代码

学生信息系统源代码

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<conio.h>#define MY1 printf("\t学号\t姓名\t性别\t年龄\t出生年月\t地址\t电话\t")#define MY2 printf("\n%d\t%6s\t%4s\t%2d\t%4d%2d%2d\t%4s\t%6s\t\n",s[i].num,s[i].name,s[i].sex,s[i].age,s[ i].a.year,s[i].a.month,s[i].a.day,s[i].address,s[i].tel)#define MAX 20int i;int sum;/*时间结构体类型*/struct date{int year;int month;int day;}a;struct s_message{int num;char name[20];char sex[5];int age;struct date a;char address[50];char tel[11];char email[20];}s[MAX];/*保存学生信息模块*/void save_message(int sum){int i;FILE *fp;if((fp=fopen("D:\\s.txt","wb"))==NULL){printf("reading file is wrong!\n");return;}for (i=0;i<sum;i++){if(fwrite(&s[i],sizeof(struct s_message),1,fp)!=1)printf("writing file is wrong!\n");}fclose(fp);}/*读取学生信息模块*/int read_message(){FILE *fp;int i=0;if((fp=fopen("D:\\s.txt","rb"))==NULL){printf("\n\n***********暂时无任何库存信息,按回车键进入主菜单选择基本信息的录入!***********\n");return 0;}while(feof(fp)==0) /*feof(fp)有两个返回值:如果遇到文件结束,函数feof(fp)的值为1,否则为0。

课程设计:学生学籍管理系统源代码

课程设计:学生学籍管理系统源代码

#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]。

学生信息管理系统(简单版)源代码

学生信息管理系统(简单版)源代码

学生信息管理系统(简单版)源代码#include#include#include#include#define NUll 0#define LEN sizeof(struct student)struct student{int number;char name[10];float score;struct student *next;};/*函数说明*/struct student * creat(); /*创建链表*/void print(struct student *head); /*输出学生信息*/struct student *add(struct student *head); /*添加学生信息*/ struct student * sort(struct student *head); /*对学生信息进行排序*/struct student * insert(struct student *head); /*插入学生信息*/struct student * del_num(struct student *head); /*删除学生信息*/void search(struct student *head); /*查找学生信息*/struct student * change(struct student *head); /*修改学生信息*/int n;int main(){int num,x;char a[5];struct student *head0,*head,*head1; head=NUll;A :printf(" 学生信息系统 \n");printf("1.建立链表\n");printf("2.添加学生\n");printf("3.插入学生\n");printf("4.删除学生\n");printf("5.查找学生\n");printf("6.修改学生\n");printf("7.数据浏览\n");printf("0.退出程序\n");printf("请选择操作(输入0—7):"); scanf("%d",&num);switch(num){case 1:head=creat();break;case 2:head=add(head);head=sort(head);print(head);break;case 3:head1=insert(head);head1=sort(head1);print(head1);break;case 4:head1=del_num(head);print(head1);break;case 5:search(head);break;case 6:head1=change(head);print(head1);break;case 7:print(head);break;case 0:return 0;default :printf("输入错误的数字!!请再输一次!\07\n"); }goto A;scanf("%d",&x);return 0;}//创建链表struct student * creat(){struct student *head,*p1,*p2;n=0;head=(struct student*)malloc(LEN); if(head!=NULL){printf("空链表已建立!\n");}else{printf("没有足够的内存空间!\07\n"); }head->number=0;strcpy(head->name,"");head->score=0;return head;}//输出学生信息void print(struct student *head) {struct student *p;if(head==NULL){printf("未建立链表!!\n"); return;}p=head->next;printf("\n所有学生信息的显示为:\n");do{printf("学号:%d\t姓名:%s\t分数:%.2f\n",p->number,p->name,p->score);p=p->next;}while(p!=NUll);}//添加学生信息struct student *add(struct student *head){struct student *p1,*p2;if(head==NULL){printf("未建立链表!!\n");return NULL;}p1=head;while(1){p2=(struct student *)malloc(LEN);if(p2==NULL){printf("没有足够的空间!\07\n");return 0;}printf("学号(输入0结束):");scanf("%d",&p2->number);if(p2->number==0){break;}printf("姓名:");scanf("%s",&p2->name);printf("分数:");scanf("%f",&p2->score);n=n+1;//p2->next=NULL;p1->next=p2;p1=p2;}p1->next=NULL;return head;}//对学生信息进行排序struct student * sort(struct student *head) {int t1;float t2;struct student *p1,*p2;if(head==NULL){printf("未建立链表!!\n");return NULL;}p1=head;p2=head->next;for(int i=1;i<n;i++){p1=head->next;p2=p1->next;do{if((p1->number)<(p2->number)){t1=p1->number;t2=p1->score;p1->number=p2->number;p1->score=p2->score;p2->number=t1;p2->score=t2;}p2=p1;p1=p1->next;}while(p1!=NULL);}printf("自动排序……");return head;}//插入学生信息struct student * insert(struct student *head) {struct student *p1,*p2,*stu;if(head==NULL){printf("未建立链表!!\n"); return NULL;}while(1){p1=head->next;p2=p1;stu=(struct student *)malloc(LEN); if(stu==NULL){printf("没有足够的空间!\07\n"); return 0;}printf("\n学号(输入0结束):"); scanf("%d",&stu->number);if(stu->number==0){break;}printf("姓名:");scanf("%s",&stu->name);printf("分数:");scanf("%f",&stu->score);n=n+1;if(stu->numbernumber){stu->next=p1;head->next=stu;}else{while((stu->number)>(p1->number)&&p1!=NULL) {p2=p1;p1=p1->next;}if((stu->number)<=(p1->number)){p2->next=stu;stu->next=p1;}else{p1=stu;stu->next=NULL;}}}return head;}//删除学生信息struct student * del_num(struct student *head) {struct student *p1,*p2;if(head==NULL){printf("未建立链表!!\n");return NULL;}int num;while(1){printf("学号(输入0结束):"); scanf("%d",&num);if(num==0){break;}p1=head;if(num==head->number){head=p1->next;}else{do{p2=p1;p1=p1->next;if(num==p1->number){printf("\n已找到要删除的学生!\n"); p2->next=p1->next;printf("删除完成!\n");n=n-1;break;}}while(p1->next!=NULL);}}return head;}//查找学生信息void search(struct student *head) {int num;struct student *p1;if(head==NULL){printf("未建立链表!!\n"); return;}p1=head->next;while(1){printf("学号(输入0结束):"); scanf("%d",&num);if(num==0){break;}do{if(num==p1->number){printf("该生信息已找到!\n其学号为:%d,姓名为:%s成绩为:%.2f\</n;i++)n",p1->number,p1->name,p1->score);break;}p1=p1->next;if(p1==NULL){printf("未找到学号为%d的相关信息!!\n",num);}}while(p1!=NULL);}}//修改学生信息struct student * change(struct student *head){int num;float score1;struct student *p1;if(head==NULL){printf("未建立链表!!\n");return NULL;}p1=head;printf("学号(输入0结束):\t");scanf("%d",&num);do{if(num==p1->number){printf("已找到学号为%d的同学。

C语言学生信息管理系统(附源码)

C语言学生信息管理系统(附源码)
getch();
fclose(fp);
return;
}
printf("姓名:");
scanf("%s",stu[m].name);
printf("语文成绩:");
scanf("%f",&stu[m].chinese);
printf("数学成绩:");
scanf("%f",&stu[m].math);
char ch[2];
if((fp=fopen("stuData.txt","rb"))==NULL)
{
printf("打开文件失败\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("文件无记录!\n");
default:printf("输入有误,请重新输入:");break;
}
getch();
menu();
scanf("%d",&n);
}
return 0;
}
/*******自定义函数实现菜单功能******/
void menu()
{
system("cls");
printf("\t\t|-------------学生信息系统----------|\n");
printf("\t\t| |\n");

学生信息管理系统源代码

学生信息管理系统源代码

#include "conio.h"#include <stdio.h>#include<stdlib.h>#define MAX 30/*日期结构体类型*/typedef struct{int year;int month;int day;}DATE;/*学生结构体类型*/typedef struct{int num;char name[10];char sex[10];DATE birthday;int score ;}STU;int read_file(STU students[]){ FILE*fp;int i=0;if((fp=fopen("lab.txt","rt"))==NULL) {printf("\n\n*****库文件不存在!请重建");return 0;}while(feof(fp)!=1){fread(&students[i],sizeof(STU),1,fp);if(students[i].num==0)break;elsei++;}fclose(fp);return i;}void save_file(STU students[],int sum){ FILE *fp;int i;if((fp=fopen("lab.txt","wb"))==NULL) { printf("读文件错误!\n");return;}for(i=0;i<sum;i++)if(fwrite(&students[i],sizeof(STU),1,fp)!=1) printf("写文件错误!\n");fclose(fp);}/*输入模块*/int input(STU students[]){int i=0,sum;system("cls");printf("\n\n 录入学生个数\n\n");scanf("%d",&sum);printf("\n\n 录入学生信息\n",MAX);printf("\n\n ----------------------\n") ;for(i=0;i<sum;i++){ printf("\n第%d个人",i+1) ;printf("\n\n 学号");scanf("%d",&students[i].num) ;printf("\n\n 姓名") ;scanf("%s",&students[i].name);printf("\n\n 性别");scanf("%s",&students[i].sex);printf("\n\n 出生日期") ;printf("\n\n 年");scanf("%d",&students[i].birthday.year);printf("\n\n 月");scanf("%d",&students[i].birthday.month);printf("\n\n 日");scanf("%d",&students[i].birthday.day);printf("\n\n 成绩");scanf("%d",&students[i].score );}printf("\n---%d个学生信息输入完毕---\n",i);printf("---按任意键返回主菜单---") ;return i;}/*输出模块*/void output(STU students[],int sum){system("cls");{ int i=0;for(i=0;i<sum;i++){printf("\n -------学生信息------- \n");printf("学号姓名性别出生日期成绩\n");printf("------------------------------- \n");printf("%4d %10s %8s %15d-%2d-%2d %3d\n",students[i].num,students[i].name,students[i].sex,students[i].birthday.year,students[i].birthday.month,students[i].birthday.day,students[i].score );}}printf("按任意键返回主菜单\n");getch();}/*添加模块*/int append(STU students[],int sum){ system("cls");{int i,j;printf("请输入要添加的学生数量:\n");scanf("%d",&j);for(i=sum;i<sum+j;i++){ printf("---按格式输入提示内容:\n");printf("请输入学号:\n");scanf("%d",&students[i].num);printf("请输入姓名:\n");scanf("%s", &students[i].name );printf("请输入性别:\n");scanf("%s",&students[i].sex);printf("请输入出生日期:\n");scanf("%d-%d-%d",&students[i].birthday.year,&students[i].birthday.month,&students[i].birthday.day);printf("请输入成绩:\n") ;scanf ("%d",students[i].score );}printf("%d本信息输入完毕",i);printf("学号姓名性别出生日期成绩\n");printf("------------------------------- \n");printf("%4d %10s %8s %15d-%2d-%2d %3d\n",students[i].num,students[i].name,students[i].sex,students[i].birthday.year,students[i].birthday.month,students[i].birthday.day,students[i].score );printf("按任意键返回主菜单\n");sum=sum+j;return(sum);}}/*修改模块*/void modify(STU students[],int sum){ int i=0,choice,modify_num,flag;do{system("cls") ;printf("\n输入要修改的学生学号\n") ;scanf("%d",&modify_num);for(i=0;i<sum;i++)if(students[i].num==modify_num){printf("\n -------学生信息------- \n");printf("学号姓名性别出生日期成绩\n");printf("------------------------------- \n");printf("%4d %6s %4s %10d-%2d-%2d %6d\n",students[i].num,students[i].name,students[i].sex,students[i].birthday.year,students[i].birthday.month,students[i].birthday.day,students[i].score );printf(" \n 您要修改那一项\n ");printf(" \n 1 学号\n ");printf(" \n 2 姓名\n ");printf(" \n 3 性别\n ");printf(" \n 4 出生日期\n ");printf(" \n 5 成绩\n ");printf(" \n 请选择(1-4): \n ");scanf ("%d",&choice);switch(choice){case 1:printf("\n 输入修改后的学号:");scanf("%d",&students[i].num); break;case 2:printf("\n 输入修改后的姓名:");scanf("%s",&students[i].name); break;case 3:printf("\n 输入修改后的性别:");scanf("%s",&students[i].sex); break;case 4:printf("\n 输入修改后的出生日期");scanf("%d-%d-%d",&students[i].birthday.year,&students[i].birthday.month,&students[i].birthday.day); break;case 5:printf("\n 输入修改后的成绩:");scanf("%d",&students[i].score); break;}printf("\n -------该学生信息------- \n");printf("学号姓名性别出生日期成绩\n");printf("------------------------------- \n");printf("%4d %6s %4s %10d-%2d-%2d %6d\n",students[i].num,students[i].name,students[i].sex,students[i].birthday.year,students[i].birthday.month,students[i].birthday.day,students[i].score );break;}if(i==sum){printf("\n 该学号不存在" );// bioskey(0);}printf("\n\n 继续修改吗?(Y/N) ");choice=getch();if(choice=='Y'||choice=='y'){flag=1;printf("\n 继续!\n");}else flag=0;}while(flag==1);printf("\n---按任意键返回主菜单---\n");//bioskey(0);}/*删除模块*/void del(STU students[],int sum)int j;int del_num;system("cls") ;printf("\n输入要删除的学生学号\n") ;scanf("%d",&del_num);for(i=0;i<sum;i++)if(students[i].num==del_num) break;for(j=i;j<sum;j++)students[j] =students[j+1];}/*查询模块*/void inquire(STU students[],int sum){ int i=0,choice,inquire_num,flag;do{ system("cls") ;printf("\n输入要查询的学生学号\n") ;scanf("%d",&inquire_num);for(i=0;i<sum;i++)if(students[i].num==inquire_num){ printf("\n -------该学生信息------- \n");printf("学号姓名性别出生日期成绩\n");printf("------------------------------- \n");printf("%4d %6s %4s %10d-%2d-%2d %6d\n",students[i].num,students[i].name,students[i].sex,students[i].birthday.year,students[i].birthday.month,students[i].birthday.day,students[i].score ); break;}if(i==sum){printf("\n 该学号不存在" );//bioskey(0);}printf("\n\n 继续查询吗?(Y/N) ");choice=getch();if(choice=='Y'||choice=='y'){flag=1;printf("\n 继续!\n");else flag=0;}while(flag==1);printf("\n---按任意键返回主菜单---\n");//bioskey(0);}/*排序模块*/void sort(STU students[],int sum){STU t;int i,j,k;system("cls") ;printf("\n------------------库行排名--------------------------\n");printf("\n----------------------------------------------------\n");printf("\n 排名学号姓名性别出生日期\n ") ;for(i=0;i<sum;i++){ k=i;for(j=i+1;j<sum;j++)if (students[i].score>students[j].score) k=j;if (k!=i){t=students[i];students[i]=students[k];students[k]=t;}}output(students, sum);//bioskey(0);}void main(){ STU students[MAX];int choice,sum;sum=read_file(students);if(sum==0){ printf("****并录入基本库存信息!****\n");getch();sum=input(students);}do{system("cls");printf("\n\n\n ****学生管理系统*****\n\n") ; printf(" 1 添加学生信息\n\n") ;printf(" 2 修改学生信息\n\n") ;printf(" 3 删除学生信息\n\n") ;printf(" 4 打印学生信息\n\n") ;printf(" 5 查询学生信息\n\n") ;printf(" 6 排序学生信息\n\n") ;printf(" 0 退出系统\n\n\n") ;printf(" 请选择(0-6):") ;scanf("%d",&choice) ;switch (choice){case 1:sum=append(students,sum); break;case 2:modify(students,sum); break;case 3:del(students,sum); break;case 4:output(students,sum); break;case 5:inquire(students,sum);break;case 6:sort(students,sum); break;case 0: break;}}while(choice!=0);save_file(students,sum);}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

package xsgl;
import java.awt.*; import java.awt.event.*; import java.sql.*; import java.util.*; import javax.swing.*; import java.util.Vector; import javax.swing.table.* import java.awt.event.*; public class Xsglxt
接口 ActionListener extends JFrame implements { ActionListener // 继承 JFrame 并实现
JPanel mb1, mb2; JLabel bq1 ;
JTextField wbk1;
JButton an1, an2, an3 , an4; JTable bg1 ; JScrollPane
Xsxx xsxx2 ;
// 定义表格对象
化。

gd1; // 定义 Xsxx 类的一个对象 xsxx2
public static
{
Xsglxt xs=
}
public Xsglxt() void main(String[] args)
new Xsglxt(); //XSGLXT 构造方法,用于对象初始
mb1=new JPanel();
bq1 =new JLabel( " 请输入姓名 " ); wbk1 =new JTextField(10); an1 =new JButton( "查询"); an1 .addActionListener( this ); an1 .setActionCommand(
"chaxun"
mb1.add( bq1); mb1.add( wbk1 ); );
mb1.add( // 对按钮 1添加监听
// 设置按钮 1的监听信息 an1);
mb2=new JPanel();
an2 =new JButton( "添加");
an2 .addActionListener( this ); an2 .setActionCommand( "tianjia" an3 =new JButton( "修改");
an3 .addActionListener( this ); an3 .setActionCommand( "xiugai" an4 =new JButton( "删除");
an4 .addActionListener( this ); an4 .setActionCommand( "shanchu"
);
);
);
mb2.add( an2); mb2.add( an3); mb2.add( an4); xsxx2 =new Xsxx(); bg1 =new JTable( xsxx2 );
gd1 =new JScrollPane(
bg1);
.add( gd1);
.add( mb1, "North"
.add( mb2, "South"
String xingming= this . wbk1 .getText().trim();
// 将本窗口的文本框 1中文本取出,
忽略前后空格后赋给变量 xingming
String sql= "select * from xuesheng where xingming='"
+xingming+ "'"
//将SQL 语句赋给String 类型变量sql
//将String 类型变量sql 作为参数NEW-个
bg1 .setModel( xsxx2 );
// 将表 bg1 的数据模型设为 newModel ,并向其注
册以获取来自新数据模型的侦听器通知。

}
else {
Tianjia tj= new Tianjia( this
xsxx2 =new Xsxx(); //无
参数传递的 NEW 个Xsxx 类的对象xsxx2 bg1.setModel( xsxx2 );
int ii= this . bg1 .getSelectedRow();
// 使用 getSelectedRow() 方法返回第一个选定
JOptionPane. showMessageDialog (this , " 请选中要修改的行 " ); // 显示一个
错误对话框
return
}
new Xiugai( this , " 修改学生信息 ", true , xsxx2 ,ii);
this this this this this this } public
.setTitle( " 学生管理系统 " ); .setSize(500,400); .setLocation(201,181); .setResizab le( false ); .setDefaultCloseOperation(JFrame. .setVisible( true );
EXIT_ON_CLOSE);
void actionPerformed(ActionEvent e) 抽象方法 // 实现接口 ActionListener 中的
actionPerformed { if (e.getActionCommand().equals( "chaxun" (是不是查询按钮)
{
"chaxun" )) // 判断监听到的组件信息是不是
this this this ); );
xsxx2 =new Xsxx(sql); Xsxx 类的对象 xsxx2
if (e.getActionCommand().equals(
"tianjia" ))
, " 添加学生信息 " , true );
} else
{
if (e.getActionCommand().equals( "xiugai" ))
行的索引;如果没有选定的行,则返回
-1
i f
{
(ii==-1)。

相关文档
最新文档