数据结构课程设计报告.docx

上传人:b****1 文档编号:15141640 上传时间:2023-07-01 格式:DOCX 页数:23 大小:118.02KB
下载 相关 举报
数据结构课程设计报告.docx_第1页
第1页 / 共23页
数据结构课程设计报告.docx_第2页
第2页 / 共23页
数据结构课程设计报告.docx_第3页
第3页 / 共23页
数据结构课程设计报告.docx_第4页
第4页 / 共23页
数据结构课程设计报告.docx_第5页
第5页 / 共23页
数据结构课程设计报告.docx_第6页
第6页 / 共23页
数据结构课程设计报告.docx_第7页
第7页 / 共23页
数据结构课程设计报告.docx_第8页
第8页 / 共23页
数据结构课程设计报告.docx_第9页
第9页 / 共23页
数据结构课程设计报告.docx_第10页
第10页 / 共23页
数据结构课程设计报告.docx_第11页
第11页 / 共23页
数据结构课程设计报告.docx_第12页
第12页 / 共23页
数据结构课程设计报告.docx_第13页
第13页 / 共23页
数据结构课程设计报告.docx_第14页
第14页 / 共23页
数据结构课程设计报告.docx_第15页
第15页 / 共23页
数据结构课程设计报告.docx_第16页
第16页 / 共23页
数据结构课程设计报告.docx_第17页
第17页 / 共23页
数据结构课程设计报告.docx_第18页
第18页 / 共23页
数据结构课程设计报告.docx_第19页
第19页 / 共23页
数据结构课程设计报告.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

数据结构课程设计报告.docx

《数据结构课程设计报告.docx》由会员分享,可在线阅读,更多相关《数据结构课程设计报告.docx(23页珍藏版)》请在冰点文库上搜索。

数据结构课程设计报告.docx

数据结构课程设计报告

数据结构课程设计报告

班级:

____软件121_____________

姓名:

___________________

指导教师:

__________________

成绩:

__________________________

信息工程学院

2014年1月9日

 

题目1

1.需求分析

简单的员工管理系统

每一个员工的信息包括:

编号、姓名、性别、出生年月、学历、职务、电话、住址等,系统的功能包括:

(1)查询:

按特定条件查找员工。

(2)修改:

按编号对某个员工的某项信息进行修改

(3)排序:

按特定条件对所有员工的信息进行排序

(4)插入:

按编号删除已离职的员工的信息。

(5)删除:

按编号删除已离职的员工信息。

2.概要设计

java.io.Serializable//实现可比较和序列化接口

publicFriend(Stringname,Stringcode)//构造方法

publicintcompareTo(Friendf)//比较两个对象大小,实现Comparable接口

publicObject[]toArray()//将对象的两个成员变量保存在对象数组中

publicStaffManagementSystem(Stringfilename)//构造图形用户界面

publicStaffManagementSystem()//员工管理系统

privatevoidreadFromFile()//从指定文件中读取已有对象

privatevoidgetFamilyName()//JList添加其中所有姓氏

publicvoidvalueChanged(ListSelectionEvente)//列表框的选择事件处理方法

publicvoidactionPerformed(ActionEvente)//单击事件处理方法

publicvoidwindowClosing(WindowEvente)//关闭窗口事件处理方法

3.详细设计

//Friend.java

publicclassFriendimplementsjava.lang.Comparable,java.io.Serializable//实现可比较和序列化接口

{

privateStringname;//姓名

privateStringcode;//编号

publicFriend(Stringname,Stringcode)//构造方法

{

this.name=name;

this.code=code;

}

publicStringgetName()//获得姓名

{

returnthis.name;

}

publicStringgetcode()//获得电话号码

{

returnthis.code;

}

publicStringtoString()

{

return"("+this.name+","+this.code+")";

}

publicintcompareTo(Friendf)//比较两个对象大小,实现Comparable接口

{//指定排序次序

if(!

this.name.equals(f.name))

returnpareTo(f.name);//两人以姓名为序

else

returnpareTo(f.code);//同一人以电话号码为序

}

publicObject[]toArray()//将对象的两个成员变量保存在对象数组中

{

Object[]vars=newObject[2];

vars[0]=this.name;

vars[1]=this.code;

returnvars;

}

}

//StaffManagementSystem.java

importjava.util.*;

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.*;

importjavax.swing.event.*;

importjavax.swing.table.*;

importjava.io.*;

publicclassStaffManagementSystemextendsJFrameimplementsListSelectionListener,ActionListener,WindowListener

{

privateStringfilename;//文件名

privateTreeSettbook;//使用一个树集合存储多个Friend对象

privateJListlist;//列表框

privateDefaultListModellistModel;//默认列表框模型

privateJTabletable;//表格组件

privateDefaultTableModeltableModel;//默认表格模型

privateJComboBoxcombobox_name;//姓名组合框

privateDefaultComboBoxModelcomboModel;//组合框模型,选择姓氏

privateJTextFieldtext_code;//编号文本行

publicStaffManagementSystem(Stringfilename)//构造图形用户界面

{

super("员工管理系统");

this.setBounds(300,300,450,300);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.addWindowListener(this);//注册窗口事件监听器

JSplitPanesplit_h=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT);

//水平分割窗格

split_h.setDividerLocation(40);//设置垂直分隔条的位置

this.getContentPane().add(split_h);

//初始化一个容器,在容器上添加字符串组(无该语句则白屏)

JSplitPanesplit_v=newJSplitPane(JSplitPane.VERTICAL_SPLIT);

//垂直分割窗格

split_v.setDividerLocation(180);//设置水平分隔条的位置

this.filename=filename;

tbook=newTreeSet();

this.readFromFile();//从指定文件中读取已有对象信息

this.listModel=newDefaultListModel();//默认列表框模型

this.listModel.addElement("姓氏");

this.list=newJList(listModel);//创建列表框

this.list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);//设置单选模式,默认为多选

this.list.addListSelectionListener(this);//列表框注册选择事件监听器

split_h.add(newJScrollPane(this.list));//添加在滚动窗格中

split_h.add(split_v);

String[]columns={"姓名","编号","性别","诞日","学历","职务","电话","住址"};//表格各列的中文标题

this.tableModel=newDefaultTableModel(columns,0);

//默认表格模型,指定列标题,0行

this.table=newJTable(tableModel);//创建空表格,有列标题

this.list.setSelectedIndex(0);//选中列表框第一项,执行valueChanged()方法

split_v.add(newJScrollPane(table));

//以下面板包括组合框、文本行和添加、删除、查找等按钮

JPanelfriendpanel=newJPanel(newGridLayout(2,1));

//将下框的内容分成2行1列

split_v.add(friendpanel);

JPanelpanels[]={newJPanel(),newJPanel()};

for(inti=0;i

friendpanel.add(panels[i]);

panels[0].add(newJLabel(columns[0]));

boModel=newDefaultComboBoxModel();//默认组合框模型

combobox_name=newJComboBox(boModel);

combobox_name.setEditable(true);

panels[0].add(combobox_name);

panels[0].add(newJLabel(columns[1]));

this.text_code=newJTextField("1",12);//编号长度

panels[0].add(text_code);

this.getFamilyName();//列表框和组合框添加其中所有姓氏

Stringbuttonstr[]={"添加","删除","按编号查找"};

JButtonbuttons[]=newJButton[buttonstr.length];

for(inti=0;i

{

buttons[i]=newJButton(buttonstr[i]);

panels[1].add(buttons[i]);

buttons[i].addActionListener(this);

}

this.setVisible(true);

}

publicStaffManagementSystem()

{

this("friends.dat");//指定默认文件名

}

privatevoidreadFromFile()//从指定文件中读取已有对象

{

try

{

FileInputStreamfin=newFileInputStream(this.filename);//文件字节输入流

ObjectInputStreamobjin=newObjectInputStream(fin);//对象字节输入流

while(true)//输入流未结束时

try

{

tbook.add((Friend)objin.readObject());//读取一个对象添加到系统

}

catch(Exceptione)//捕获ClassNotFoundException和EOFException异常

{

break;

}

objin.close();//先关闭对象流

fin.close();//再关闭文件流

}

catch(IOExceptionioe){}//指定文件不存在时,表格为空

}

privatevoidgetFamilyName()//JList添加其中所有姓氏

{

if(!

tbook.isEmpty())

{

Iteratorit=tbook.iterator();//返回一个迭代器对象

while(it.hasNext())//若有后继元素,使用迭代器遍历集合

{

Friendf=(Friend)it.next();//返回后继元素

Stringfamilyname=f.getName().charAt(0)+"";//获得姓氏

if(!

this.listModel.contains(familyname))

{

this.listModel.addElement(familyname);//列表框模型添加不重复数据项

boModel.addElement(familyname);//组合框模型添加不重复数据项

}

}

}

}

publicvoidvalueChanged(ListSelectionEvente)//列表框的选择事件处理方法

{

Stringfamilyname=(String)list.getSelectedValue();

//返回列表框选中数据项对象

if(!

tbook.isEmpty()&&familyname!

=null&&familyname!

="")

//以选中姓氏更新表格

{

for(inti=this.tableModel.getRowCount()-1;i>=0;i--)//清空表格

this.tableModel.removeRow(i);

Iteratorit=tbook.iterator();

while(it.hasNext())//在系统中查找指定姓氏

{

Friendf=(Friend)it.next();

if(familyname=="姓氏"||f.getName().charAt(0)==familyname.charAt(0))

this.tableModel.addRow(f.toArray());//表格添加一行,参数数组指定各列值

}

}

}

publicvoidactionPerformed(ActionEvente)//单击事件处理方法

{

if(e.getActionCommand().equals("添加"))//单击添加按钮

{

Stringname=(String)combobox_name.getSelectedItem();

Stringcode=text_code.getText();

Friendf=newFriend(name,code);

if(!

name.equals("")&&!

tbook.contains(f))

//不能插入姓名空串和重复对象

{

tbook.add(f);//添加对象,TreeSet不插入重复元素,没提示也不抛出异常

Stringfamilyname=name.charAt(0)+"";//返回姓名的第一个字符

if(list.getSelectedValue().equals(familyname))

tableModel.addRow(f.toArray());

else

{

if(!

listModel.contains(familyname))//列表框中添加不重复元素

{

listModel.addElement(familyname);

comboModel.addElement(familyname);

}

list.setSelectedValue(familyname,true);//设置列表框选中项

}

}

else

JOptionPane.showMessageDialog(this,"不能添加姓名空串或重复对象"+f.toString());

}

if(e.getActionCommand().equals("删除"))

{

if(tbook.isEmpty())

JOptionPane.showMessageDialog(this,"表格空,不能删除数据项。

");

else

{

inti=table.getSelectedRow();//表格当前选中行号

if(i==-1)

JOptionPane.showMessageDialog(this,"请选择数据项。

");

else

{

Stringname=(String)table.getValueAt(i,0);

intyes=JOptionPane.showConfirmDialog(null,"删除\""+name+"\"行?

");

//确认对话框包括Yes和No按钮

if(yes==0)//单击确认对话框的Yes按钮

{

Stringcode=(String)table.getValueAt(i,1);

tbook.remove(newFriend(name,code));//删除对象

tableModel.removeRow(i);//表格中删除一行

listModel.removeElement(name.charAt(0)+"");//列表框中删除指定姓氏

comboModel.removeElement(name.charAt(0)+"");

}

}

}

}

if(!

tbook.isEmpty()&&e.getActionCommand().equals("按编号查找"))

{//查找编号,结果显示在表格中

Friendfind=null;

Iteratorit=tbook.iterator();

while(find==null&&it.hasNext())

{

Friendf=(Friend)it.next();

if(f.getcode().equals(text_code.getText()))//比较编号字符串

find=f;

}

if(find!

=null)//若查找成功

{

for(inti=tableModel.getRowCount()-1;i>=0;i--)//清空表格

this.tableModel.removeRow(i);

this.tableModel.addRow(find.toArray());

}

elseJOptionPane.showMessageDialog(this,"未查找到满足条件的数据!

");

}

}

publicvoidwindowClosing(WindowEvente)//关闭窗口事件处理方法

{

try//将其中所有对象写入指定文件

{//指定文件不存在时,表格为空创建新文件

FileOutputStreamfout=newFileOutputStream(this.filename);

//文件字节输出流

ObjectOutputStreamobjout=newObjectOutputStream(fout);

//对象字节输出流

if(!

tbook.isEmpty())

{

Iteratorit=tbook.iterator();

while(it.hasNext())

objout.writeObject((Friend)it.next());//写入一个对象

}

objout.close();

fout.close();

}

catch(IOExceptionioe){}

}

publicvoidwindowOpened(WindowEvente){}

publicvoidwindowActivated(WindowEvente){}

publicvoidwindowDeactivated(WindowEvente){}

publicvoidwindowClosed(WindowEvente){}

publicvoidwindowIconified(WindowEvente){}

publicvoidwindowDeiconified(WindowEvente){}

publicstaticvoidmain(Stringargs[])

{

newStaffManagementSystem();//默认文件名为"frindes.dat"

}

}

4.调试分析

(1)调试过程中问题:

主要是一些框架结构的定义以及一些语法上的应用,通过查找API可以详细知道其意思,并应用到程序中。

(2)需要的改进:

A、实现检查电话号码的位数。

B、增加员工管理系统的修改功能。

C、双击表格一列,能够修改,响应事件保存修改内容。

(3)经验和体会:

这次编写的代码主要是修改别人的代码,在这个过程中虽然没有完全做到自己编写,但是也认真看了,说实话很多都不怎么懂,感觉好多要记忆的东西,比如一些框架的定义,操作动作的语法定义。

经过这几天的练习,表示在编程方面还是要花上很多心思和时间的。

5.测试结果

题目2

1.需求分析

求图的最短路径问题

2.概要设计

typedefstruct{}MGraph;//定义邻接矩阵结构体

voidShortestPath_DIJ(MGraphG,intv0,PathMatrix&P,ShortPathTable&D)//说明最短路径结构

intLocateVex(MGraphG,charu)//定位邻接矩阵各个顶点是否有误

voidCreateMGraph(MGraph&G)//建立邻接矩阵

3.详细设计

#include

#include

#defineINT_MAX2147483647

#defineINFINITYINT_MAX

#defineFALSE0

#defineTRUE1

#defineNumVertices6//图中最大顶点个数

typedefintPathMatrix[NumVertices][NumVertices];//最短路径数组

typedefintShortPathTable[NumVertices];//最短路径长度

typedefintAdjMatrix[NumVertices][NumVertices];

typedefcharVertexType;

typedefstruct{

VertexTypevexs[NumVertices];

AdjMatrixarcs;//邻接矩阵

intvexnum,arcnum;

}MGraph;

intL

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2