学生课程设计设计案例.doc_第1页
学生课程设计设计案例.doc_第2页
学生课程设计设计案例.doc_第3页
学生课程设计设计案例.doc_第4页
学生课程设计设计案例.doc_第5页
已阅读5页,还剩32页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

学生课程设计设计案例编写程序实现对学生四门课程的考试成绩进行管理的功能。 其功能包括:1. 增加学生成绩记录2. 修改学生成绩记录3. 删除学生成绩记录4. 学生成绩记录列表5. 成绩记录写入文件6. 学生成绩记录文件读取7. 按学号排序和按名称搜索。程序界面要求:仿 windows 窗口风格以菜单方式驱动,并每个功能都在字符窗口中实现。 题目分析: 程序的几个需要考虑的问题: 1 、一个实用的应用程序必须提供一个相对比较简单、清晰的操作界面。目前大多数在 windows 中实现的应用系统都可以借助其开发接口很简单的产生标准的窗口界面。然而这样的界面风格在 Dos 中实现并非一件简单的任务,我们必须清晰的规划出屏幕和窗口的规格以及和应用结合的接口。 2 、我们面临的应用程序不是简单的实现一个算法的程序,是一个针对学生成绩记录的多功能的小型系统,而且扩充的可能性非常大,需要我们按照自顶向下,逐步求精的设计思想先从功能上将系统划分为多个模块,再从模块细节来把握和分解系统,降低其复杂度直至可以编写程序。 3 、程序完成的是对学生成绩记录的多种独立的操作,需要进行功能规划。总体上划分为三个功能部分:( 1 )文件接口功能部分:完成学生成绩记录的文件读取和写入。( 2 )学生记录的操作功能:完成向记录集添加成绩记录、删除成绩记录、修改成绩记录等功能。( 3 )察看学生记录,完成学生成绩记录集的排序、搜索、列表等功能。 4 、界面组成设计分析:( 1 )整个屏幕用背景覆盖,称为桌面( 2 )屏幕最顶一行用于显示主菜单行。( 3 )最底一行用于显示提示行。( 4 )子菜单由菜单盒显示。( 5 )单一的输入,使用单行输入框。( 6 )提示信息使用信息提示框显示。( 7 )记录信息的输入使用录入框实现。 结构分析1 、功能模块的划分:划分的情况见下图 2 、软件运行模式:软件的运行采用菜单驱动,选取菜单项后,启动相关功能,进入每个功能后,都通过独立的窗口执行相应流程。功能执行退出后,由主菜单继续获得控制权。 3 、程序单元结构设计: 序号 单元名称 单元头文件 单元实现文件 单元说明 1 stmain stmain.h stmain.c 全局变量的定义和 main 主控函数,菜单及模块调度执行函数 2 student student.h student.c 学生成绩结构定义和记录基本运算函数 3 basefile basefile.h basefile.c 学生成绩结构的文件接口函数 4 basemenu basemenu.h basemenu.c 菜单的构造、控制基础功能函数 5 basewin basewin.h basewin.c 所有类型界面及其窗口绘制控制函数 6 menudo menudo.h menudo.c 对应菜单项直接驱动的功能模块函数 4 、各单元主要数据结构、全局变量与处理函数: (1)stmain 单元 名称 类型 原型 说明 studentcount 全局变量 int studentcount=0 ; 当前学生记录的个数 studentarr 全局变量 STUDENT studentarr200 ; 存储当前学生成绩记录的总缓冲区,实际记录的个数在变量 studentcount中 winbuf 全局变量 char winbuf4096 ; 保存在桌面中的画面区域的缓冲区 menuareabuf 全局变量 char menuareabuf34096 ; 保存子菜单画面区域的缓冲区 menu 全局变量 MENUITEMNODE *menu ; 第一项菜单结构节点的指针 pcurrent 全局变量 MENUITEMNODE *pcurrent ; 当前菜单结构节点的指针 selectedid 全局变量 int selectedid ; 当前菜单项选取后的返回 id initmenu 函数 int initmenu(void) ; 构造系统菜单结构的函数 dealselect 函数 int dealselect(void); 依据 selectedid,执行模块调度的函数 (2)student 单元名称 类型 原型 说明 STUDENT 学生成绩结构类型 typedef struct _student char stid20; char name20; float mathscore; float englishscore; float computerscore; float politicsscore; STUDENT ; 学生成绩的结构类型,是系统数据处理的基础 addstudent 函数 void addstudent( STUDENT *pliststudent , int stcount , STUDENT *pstudent ) ; 向 pliststudent结构数组中添加一个学生记录pstudent,结构数组中有效记录个数通过stcount传递 findstudent 函数 STUDENT *findstudent( STUDENT *pliststudent , int stcount , char *stid ) ; 在 pliststudent结构数组中查找学号为stid的记录,结构数组有效记录个数通过stcount传递。返回查找的结果,成功返回找到记录的指针,失败返回NULL modifystudent 函数 void modifystudent( STUDENT *pliststudent , int stcount , char *stid , STUDENT *newpstudent ) ; 将 pliststudent结构数组中学号为stid的记录,替换为新记录 newpstudent 。 结构数组有效记录个数通过 stcount传递。 deletestudent 函数 void deletestudent( STUDENT *pliststudent , int stcount , char *stid ) ; 将 pliststudent结构数组中学号为stid的记录删除掉。结构数组有效记录个数通过stcount传递。 (3)basefile 单元 名称 类型 原型 说明 readfiletobuf 函数 int readfiletobuf( char *readfilename ,STUDENT *pliststudent ,int *readcount) ; 从结构文件 readfilename中读取学生成绩结构到结构数组pliststudent中,读取的记录个数通过变量readcount输出 writebuftofile 函数 int writebuftofile( char *writefilename ,STUDENT *pliststudent ,int stcount) ; 将结构数组 pliststudent中的学生成绩记录写入结构文件 writefilename ,写入记录的个数在变量 stcount 中 (4) basemenu 单元 名称 类型 原型 说明 MENUITEMREC 菜单项结构类型 typedef struct menuitemrec int itemid; char itemtext20; int level; MENUITEMREC; itemid菜单项标识号 itemtext菜单项显示文本 level菜单项级别 MENUITEMNODE PMENUITEMNODE 菜单项节点结构类型 菜单项节点结构指针类型 typedef struct menuitemnode MENUITEMREC item ; int x , y , w ; struct menuitemnode *pprev ; struct menuitemnode *pnext ; struct menuitemnode *pchild ; struct menuitemnode *pparent ; MENUITEMNODE, *PMENUITEMNODE ; item菜单项信息 x,y菜单项屏幕位置 w菜单项宽度 pprev前项指针 pnext后项指针 pchild子菜首项指针 pparent父级菜单项指针 makemenuitem 函数 MENUITEMNODE *makemenuitem( int id , char *text , int level ); 构造菜单项记录并返回其指针 id:设置的菜单项标号 text:设置的菜单项文字 level:菜单项级别 addnext 函数 MENUITEMNODE *addnext( MENUITEMNODE *current , MENUITEMNODE *next ) ; 向当前菜单节点 current中加入同级别相邻下一个节点next addchild 函数 MENUITEMNODE *addchild( MENUITEMNODE *current , MENUITEMNODE *child ); 向当前菜单节点 current中加入下一级第一节点child initmenuposition 函数 void initmenuposition( MENUITEMNODE *menu ) ; 初始化菜单中 menu所有节点菜单项的屏幕位置和宽度 showmenu 函数 void showmenu( MENUITEMNODE *menuptr ) ; 显示主菜单条 menuptr在屏幕顶行,并激活第一项菜单 menuselect 函数 int menuselect(void); 激活菜单控制,返回选择的菜单项的标识号 (5) basewin 单元 名称 类型 原型 说明 editbox 编辑框结构类型 typedef struct _EDITBOX char *label ; int x,y ; int labelwidth ; int editwidth ; editstyle edittype ; char *strptr ; float *floatptr ; editbox ; 自定义控制编辑框输入文本,转换存到字符串或实数中的结构 label:显示的提示信息 x,y:编辑框的屏幕位置 labelwidth:提示显示的宽度 editwidth:编辑框的宽度 edittype:编辑目标的类型 strptr:编辑字符串存入的目标 floatptr:编辑实数存入的目标 pusharea 函数 void pusharea( int left , int top , int w , int h , char *buf ) ; 保存一个矩形屏幕区域到缓冲区 buf中,保存区域的左上角为(left,top),宽高为w,h, poparea 函数 void poparea( int left , int top , int w , int h , char *buf ) ; 恢复保存的缓冲区 buf到一个矩形屏幕区域,恢复左上角为(left,top),宽高为w,h drawdesktop 函数 void drawdesktop(void); 绘制桌面区域 msg 函数 int messagebox( char *msg ) ; 在屏幕中显示一个消息框 msg:要显示的消息字符串 inputbox 函数 int inputbox( char *lable , char *savestr ) ; 输入单行字符串的输入窗口 label:提示字符串 savestr:输入后保存的目标字符串 inputeditbox 函数 int inputeditbox( editbox *ebptr , int inputcount ) ; 用于在编辑窗口中控制多栏编辑输入 ebptr:多栏编辑结构指针 inputcount:输入栏位的数量 getkey 函数 int getkey(void) ; 得到键盘的输入,包括功能键及组合键 返回按键的键值 inputstudent 函数 int inputstudent( STUDENT *ptrst ) ; 在多栏输入框中编辑学生成绩记录 ptrst:学生成绩记录指针 (6)menudo 单元 名称 类型 原型 说明 loadstudent 函数 void loadstudent(void) ; 执行从输入的文件名中调入学生成绩记录到全局数组的模块函数 writestudent 函数 void writestudent(void) ; 执行将学生成绩记录全局数组写入输入的文件名的模块函数 liststudent 函数 void liststudent(void) ; 执行将学生成绩记录全局数组进行窗口列表显示的控制模块函数 appendstudent 函数 void appendstudent(void) ; 执行添加学生成绩并编辑和记录到全局数组的模块函数 editstudent 函数 void editstudent(void) ; 执行编辑修改指定学号的学生成绩记录的模块函数 erasestudent 函数 void erasestudent(void); 执行删除指定学号的学生成绩记录的模块函数 5 、工程文件: 建立工程文件 STMAN.PRJ ,该文件支持对单元的集成编译和连接。下图显示了工程文件窗口的主要的屏幕画面。 STMAN 工程文件同各个单元源文件之间的关系如下: 源程序: 1 、 stmain 单元头文件 stmain.h 源程序 #ifndef _STMAIN_H #define _STMAIN_H #include student.h #include basemenu.h STUDENT studentarr200; int studentcount=0; char winbuf4096; char menuareabuf34096; MENUITEMNODE *menu,*pcurrent; int selectedid; int initmenu(void); int dealselect(void); #endif 2 、 stmain 单元实现文件 stmain.c 源程序 #include basemenu.h #include basewin.h #include menudo.h #include stmain.h #include #include #include void main() int key; clrscr(); drawdesktop(); initmenu(); showmenu(menu); while (selectedid=menuselect()!=QUITID) dealselect(); setdefaultcolor(); clrscr(); int initmenu(void) menu = addnext( addchild(makemenuitem(1,File,0), addnext(makemenuitem(101,Load,1), addnext(makemenuitem(102,Save,1), makemenuitem(0,Quit,1) ) ), addnext( addchild(makemenuitem(2,Edit,0), addnext(makemenuitem(201,Add,1), addnext(makemenuitem(202,Edit,1), makemenuitem(203,Delete,1) ) ), addchild(makemenuitem(3,View,0), addnext(makemenuitem(301,Sort,1), addnext(makemenuitem(302,Search,1), makemenuitem(303,List,1) ) ) ) ); initmenuposition(menu); pcurrent = menu; return 0; int dealselect(void) switch (selectedid) case 101: /Load loadstudent(); break; case 102: /Save writestudent(); break; case 201: /Add appendstudent(); break; case 202: /Edit editstudent(); break; case 203: /Delete erasestudent(); break; case 301: /Sort break; case 302: /Search break; case 303: /List liststudent(); break; return 0; 3 、 student 单元头文件 student.h 源程序 #ifndef _STUDENT_H #define _STUDENT_H typedef struct _student char stid20; char name20; float mathscore; float englishscore; float computerscore; float politicsscore; STUDENT; void addstudent(STUDENT *pliststudent,int stcount,STUDENT *pstudent); STUDENT *findstudent(STUDENT *pliststudent,int stcount,char *stid); void modifystudent(STUDENT *pliststudent,int stcount, char *stid,STUDENT *newpstudent); void deletestudent(STUDENT *pliststudent,int stcount,char *stid); #endif 4 、 student 单元实现文件 student.c 源程序 #include student.h #include #include void addstudent(STUDENT *pliststudent,int stcount,STUDENT *pstudent) pliststudentstcount=*pstudent; STUDENT *findstudent(STUDENT *pliststudent,int stcount,char *stid) int i; STUDENT *stptr; stptr = pliststudent; for (i=0;istid,stid)=0) return stptr; stptr+; return NULL; void modifystudent(STUDENT *pliststudent,int stcount, char *stid,STUDENT *newpstudent) STUDENT *stptr; if (stptr=findstudent(pliststudent,stcount,stid)=NULL) return; *stptr=*newpstudent; void deletestudent(STUDENT *pliststudent,int stcount,char *stid) STUDENT *stptr; STUDENT *nextstptr; int copycount; int i; if (stptr=findstudent(pliststudent,stcount,stid)=NULL) return; nextstptr=stptr; nextstptr+; copycount=stcount-(stptr-pliststudent)-1; for (i=copycount;i0;i-) *stptr=*nextstptr; nextstptr+; 5 、 basefile 单元头文件 basefile.h 源程序 #ifndef _BASEFILE_H #define _BASEFILE_H #include student.h int readfiletobuf(char *readfilename,STUDENT *pliststudent,int *readcount); int writebuftofile(char *writefilename,STUDENT *pliststudent,int stcount); #endif 6 、 basefile 单元实现文件 basefile.c 源程序 #include #include basefile.h #include student.h #define STUSIZE (sizeof(STUDENT) int readfiletobuf(char *filename,STUDENT *pliststudent,int *readcount) FILE *rf; STUDENT sbuf; int readbytes; int studentcount; if (rf = fopen(filename, rb)= NULL) /fprintf(stderr, Cannot open input file.n); return 1; studentcount=0; while (!feof(rf) readbytes=fread(&sbuf,STUSIZE,1,rf); if (readbytes=1) addstudent(pliststudent,studentcount,&sbuf); studentcount+; ; fclose(rf); *readcount=studentcount; return 0; int writebuftofile(char *filename,STUDENT *pliststudent,int stcount) FILE *wf; if (wf = fopen(filename, wb) = NULL) /fprintf(stderr, Cannot open output file.n); return 1; fwrite(pliststudent,STUSIZE,stcount,wf); fclose(wf); return 0; 7 、 basemenu 单元头文件 basemenu.h 源程序 #ifndef _BASEMENU_H #define _BASEMENU_H #define QUITID 0 #define OPMAINMENU 1 #define OPSUBMENU 2 typedef struct menuitemrec int itemid; char itemtext20; int level; MENUITEMREC; typedef struct menuitemnode MENUITEMREC item; /level =0 mines mainmenubar int x,y,w; struct menuitemnode *pprev; struct menuitemnode *pnext; struct menuitemnode *pchild; struct menuitemnode *pparent; MENUITEMNODE,*PMENUITEMNODE; extern MENUITEMNODE *menu,*pcurrent; MENUITEMNODE *makemenuitem(int id,char *text,int level); MENUITEMNODE *addnext(MENUITEMNODE *current,MENUITEMNODE *next); MENUITEMNODE *addchild(MENUITEMNODE *current, MENUITEMNODE *child); void initmenuposition(MENUITEMNODE *menu); void showmenu(MENUITEMNODE *menuptr); int menuselect(void); #endif 8 、 basemenu 单元实现文件 basemenu.c 源程序 #include basemenu.h #include basewin.h #include #include #include #include void initsubmenuposition(MENUITEMNODE *menuptr); void showmenuitem(MENUITEMNODE *menuptr,int actived); void popupmenuwindow(MENUITEMNODE *menuptr); void closemenuwindow(MENUITEMNODE *menuptr); void shiftmenutoleft(MENUITEMNODE *menuptr); void shiftmenutoright(MENUITEMNODE *menuptr); void shiftmenutoup(MENUITEMNODE *menuptr); void shiftmenutodown(MENUITEMNODE *menuptr); void showmenuitem(MENUITEMNODE *menuptr,int actived) if (menuptr=NULL) return; if (actived) setactivemenutextcolor(); else setmenutextcolor(); gotoxy(menuptr-x,menuptr-y); cprintf(%s,menuptr-item.itemtext); void showmenu(MENUITEMNODE *menuptr) int posmenu; char mstr81; MENUITEMNODE *menuitemptr; menuitemptr = menuptr; setmenutextcolor(); sprintf(mstr,%80s, ); gotoxy(1,1); cprintf(%s,mstr); while (menuitemptr!=NULL) gotoxy(menuitemptr-x,menuitemptr-y); cprintf(%s,menuitemptr-item.itemtext); menuitemptr=menuitemptr-pnext; ; setactivemenutextcolor(); gotoxy(menuptr-x,menuptr-y); cprintf(%s,menuptr-item.itemtext); void popupmenuwindow(MENUITEMNODE *menuptr) int menulevel; int subleft,subtop,subw,subh; MENUITEMNODE *menuitemptr; if (menuptr=NULL) return; if (menuptr-pchild)=NULL) return; menuitemptr = menuptr-pchild; pcurrent = menuitemptr; subh=0; while (menuitemptr!=NULL) subh+; menuitemptr = menuitemptr-pnext; ; menuitemptr = menuptr-pchild; menulevel = menuitemptr-item.level; subleft = menuitemptr-x-1; subtop = menuitemptr-y-1; subw = menuitemptr-w+2; subh+=2; pusharea(subleft,subtop,subw,subh,menuareabufmenulevel); drawwinframe(subleft,subtop,subw,subh); setmenutextcolor(); menuitemptr = menuptr-pchild; while (menuitemptr!=NULL) gotoxy(menuitemptr-x,menuitemptr-y); cprintf(%s,menuitemptr-item.itemtext); menuitemptr=menuitemptr-pnext; ; menuitemptr = menuptr-pchild; setactivemenutextcolor(); gotoxy(menuitemptr-x,menuitemptr-y); cprintf(%s,menuitemptr-item.itemtext); void closemenuwindow(MENUITEMNODE *menuptr) int menulevel; int subleft,subtop,subw,subh; MENUITEMNODE *parentitemptr,*menuitemptr; if (menuptr=NULL) return; if (menuptr-item.level=0) return; menuitemptr = menuptr; while (menuitemptr-pprev!=NULL) menuitemptr=menuitemptr-pprev; parentitemptr=menuitemptr-pparent; pcurrent = parentitemptr; subh=0; while (menuitemptr!=NULL) subh+; menuitemptr = menuitemptr-pnext; ; menuitemptr = parentitemptr-pchild; menulevel = menuitemptr-item.level; subleft = menuitemptr-x-1; subtop = menuitemptr-y-1; subw = menuitemptr-w+2; subh+=2; poparea(subleft,subtop,subw,subh,menuareabufmenulevel); void shiftmenutoleft(MENUITEMNODE *menuptr) if (menuptr=NULL) return; if (menuptr-item.level!=0) return; if (menuptr-pprev=NULL) pcurrent = menuptr; while (pcurrent-pnext)!=NULL) pcurrent = pcurrent-pnext; else pcurrent = menuptr-pprev; showmenuitem(menuptr,0); showmenuitem(pcurrent,1); void shiftmenutoright(MENUITEMNODE *menuptr) if (menuptr=NULL) return; if (menuptr-item.level!=0) return; if (menuptr-pnext=NULL) pcurrent = menuptr; while (pcurrent-pprev)!=NULL) pcurrent = pcurrent-pprev; else pcurrent = menuptr-pnext; showmenuitem(menuptr,0); showmenuitem(pcurrent,1); void shiftmenutoup(MENUITEMNODE *menuptr) if (menuptr=NULL) return; if (menuptr-item.level=0) return; if (menuptr-pprev=NULL) pcurrent = menuptr; while (pcurrent-pnext)!=NULL) pcurrent = pcurrent-pnext; else pcurrent = menuptr-pprev; showmenuitem(menuptr,0); showmenuitem(pcurrent,1); void shiftmenutodown(MENUITEMNODE *menuptr) if (menuptr=NULL) return; if (menuptr-item.level=0) return; if (menuptr-pnext=NULL) pcurrent = menuptr; while (pcurrent-pprev)!=NULL) pcurrent = pcurrent-pprev; else pcurrent = menuptr-pnext; showmenuitem(menuptr,0); showmenuitem(pcurrent,1); MENUITEMNODE *makemenuitem(int id,char *text,int level) MENUITEMNODE *miptr; miptr = (MENUITEMNODE *)malloc(sizeof(MENUITEMNODE); miptr-item.itemid=id; strcpy(miptr-item.itemtext,text); miptr-item.level=level; miptr-pprev=NULL; miptr-pnext=NULL; miptr-pchild=NULL; miptr-pparent=NULL; return miptr; MENUITEMNODE *addnext(MENUITEMNODE *current, MENUITEMNODE *next) current-pnext=next; next-pprev=current; return current; MENUITEMNODE *addchild(MENUITEMNODE *current,MENUITEMNODE *child) current-pchild = child; child-pparent=current; return current; void initmenuposition(MENUITEMNODE *menu) int position; MENUITEMNODE *menuptr; position=1; menuptr=menu; /init menuitems position of mainmenubar while (menuptr!=NULL) position+=3; menuptr-x =position; menuptr-y =1; menuptr-w =strlen(menuptr-item.itemtext); position+=menuptr-w; initsubmenuposition(menuptr); menuptr=menuptr-pnext; ; void initsubmenuposition(MENUITEMNODE *menuptr) int ix,iy,iw; MENUITEMNODE *itemptr; if (menuptr=NULL)|(menuptr-pchild)=NULL) return; iw=0; itemptr=menuptr-pchild; while (itemptr!=NULL) iw=max(iw,strlen(itemptr-item.itemtext); itemptr = itemptr-pnext; ; itemptr=menuptr-pchild; ix=menuptr-x+1; iy=menuptr-y+2; while (itemptr!=NULL) if (itemptr-pchild)!=NULL) initsubmenuposition(itemptr-pchild); itemptr-x = ix; itemptr-y = iy; itemptr-w = iw; iy+; itemptr=itemptr-pnext; int menuselect(void) int menustatus; int keypressed; int IsSeletedEnd; int retmenuid; _setcursortype(_NOCURSOR); menustatus = OPMAINMENU; IsSeletedEnd = 0; while (!IsSeletedEnd) keypressed = getkey(); if (keypressed=KEYQUIT) IsSeletedEnd=1; retmenuid=QUITID; continue; ; switch (menustatus) case OPMAINMENU: switch (keypressed) case KEYENTER: if (pcurrent-pchild)=NULL) IsSeletedEnd=1; retmenuid=pcurrent-item.itemid; continue; ; case KEYDOWN: if (pcurrent-pchild)!=NULL) popu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论