java管理系统源代码(java程序)
今天给各位分享java管理系统源代码的知识,其中也会对java程序进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
急求java学生信息管理系统源代码,带有连接数据库的,万分感谢
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip= null;
SelectPanel sp= null;
JPanel pframe;
JButton jb1,jb2,jb3;
JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb= new JMenuBar();
this.setJMenuBar(mb);
JMenu m1= new JMenu("系统");
JMenu m2= new JMenu("基本信息");
JMenu m3= new JMenu("成绩");
JMenu m4= new JMenu("奖惩");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11= new JMenuItem("退出系统");
jm21= new JMenuItem("输入");
jm22= new JMenuItem("查询");
jm23= new JMenuItem("更改");
jm31= new JMenuItem("输入成绩");
jm32= new JMenuItem("查询成绩");
jm41= new JMenuItem("奖励");
jm42= new JMenuItem("处分");
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
m4.add(jm41);
m4.add(jm42);
Icon i1= new ImageIcon();
Icon i2= new ImageIcon();
Icon i3= new ImageIcon();
jb1= new JButton(i1);
jb1.setToolTipText("输入");
jb2= new JButton(i2);
jb2.setToolTipText("查询");
jb3= new JButton(i3);
jb3.setToolTipText("退出");
JToolBar tb= new JToolBar("系统工具");
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout= new CardLayout();
pframe= new JPanel(clayout);
add(pframe);
JPanel mainp= new JPanel(new BorderLayout());
JLabel mainl= new JLabel("学生信息管理平台",SwingConstants.CENTER);
mainl.setFont(new Font("serif",Font.BOLD,30));
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe,"main");
}
public void actionPerformed(ActionEvent e){
if(e.getSource()== jm21|| e.getSource()== jb1){
if(ip== null){
ip= new InsertPanel();
pframe.add(ip,"insert");
}
clayout.show(pframe,"insert");
this.setTitle("输入学生信息");
}
else if(e.getSource()== jm22|| e.getSource()== jb2){
if(sp== null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe,"select");
this.setTitle("查询学生信息");
}
else if(e.getSource()== jm11|| e.getSource()== jb3){
System.exit(0);
}
}
}
第二个:
import javax.swing.JFrame;
public class MainTest{
public static void main(String [] args){
MainFrame f= new MainFrame("学生信息管理平台");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二个:
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection{
static Connection getCon(){
Connection con= null;
try{
Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");
}
catch(Exception e){
System.out.println("建立数据库连接遇到异常!");
}
return con;
}
}
第四个:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
JTextField jt1,jt2,jt3,jt4;
public SelectPanel(){
JLabel jl= new JLabel("请输入学号:",SwingConstants.CENTER);
jt= new JTextField();
jb= new JButton("确定");
JPanel jp1= new JPanel(new GridLayout(1,3));
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
JLabel j1,j2,j3,j4;
j1= new JLabel("学号:",SwingConstants.CENTER);
j2= new JLabel("姓名:",SwingConstants.CENTER);
j3= new JLabel("性别:",SwingConstants.CENTER);
j4= new JLabel("年龄:",SwingConstants.CENTER);
jt1= new JTextField(6);
jt1.setEditable(false);
jt2= new JTextField(6);
jt2.setEditable(false);
jt3= new JTextField(6);
jt3.setEditable(false);
jt4= new JTextField(6);
jt4.setEditable(false);
JPanel jp2= new JPanel(new BorderLayout());
JPanel jp3= new JPanel(new GridLayout(4,2));
jp2.add(new JLabel(""),BorderLayout.NORTH);
jp3.add(j1);
jp3.add(jt1);
jp3.add(j2);
jp3.add(jt2);
jp3.add(j3);
jp3.add(jt3);
jp3.add(j4);
jp3.add(jt4);
jp2.add(jp3);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
add(jp2);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()== jb){
String stuNo= jt.getText().trim();
Student s= new Student();
boolean b= true;
try{
b= s.selectByStuNo(stuNo);
}
catch(Exception ex){
System.out.println("查询学生信息遇到异常!");
}
if(b){
jt1.setText(s.getStuNo());
jt2.setText(s.getName());
jt3.setText(s.getGender());
int a= s.getAge();
Integer i= new Integer(a);
jt4.setText(i.toString());
}
else{
JOptionPane.showMessageDialog(null,"无此学生!");
}
}
}
}
第五个:
import javax.swing.JFrame;
public class SelectTest{
public static void main(String [] args){
JFrame f= new JFrame("查询学生信息");
SelectPanel p= new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六个:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class Student{
String stuNo;
String name;
String gender;
int age;
public Student(){}
public Student(String stuNo,String name,String gender, int age){
this.stuNo= stuNo;
this.name= name;
this.gender= gender;
this.age= age;
}
public String getStuNo(){
return stuNo;
}
public void setStuNo(String stuNo){
this.stuNo= stuNo;
}
public String getName(){
return name;
}
public void setName(String name){
this.name= name;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender= gender;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age= age;
}
public boolean insertStudent(){
boolean b= true;
try{
Connection con= MySQLConnection.getCon();
Statement statement= con.createStatement();
String sql="insert into student values('"+ stuNo+"','"+ name+"','"+ gender+"',"+ age+")";
sql= new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b= false;
System.out.println("插入数据库遇到异常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b= true;
Connection con= MySQLConnection.getCon();
Statement statement= con.createStatement();
String sql="select* from student where stuNo="+ stuNo;
ResultSet rs= statement.executeQuery(sql);
if(rs!= null&& rs.next()){
String no= rs.getString(1);
this.setStuNo(no);
String n= rs.getString(2);
n= new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g= rs.getString(3);
g= new String(g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b= true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
数据库你自己弄吧,我没时间弄了!初学得多动手哦
学生考试管理系统,JAva源代码
//主类EnglishTest——
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EnglishTest extends JFrame
{
TestArea testPanel=null;
Container con=null;
public EnglishTest()
{
super("模拟考试");
testPanel=new TestArea();
con=getContentPane();
con.add(testPanel,BorderLayout.CENTER);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
});
setVisible(true);
setBounds(60,40,660,460);
con.validate();
validate();
}
public static void main(String args[])
{
new EnglishTest();
}
}
//读取试题 ReadTestquestion
import java.io.*;
import java.util.*;
public class ReadTestquestion
{ String filename="",
correctAnswer="",
testContent="",
selection="";
int score=0;
long time=0;
boolean完成考试=false;
File f=null;
FileReader in=null;
BufferedReader读取=null;
public void setFilename(String name)
{ filename=name;
score=0;
selection="";
try{
if(in!=null&&读取!=null)
{
in.close();
读取.close();
}
f=new File(filename);
in=new FileReader(f);
读取=new BufferedReader(in);
correctAnswer=(读取.readLine()).trim();
String temp=(读取.readLine()).trim();
StringTokenizer token=new StringTokenizer(temp,":");
int hour=Integer.parseInt(token.nextToken());
int minute=Integer.parseInt(token.nextToken());
int second=Integer.parseInt(token.nextToken());
time=1000*(second+minute*60+hour*60*60);
}
catch(Exception e)
{
testContent="没有选择试题";
}
}
public String getFilename()
{
return filename;
}
public long getTime()
{
return time;
}
public void set完成考试(boolean b)
{
完成考试=b;
}
public boolean get完成考试()
{
return完成考试;
}
public String getTestContent()
{ try{
String s=null;
StringBuffer temp=new StringBuffer();
if(读取!=null)
{
while((s=读取.readLine())!=null)
{
if(s.startsWith("**"))
break;
temp.append("\n"+s);
if(s.startsWith("endend"))
{
in.close();
读取.close();
完成考试=true;
}
}
testContent=new String(temp);
}
else
{
testContent=new String("没有选择试题");
}
}
catch(Exception e)
{
testContent="试题内容为空,考试结束!!";
}
return testContent;
}
public void setSelection(String s)
{
selection=selection+s;
}
public int getScore()
{ score=0;
int length1=selection.length();
int length2=correctAnswer.length();
int min=Math.min(length1,length2);
for(int i=0;i<min;i++)
{ try{
if(selection.charAt(i)==correctAnswer.charAt(i))
score++;
}
catch(StringIndexOutOfBoundsException e)
{
i=0;
}
}
return score;
}20:10 03-8-31
public String getMessages()
{
int length1=selection.length();
int length2=correctAnswer.length();
int length=Math.min(length1,length2);
String message="正确答案:"+correctAnswer.substring(0,length)+"\n"+
"你的回答:"+selection+"\n";
return message;
}
}
//考试区域TestArea
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
class FileName implements FilenameFilter
{
String str=null;
FileName(String s)
{
str="."+s;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
public class TestArea extends JPanel implements ActionListener,ItemListener,Runnable
{
Choice list=null;
JTextArea试题显示区=null,消息区=null;
JCheckBox box[];
JButton提交该题答案,读取下一题,查看分数;
ReadTestquestion读取试题=null;
JLabel welcomeLabel=null;
Thread countTime=null;
long time=0;
JTextField timeShow=null;
boolean是否关闭计时器=false,
是否暂停计时=false;
JButton暂停或继续计时=null;
public TestArea()
{
list= new Choice();
String当前目录=System.getProperty("user.dir");
File dir=new File(当前目录);
FileName fileTxt=new FileName("txt");
String fileName[]=dir.list(fileTxt);
for(int i=0;i<fileName.length;i++)
{
list.add(fileName[i]);
}
试题显示区=new JTextArea(15,12);
试题显示区.setLineWrap(true);
试题显示区.setWrapStyleWord(true);
试题显示区.setFont(new Font("TimesRoman",Font.PLAIN,14));
试题显示区.setForeground(Color.blue);
消息区=new JTextArea(8,8);
消息区.setForeground(Color.blue);
消息区.setLineWrap(true);
消息区.setWrapStyleWord(true);
countTime=new Thread(this);
String s[]={"A","B","C","D"};
box=new JCheckBox[4];
for(int i=0;i<4;i++)
{
box[i]=new JCheckBox(s[i]);
}
暂停或继续计时=new JButton("暂停计时");
暂停或继续计时.addActionListener(this);
提交该题答案=new JButton("提交该题答案");
读取下一题=new JButton("读取第一题");
读取下一题.setForeground(Color.blue);
提交该题答案.setForeground(Color.blue);
查看分数=new JButton("查看分数");
查看分数.setForeground(Color.blue);
提交该题答案.setEnabled(false);
提交该题答案.addActionListener(this);
读取下一题.addActionListener(this);
查看分数.addActionListener(this);
list.addItemListener(this);
读取试题=new ReadTestquestion();
JPanel pAddbox=new JPanel();
for(int i=0;i<4;i++)
{
pAddbox.add(box[i]);
}
Box boxH1=Box.createVerticalBox(),
boxH2=Box.createVerticalBox(),
baseBox=Box.createHorizontalBox();
boxH1.add(new JLabel("选择试题文件"));
boxH1.add(list);
boxH1.add(new JScrollPane(消息区));
boxH1.add(查看分数);
timeShow=new JTextField(20);
timeShow.setHorizontalAlignment(SwingConstants.RIGHT);
timeShow.setEditable(false);
JPanel p1=new JPanel();
p1.add(new JLabel("剩余时间:"));
p1.add(timeShow);
p1.add(暂停或继续计时);
boxH1.add(p1);
boxH2.add(new JLabel("试题内容:"));
boxH2.add(new JScrollPane(试题显示区));
JPanel p2=new JPanel();
p2.add(pAddbox);
p2.add(提交该题答案);
p2.add(读取下一题);
boxH2.add(p2);
baseBox.add(boxH1);
baseBox.add(boxH2);
setLayout(new BorderLayout());
add(baseBox,BorderLayout.CENTER);
welcomeLabel=new JLabel("欢迎考试,提高英语水平",JLabel.CENTER);
welcomeLabel.setFont(new Font("隶书",Font.PLAIN,24));
welcomeLabel.setForeground(Color.blue);
add(welcomeLabel,BorderLayout.NORTH);
}
public void itemStateChanged(ItemEvent e)
{
timeShow.setText(null);
是否关闭计时器=false;
是否暂停计时=false;
暂停或继续计时.setText("暂停计时");
String name=(String)list.getSelectedItem();
读取试题.setFilename(name);
读取试题.set完成考试(false);
time=读取试题.getTime();
if(countTime.isAlive())
{
是否关闭计时器=true;
countTime.interrupt();
}
countTime=new Thread(this);
消息区.setText(null);
试题显示区.setText(null);
读取下一题.setText("读取第一题");
提交该题答案.setEnabled(false);
读取下一题.setEnabled(true);
welcomeLabel.setText("欢迎考试,你选择的试题:"+读取试题.getFilename());
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==读取下一题)
{
读取下一题.setText("读取下一题");
提交该题答案.setEnabled(true);
String contentTest=读取试题.getTestContent();
试题显示区.setText(contentTest);
消息区.setText(null);
读取下一题.setEnabled(false);
try{
countTime.start();
}
catch(Exception event)
{
}
}
if(e.getSource()==提交该题答案)
{
读取下一题.setEnabled(true);
提交该题答案.setEnabled(false);
String answer="?";
for(int i=0;i<4;i++)
{
if(box[i].isSelected())
{
answer=box[i].getText();
box[i].setSelected(false);
break;
}
}
读取试题.setSelection(answer);
}
if(e.getSource()==查看分数)
{
int score=读取试题.getScore();
String messages=读取试题.getMessages();
消息区.setText("分数:"+score+"\n"+messages);
}
if(e.getSource()==暂停或继续计时)
{
if(是否暂停计时==false)
{
暂停或继续计时.setText("继续计时");
是否暂停计时=true;
}
else if(是否暂停计时==true)
{
暂停或继续计时.setText("暂停计时");
是否暂停计时=false;
countTime.interrupt();
}
}
}
public synchronized void run()
{
while(true)
{
if(time<=0)
{
是否关闭计时器=true;
countTime.interrupt();
提交该题答案.setEnabled(false);
读取下一题.setEnabled(false);
timeShow.setText("用时尽,考试结束");
}
else if(读取试题.get完成考试())
{
是否关闭计时器=true;
timeShow.setText("考试效果:分数*剩余时间(秒)="+1.0*读取试题.getScore()*(time/1000));
countTime.interrupt();
提交该题答案.setEnabled(false);
读取下一题.setEnabled(false);
}
else if(time>=1)
{
time=time-1000;
long leftTime=time/1000;
long leftHour=leftTime/3600;
long leftMinute=(leftTime-leftHour*3600)/60;
long leftSecond=leftTime%60;
timeShow.setText(""+leftHour+"小时"+leftMinute+"分"+leftSecond+"秒");
}
try
{
Thread.sleep(1000);
}
catch(InterruptedException ee)
{
if(是否关闭计时器==true)
return;
}
while(是否暂停计时==true)
{
try
{
wait();
}
catch(InterruptedException ee)
{
if(是否暂停计时==false)
{
notifyAll();
}
}
}
}
}
}
求、急~~~学生学籍管理系统 java 源代码
# include<iostream.h>
# include<string.h>
# include<stdio.h>
# include<stdlib.h>
# include<fstream.h>
//*****定义一个学生原子的的数据结构*****//
struct stuatom
{
char*name;
int id;
char sex;
float math, eng, comp, totll, aver;
void show();
void setup();
};
//*********定义一系列对学生的操作**********//
class student
{
private:
stuatom ob[100];
int stulen;
public:
student();
void input();
void order();
void save();
void Query();
void read();
void add();
void del();
};
//********对学生数据的初始化(类的构造函数)**********//
student::student()
{
//用for循环对全部数组中的数据初始化
for(int i=0;i<100;i++)
{
ob[i].math=ob[i].eng=ob[i].comp=ob[i].totll=ob[i].aver=0;
ob[i].id=0;
ob[i].sex='';
ob[i].name=NULL;
}
this->stulen=0;
}
//********输入学生的数据,并判断是否在规定数据域内*******//
void stuatom::setup()
{
char n[20]; char s;
int b;
//如果输入学好在数据域内,跳出循环并且赋值。
//如果不再数据域内,一直循环到输入数据符合数据域为止
do{
cout<<"学号:";
cin>>b;
if(b>1020||b<1001)
cout<<"Bad data input!!"<<endl<<endl;
}while(b<1001||b>1020);
id=b;
//如果输入学好在数据域内,跳出循环并且赋值。
//如果不再数据域内,一直循环到输入数据符合数据域为止
do{
name=new char[strlen(n)+1];
cout<<"姓名:";
cin>>n;
if( strlen(n)>6|| strlen(n)<4)
cout<<"Bad data input!!"<<endl<<endl;
}while( strlen(n)>6&& strlen(n)<4);
strcpy(name,n);
cout<<"性别(m/f):";
cin>>s;
//如果输入学好在数据域内,跳出循环并且赋值。
//如果不再数据域内,一直循环到输入数据符合数据域为止
while(s!='m'&& s!='f')
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<"性别(m/f):";
cin>>s;
}
sex=s;
float m, e, co;
cout<<"数学:";
cin>>m;
//如果输入学好在数据域内,跳出循环并且赋值。
//如果不再数据域内,一直循环到输入数据符合数据域为止
while(m<0|| m>100)
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<"数学:";
cin>>m;
}
math=m;
cout<<"英语:";
cin>>e;
//如果输入学好在数据域内,跳出循环并且赋值。
//如果不再数据域内,一直循环到输入数据符合数据域为止
while(e<0|| e>100)
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<"英语:";
cin>>e;
}
eng=e;
cout<<"计算机:";
cin>>co;
//如果输入学好在数据域内,跳出循环并且赋值。
//如果不再数据域内,一直循环到输入数据符合数据域为止
while(co<0|| co>100)
{
cout<<"Bad data input!!"<<endl<<endl;
cout<<"计算机:";
cin>>co;
}
comp=co;
totll=math+eng+comp;
aver=(math+eng+comp)/3;
}
//*******按照规定格式把该学生的数据显示在屏幕上******//
void stuatom::show()
{
cout.setf(ios::left);
cout.width(6);
cout<<""<<id<<"";
cout.width(8);
cout<<name;
cout.width(10);
cout<<sex;
cout.width(9);
cout<<math;
cout.width(9);
cout<<eng;
cout.width(11);
cout<<comp;
cout.width(10);
cout<<totll<<aver<<endl;
}
//**************输入学生的数据***********************//
void student::input()
{
int n;
cout<<endl<<"输入将要录入的学生数目:";
cin>>n;
int j;
//通过循环输入要求输入学生个数的学生的数据。
for(j=0; j<n; j++)
{
cout<<"输入学生信息"<<j<<endl;
ob[j].setup();
}
this->stulen=n;//学生个数赋值
//学生数据显示格式
system("cls");
cout<<endl<<"-----------------------------学生信息表------------------------------------"<<endl;
cout<<endl<<"学号姓名性别数学英语计算机总分平均分"<<endl;
//通过循环输出所有学生数据。
for(j=0; j<n; j++)
{
ob[j].show();
}
cout<<endl;
cout<<"是否保存?(Y/N):";
char Y;
cin>>Y;
system("cls");
}
//**************按照一定格式显示所要查询学生的信息。**************//
void student::Query()
{
int x, i;
cout<<endl<<"输入要查询学生的学号:";
cin>>x;
cout<<endl<<"学号姓名性别数学英语计算机总分平均分"<<endl;
for(i=0;i<=this->stulen;i++)
{ if(x==ob[i].id)
{
cout.setf(ios::left);
cout.width(6);
cout<<""<<ob[i].id<<"";
cout.width(8);
cout<<ob[i].name;
cout.width(10);
cout<<ob[i].sex;
cout.width(9);
cout<<ob[i].math;
cout.width(9);
cout<<ob[i].eng;
cout.width(11);
cout<<ob[i].comp;
cout.width(10);
cout<<ob[i].totll<<ob[i].aver<<endl;
}
}
getchar();
}
//*******************保存学生数据**************************//
void student::save()
{
int i;
ofstream outfile;
outfile.open("list.txt",ios::trunc);
if(!outfile)
{
cout<<"Cannot open output file!\n,";
}
//通过循环把所有的学生数据保存在list.txt里边。
for(i=0; i<this->stulen; i++)
{
outfile<<ob[i].id<<""<<ob[i].name<<""<<ob[i].sex<<""<<
ob[i].math<<""<<ob[i].eng<<""<<ob[i].comp<<""<<ob[i].totll<<""<<ob[i].aver<<endl;
}
outfile.close();
}
//*************显示所有学生数据*********************//
void student::read()
{
int i;
system("cls");
cout<<endl<<"-----------------------------学生信息表------------------------------------"<<endl;
cout<<endl<<"学号姓名性别数学英语计算机总分平均分"<<endl;
for(i=0; i<this->stulen; i++)
{
ob[i].show();
}
getchar();
}
//*******************一个学生的数据****************//
void student::add()
{
int i, d=this->stulen;
cout<<"输入要添加学生的信息:"<<endl;
ob[d].setup();
cout<<endl<<"-----------------------------学生信息表------------------------------------"<<endl;
cout<<endl<<"学号姓名性别数学英语计算机总分平均分"<<endl;
for(i=0; i<=d; i++)
{
ob[i].show();
}
ofstream fout("list.txt",ios::app);
if(!fout)
{
cout<<"Cannot open output file!\n,";
}
//把添加的学生数据添加到list.txt里边去。
fout<<ob[d].id<<""<<ob[d].name<<""<<ob[d].sex<<""<<
ob[d].math<<""<<ob[d].eng<<""<<ob[d].comp<<""<<ob[d].totll<<""<<ob[d].aver<<endl;
fout.close();
getchar();
}
//*********************删除指定名字学生的数据*******************//
void student::del()
{
int i,p; char x[8];
cout<<"输入要删除学生名字:"<<endl;
cin>>x;
//通过for循环查找要删除学生的姓名
for(i=0; i<stulen; i++)
{
if(strcmp(ob[i].name,x)==0)
{
p=i;
cout<<endl<<"学号姓名性别数学英语计算机总成绩平均成绩"<<endl;
cout<<ob[i].id<<""<<ob[i].name<<""<<ob[i].sex<<""<<ob[i].math<<""<<ob[i].eng<<""<<ob[i].comp<<""<<ob[i].totll<<""<<ob[i].aver<<endl;
break;
}
else
continue;
}
cout<<endl<<"-----------------------------学生信息表------------------------------------"<<endl;
cout<<endl<<"学号姓名性别数学英语计算机总分平均分"<<endl;
//删除了之后,应该把后面的数据往前移,把要删除的数据覆盖,并且学生长度减1
stulen--;
for(i;i<stulen;i++)
{
ob[i]=ob[i+1];
}
this->read();
cout<<"删除成功!"<<endl;
getchar();
}
//***********把学生成绩排序******************//
void student::order()
{
int k,j;
float t; char n[20];
//排序算法。
for(j= 0; j<=(2-1); j++)
{
for(k=1; k<=(2-j); k++)
{
if(ob[k].totll< ob[k+ 1].totll)
{
t= ob[k].totll;
ob[k].totll= ob[k+1].totll;
ob[k+1].totll= t;
strcpy(n, ob[k].name);
strcpy(ob[k].name, ob[k+1].name);
strcpy(ob[k+1].name, n);
}
cout<<"成绩排名:"<<endl;
cout<<"姓名总成绩名次"<<endl;
for(k=0; k<=stulen; k++)
{
cout<<"";
cout.setf(ios::left);
cout.width(9);
cout<<ob[k].name;
cout.width(9);
cout<<ob[k].totll<<k<<endl;
}
getchar();
}
}
}
//********************选择菜单。*****************//
void menu()
{
cout<<"\n\n";
cout<<"------------------学生成绩系统-----------------"<<endl<<endl;
cout<<"\t\t1.录入与保存学生信息.\n";
cout<<"\t\t2.读取学生信息.\n";
cout<<"\t\t3.删除学生信息.\n";
cout<<"\t\t4.追加学生信息.\n";
cout<<"\t\t5.查询学生信息.\n";
cout<<"\t\t6.显示成绩名次.\n";
cout<<"\t\t7.退出系统......\n\n\n";
cout<<"\t\t请选择功能项:";
}
//---------------------------------------------------------------------------------------
void main()
{
student a;
while(1)
{
int SEL;
system("cls");
menu();
cin>>SEL;
switch(SEL)
{
case 1:
system("cls"); a.input();a.save();break;
case 2:
system("cls"); a.read(); break;
case 3:
system("cls"); a.del(); break;
case 4:
system("cls"); a.add();break;
case 5:
system("cls"); a.Query();break;
case 6:
system("cls"); a.order();break;
case 7:
cout<<endl<<"按任意键退出...."<<endl;
getchar();
exit(0);
default:
cout<<"Bad input!!\n";
break;
}
}
}
好了,文章到这里就结束啦,如果本次分享的java管理系统源代码和java程序问题对您有所帮助,还望关注下本站哦!