




已阅读5页,还剩28页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
沈阳理工大学面向对象课程设计 目目 录录 part i 1 需求分析1 2 算法基本原理.1 3 类设计.2 4 详细设计3 4.1 类的接口设计.4 4.2 类的实现.6 4.3 主函数设计.11 5 运行结果与分析13 5.1 程序运行结果.13 5.2 运行结果分析.15 part ii 1 类设计16 2 详细设计23 3 运行结果31 参考文献.31 沈阳理工大学面向对象课程设计 1 part i 1 需求分析需求分析 (1)实现年级管理(4个年级)、班级管理及学生信息管理,可以实现班级的 查询、添加、删除、修改,学生成绩的查询、添加、删除、修改等。 程序使用类的包含方法实现。 1)一个班最多30名学生,4门课程; 2)班级信息、学生成绩存放在数据文件中; 3)内存中数据组织建议采用stl容器。 设计班级类、学生类等,建立文件、输出文件内容、计算每个学生总分并进行总分 排序、查找各科最低分和最高分。 (2)设计一个student类,包含学生的基本信息:姓名、学号、四门课程(大 外、高数、模电、c+)的分数和总分数;stulist类用于实现学生成绩的查找、添 加、删除、修改;class类包含班级带的基本信息:年级、班级名称和所有学生; cllist类用于实现班级的查询、添加、删除、修改。 (3)用list链表容器存放多个学生的信息和多个班级的信息。使用容器的 sort()函数实现学生的总分排序。max()和min()分别实现查找各科的最高分 和最低分。 2 算法基本原理算法基本原理 一个年级包含多个班级,用list链表容器存放一个年级的所有班级, 用class类存放班级的所有学生,用cllist类的成员函数对班级进行查找、添加、删 除、修改。 (2)一个班级有很多学生(不超过30个),用student类存放学生信息, stulist类带的成员函数实现学生成绩的查找、添加、删除、修改,总分的排序,求 各科的最高分和最低分。 (3)学会stl标准模板库里德容器、迭代器、和算法的使用方法。本程序使 用list链表容器存放学生信息并进行相应的操作,如用push_back()函数进行添加操 作、用sort()函数进行排序,用erase()函数进行删除操作等。 (4)用文件file读取和输出学生信息和班级信息。 沈阳理工大学面向对象课程设计 2 3 类设计类设计 从上面的算法分析可以看到,本设计面临的计算问题的关键是学生信息和班级 信息的处理。可以定义一个学生类student显示学生的基本信息,然后定义一个学 生链表类stulist实现学生成绩的相关操作;又定义一个班级类class显示班级的基 本信息,最后定义一个班级链表类cllist实现班级的一些相应操作等。 从问题的需要来看,需要调用stl标准模板库里德一些函数如push_back()函数 进行添加操作、用sort()函数进行排序,用erase()函数进行删除操作等。 学生类和班级类还有学生链表类和班级链表类之间的相互关系如图1所示。 stulist - list thestu + getthestu() : list + add(student stu) : void + seek(char *num) : void + show() : void + sorttofile(char *filename) : void + max() : void + min() : void 学生类和学生链表类的uml图的表示 student - stuname20 : char - stunum12 : char - stuscore4 : float - total : float + student() + student(char *name , char *num , float s1, float s2, float s3, float s4 ) + *getnum() : char + *getstuscore() : float +operator + class() + class(char *grade, char *cclass, list l) + *getclclass() : char + cprint() : void cllist - thecl :list + cadd(class cl) : void + cseek(char *cclass) : void + cmodify(char *cclass, class /student.h学生类 class student; class stulist; ostream/ friend class stulist; /友元类 ; 沈阳理工大学面向对象课程设计 5 /stulist.h 学生信息的相关处理 class stulist private: list thestu; /链表对象 public: list getthestu() /输出链表 return thestu; void add(student stu); /添加学生信息 void seek(char *num); /查询学生信息,按学号查询,返回记录号,-1表示 没有找到 void show(); /遍历列表显示 void sorttofile(char *filename); /按学生总成绩从高到低排序并写到文件中 void max(); /各科的最高分 void min(); /各科的最低分 ; /class.h班级类 class class private: char clgrade10; /一共四个年级,其中的一个年级 char clclass10; /班级名称 list cl; /链表对象,一个班最多30个学生 public: class() /构造函数 class(char *grade, char *cclass, list l) /构造函数 strncpy(clgrade, grade, 10); strncpy(clclass , cclass, 10); cl = l; char *getclclass() /输出学号 return clclass; void cprint(); /输出学生信息 friend ostream public: void cadd(class cl); /添加班级信息 void cseek(char *cclass); /查询班级信息,按班级名称查询 void cmodify(char *cclass, class /修改班级信息 void cdelete(char *cclass); /删除班级信息 void cshow(); /遍历列表显示 ; 以上四个类已经能够显示学生信息,比不过可通过一些成员函数实现学生和班级的 一些添加、修改、删除、查找等操作。 4.2 类的实现 #include “stdafx.h“ #include #include #include #include #include #include #include using namespace std; /student.cpp student:student(char *name, char *num, float s1, float s2, float s3, float s4)/构造函数 strncpy(stuname, name, 20); strncpy(stunum , num, 12); stuscore0 = s1; stuscore1 = s2; stuscore2 = s3; stuscore3 = s4; total = stuscore0 + stuscore1 + stuscore2 + stuscore3; void student:print(int n)/输出函数 static bool stuhead = false; if(!stuhead) 沈阳理工大学面向对象课程设计 7 if(n 0) cout 0) cout:iterator it = thestu.begin(); /定义迭代器指针 student stu; while(it != thestu.end() stu = *it; if(strcmp(stu.getnum(), num) = 0) sign = i; break; it+; i+; 沈阳理工大学面向对象课程设计 8 if(sign = 0) cout:iterator it = thestu.begin(); /定义迭代器指针 int i = 0; while(it != thestu.end() it-print(+i); it+; void stulist:sorttofile(char * filename) /按学生总成绩进行排序 thestu.sort(); show(); /排序后的内容保存到文件中 ofstream out(filename); copy(thestu.begin(), thestu.end(), ostream_iterator(out); void stulist:max() /各科的最高分 float max4 = 0, 0, 0, 0; for(int i=0; i:iterator it = thestu.begin(); /定义迭代器指针 student stu; while(it != thestu.end() stu = *it; if(maxi :iterator it = thestu.begin(); /定义迭代器指针 student stu; while(it != thestu.end() stu = *it; if(mini stu.stuscorei) mini = stu.stuscorei; it+; cout:iterator it = cl.begin();/定义迭代器指针 int i = 0; while(it != cl.end() it-print(+i); it+; 沈阳理工大学面向对象课程设计 10 /cllist.cpp void cllist:cadd(class cl) /增加班级信息 thecl.push_back(cl); void cllist:cseek(char *cclass) /查询班级信息 int sign = -1; list:iterator it = thecl.begin(); /定义迭代器指针 class cl; while(it != thecl.end() cl = *it; if(strcmp(cl.getclclass(), cclass) = 0) sign = 1; break; it+; if(sign 0) cout:iterator it = thecl.begin(); /定义迭代器指针 while(it != thecl.end() if(strcmp(*it).getclclass(), cclass) = 0) *it = cl; /sign = 1; break; it+; 沈阳理工大学面向对象课程设计 11 cout:iterator it = thecl.begin();/定义迭代器指针 while(it != thecl.end() if(strcmp(*it).getclclass(), cclass) = 0) thecl.erase(it); break; it+; cout:iterator it = thecl.begin(); /定义迭代器指针 class cl; while(it != thecl.end() cl = *it; cl.cprint(); it+; 4.3 主函数设计 /kese1.cpp int main() /主函数 stulist thestu; /存放所有学生 student stu1(“ma“, “0803070201“, 88, 90, 69, 52.6f); student stu2(“li“, “0803070202“, 52, 96, 74, 56); student stu3(“wang“, “0803070101“, 85, 25, 95, 79); student stu4(“yang“, “0803070102“, 82, 78, 84, 95); student stu5(“ding“, “0803070301“, 76, 85.6f, 94, 83); thestu.add(stu1); thestu.add(stu2); thestu.add(stu3); 沈阳理工大学面向对象课程设计 12 thestu.add(stu4); thestu.add(stu5); thestu.show(); thestu.seek(“0803070201“); /查找学号为 0803070201 的同学 cout(out); 可用函数 max()和 min()求出各科的最高成绩和最低成绩,其显示结果如 上图。 5.1.2 班级信息的运行结果如图所示 显示对班级的读入并显示出来如图有两个二年级的班级 08030701 和 08030702。 查找班级,按班级的名称来查找 08030702 班,用函数 cllist:cseek(char *cclass)进行查找。 void cllist:cseek(char *cclass) /查询班级信息 int sign = -1; list:iterator it = thecl.begin(); /定义迭代器指针 class cl; while(it != thecl.end() cl = *it; if(strcmp(cl.getclclass(), cclass) = 0) 沈阳理工大学面向对象课程设计 15 sign = 1; break; it+; if(sign 0) cout:iterator it = thecl.begin();/定义迭代器指针 while(it != thecl.end() if(strcmp(*it).getclclass(), cclass) = 0) thecl.erase(it); break; it+; cout 1000 #pragma once #endif / _msc_ver 1000 class ccalculation public: void dec2bin(cstring *strexp); void dec2oct(cstring *strexp); ccalculation(); virtual ccalculation(); bool m_bdegree; int m_noutputflag;/=0 十进制输出;=1 十六进制输出;=2 八进制输出;=3 二进制输出 cstring mainpro(cstring strexp);/*主处理函数* void dec2hex(cstring *strexp); private: void calcu(cstring *strexp,int pos);/*二元运算的预处理函数* void macro(cstring *strexp);/*常数宏代换* void oct2dec(cstring *strexp);/*处理 8 进制数* void bin2dec(cstring *strexp);/*处理 2 进制数* void hex2dec(cstring *strexp);/*处理 16 进制数* void multie(cstring *strexp);/*多元运算* void minusminus(cstring *strexp);/*处理负负得正* void delbracket(cstring *strexp);/*用计算结果替换表达式* bool synres(cstring *strexp);/*判断表达式是否合法* cstring modiresult(cstring strres);/*在格式上处理最后的计算结果* 沈阳理工大学面向对象课程设计 17 cstring ntos(double d);/*数字转字串* cstring singlee(cstring op,double dx);/*一元运算* cstring twoe(cstring strexp);/*二元运算* cstring opt16; cstring opt15; cstring m_strconname15; cstring m_strconvalue15; cstring m_strtmp; bool isdigital(cstring str);/*判断表达式中是否有函数或运算符* int bracheck(cstring str);/*计算左右括号的差值* int locatelbra(cstring strexp);/*定位最后一个左括号* double ston(cstring str);/*字串转数字* char opt26; protected: ; #endif / !defined(afx_calculation_h_aa32ee12_b5f4_455f_afb3_c02717c012b1_ _included_) / calculator.h : main header file for the calculator application / #if !defined(afx_xpstyle_h_7b24cc84_968d_4019_bf93_6c66b2cde487_incl uded_) #define afx_xpstyle_h_7b24cc84_968d_4019_bf93_6c66b2cde487_included_ #if _msc_ver 1000 #pragma once #endif / _msc_ver 1000 #ifndef _afxwin_h_ #error include stdafx.h before including this file for pch #endif #include “resource.h“/ main symbols / / cfunc.h : header file / / / ccfunc dialog 沈阳理工大学面向对象课程设计 18 class ccfunc : public cdialog / construction public: ccfunc(cwnd* pparent = null); / standard constructor cstring m_strn; / dialog data /afx_data(ccfunc) enum idd = idd_dialog_func ; / note: the classwizard will add data members here /afx_data / overrides / classwizard generated virtual function overrides /afx_virtual(ccfunc) public: protected: virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv support /afx_virtual / implementation protected: cmfectooltip m_tooltip; uint m_nctrlid16; cstring m_strctrlname16; uint m_nctrlidtmp; / generated message map functions /afx_msg(ccfunc) virtual bool oninitdialog(); virtual void oncancel(); afx_msg bool onsetcursor(cwnd* pwnd, uint nhittest, uint message); afx_msg void onbntsin(); afx_msg void onbtncos(); afx_msg void onbnttan(); afx_msg void onbntcot(); afx_msg void onbntlog(); afx_msg void onbntarccos(); afx_msg void onbntarcsin(); afx_msg void onbntln(); afx_msg void onbntsqr(); afx_msg void onbntabs(); afx_msg void onbntsh(); afx_msg void onbntexp(); afx_msg void onbntch(); 沈阳理工大学面向对象课程设计 19 afx_msg void onbntarctan(); afx_msg void onbntth(); afx_msg void onbnt10exp(); /afx_msg declare_message_map() ; /afx_insert_location / microsoft visual c+ will insert additional declarations immediately before the previous line. #endif / !defined(afx_cfunc_h_53b33130_2390_4ba5_ba6d_009b6cc9b245_inclu ded_) #if !defined(afx_cnum_h_1a2707ad_bcd9_41ce_8520_2bebb5c6ef11_inclu ded_) #define afx_cnum_h_1a2707ad_bcd9_41ce_8520_2bebb5c6ef11_included_ #if _msc_ver 1000 #pragma once #endif / _msc_ver 1000 / cnum.h : header file / #include “mfectooltip.h“ / / ccop dialog class ccop : public cdialog / construction public: cstring m_strn; ccop(cwnd* pparent = null); / standard constructor / dialog data /afx_data(ccop) enum idd = idd_dialog_op ; / note: the classwizard will add data members here /afx_data / overrides / classwizard generated virtual function overrides 沈阳理工大学面向对象课程设计 20 /afx_virtual(ccop) protected: virtual void dodataexchange(cdataexchange* pdx); / ddx/ddv support /afx_virtual / implementation protected: cmfectooltip m_tooltip; uint m_nctrlidtmp; / generated message map functions /afx_msg(ccop) virtual void oncancel(); afx_msg void onbtnadd(); afx_msg void onbtnmin(); afx_msg void onbtnmul(); afx_msg void onbtndiv(); afx_msg void onbtnpow(); afx_msg void onbtnmod(); afx_msg void onbtnlbra(); afx_msg void onbtnrbra(); virtual bool oninitdialog(); afx_msg bool onsetcursor(cwnd* pwnd, uint nhittest, uint message); /afx_msg declare_message_map() ; /afx_insert_location / microsoft visual c+ will insert additional declarations immediately before the previous line. #endif / !defined(afx_cop_h_180f20ef_1922_4adf_89d4_e03c8ef7961a_include d_) #ifndef _mfectooltip_h_ #define _mfectooltip_h_ / default tooltip colors #define ivory rgb(255, 255, 220) #define blackrgb(0, 0, 0) / this structure holds all the tooltip information struct tooltipinfo : public cobject uintncontrolid;/ id of the control 沈阳理工大学面向对象课程设计 21 uintninfosize;/ number of lines in the info cstringarrayncontrolinfo;/ container of the information colorrefntextcolor;/ text color colorrefnbackcolor;/ background color ; class cmfectooltip : public cwnd / construction public: cmfectooltip(); / standard constructor virtual cmfectooltip();/ destructor voidcreate(cwnd* pwnd); voideraseprevioustooltipdisplay( uint ); voidshowtooltip( uint );/ explicitly shown the tooltip given the control id / note: the user must override the pretranslatemessage in the calling window in order / to handle mousemovent. voidshowtooltip( cpoint/ called only during mousemovement / tooltip functions booladdcontrolinfo( uint, cstringarray boolremovecontrolinfo( uint ); / inline functions voidsetfontsize( int size ) m_nfontsize = size; / implementation protected: cwnd*m_pparentwnd; intm_nheight; intm_nwidth; intm_nfontsize; intm_ntotalline; intm_maxcharinline; virtual void calculateinfoboxrect(uint ncontrolid, crect* pinforect); virtual void calculateheightandwidth(cstringarray private: 沈阳理工大学面向对象课程设计 22 tooltipinfo*iscontrolidexisting( uint ); voiddisplayinfo( tooltipinfo* ); private: cobarraym_acontrolinfo; uintm_currentcontrolid; ; #endif #ifndef _mfectooltip_h_ #define _mfectooltip_h_ / default tooltip colors #define ivory rgb(255, 255, 220) #define blackrgb(0, 0, 0) / this structure holds all the tooltip information struct tooltipinfo : public cobject uintncontrolid;/ id of the control uintninfosize;/ number of lines in the info cstringarrayncontrolinfo;/ container of the information colorrefntextcolor;/ text color colorrefnbackcolor;/ background color ; class cmfectooltip : public cwnd / construction public: cmfectooltip(); / standard constructor virtual cmfectooltip();/ destructor voidcreate(cwnd* pwnd); voideraseprevioustooltipdisplay( uint ); voidshowtooltip( uint );/ explicitly shown the tooltip given the control id / note: the user must override the pretranslatemessage in the calling window in order / to handle mousemovent. voidshowtooltip( cpoint/ called only during mousemovement 沈阳理工大学面向对象课程设计 23 / tooltip functions booladdcontrolinfo( uint, cstringarray boolremovecontrolinfo( uint ); / inline functions voidsetfontsize( int size ) m_nfontsize = size; / implementation protected: cwnd*m_pparentwnd; intm_nheight; intm_nwidth; intm_nfontsize; intm_ntotalline; intm_maxcharinline; virtual void calculateinfoboxrect(uint ncontrolid, crect* pinforect); virtual void calculateheightandwidth(cstringarray private: tooltipinfo*iscontrolidexisting( uint ); voiddisplayinfo( tooltipinfo* ); private: cobarraym_acontrolinfo; uintm_currentcontrolid; ; 2 详细设计详细设计 / cfunc.cpp : implementation file / #include “stdafx.h“ #include “calculator.h“ #include “cfunc.h“ #ifdef _debug #define new debug_new #undef this_file static char this_file = _file_; #endif 沈阳理工大学面向对象课程设计 24 / / ccfunc dialog ccfunc:ccfunc(cwnd* pparent /*=null*/) : cdialog(ccfunc:idd, pparent) /afx_data_init(ccfunc) / note: the classwizard will add member initialization here /afx_data_init void ccfunc:dodataexchange(cdataexchange* pdx) cdialog:dodataexchange(pdx); /afx_data_map(ccfunc) / note: the classwizard will add ddx and ddv calls here /afx_data_map begin_message_map(ccfunc, cdialog) /afx_msg_map(ccfunc) on_wm_setcursor() on_bn_clicked(idc_bnt_sin, onbntsin) on_bn_clicked(idc_btn_cos, onbtncos) on_bn_clicked(idc_bnt_tan, onbnttan) on_bn_clicked(idc_bnt_cot, onbntcot) on_bn_clicked(idc_bnt_log, onbntlog) on_bn_clicked(idc_bnt_arccos, onbntarccos) on_bn_clicked(idc_bnt_arcsin, onbntarcsin) on_bn_clicked(idc_bnt_ln, onbntln) on_bn_clicked(idc_bnt_sqr, onbntsqr) on_bn_clicked(idc_bnt_abs, onbntabs) on_bn_clicked(idc_bnt_sh, onbntsh) on_bn_clicked(idc_bnt_exp, onbntexp) on_bn_clicked(idc_bnt_ch, onbntch) on_bn_clicked(idc_bnt_arctan, onbntarctan) on_bn_clicked(idc_bnt_th, onbntth) on_bn_clicked(idc_bnt_10exp, onbnt10exp) /afx_msg_map end_message_map() / 沈阳理工大学面向对象课程设计 25 / ccfunc message handlers bool ccfunc:oninitdialog() cdialog:oninitdialog(); m_nctrlid0=idc_bnt_sin;m_nctrlid1=idc_btn_cos;m_nctrlid2=idc_ bnt_tan; m_nctrlid3=idc_bnt_cot;m_nctrlid4=idc_bnt_log;m_nctrlid5=idc _bnt_arccos; m_nctrlid6=idc_bnt_arcsin;m_nctrlid7=idc_bnt_ln;m_nctrlid8=i dc_bnt_sqr; m_nctrlid9=idc_bnt_abs;m_nctrlid10=idc_bnt_sh;m_nctrlid11=id c_bnt_exp; m_nctrlid12=idc_bnt_ch;m_nctrlid13=idc_bnt_arctan;m_nctrlid1 4=idc_bnt_th; m_nctrlid15=idc_bnt_10exp; m_strctrlname0=“正弦“;m_strctrlname1=“余弦“;m_strctrlname2=“正切“; m_strctrlname3=“余切“;m_strctrlname4=“以 10 为底的对数 “;m_strctrlname5=“反余弦“; m_
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 啤酒发酵过滤工安全文明竞赛考核试卷含答案
- 第十单元实验活动7溶液酸碱性的检验说课稿-2023-2024学年九年级化学人教版下册
- 扭王字块安装施工质量保证措施
- 公司音圈绕制工岗位标准化技术规程
- 过氧化二异丙苯装置操作工班组安全模拟考核试卷含答案
- 公司光刻工岗位标准化技术规程
- 品酒师岗前班组评比考核试卷含答案
- 挤密砂桩施工资源配置(人、机、料)
- 液压元件及液压系统制造工标准化技术规程
- 焊接设备装配调试工操作知识水平考核试卷含答案
- 阶段学业质量评价(一)(试题)-四年级上册数学苏教版
- 电子商务网站设计与实现毕业论文
- 工程经济学-邵颖红-第五版-课后作业
- 焊接应力计算讲义
- 教学评一体化的教学案例 课件
- GB/T 3995-2006高铝质隔热耐火砖
- 人教版初中数学《与三角形有关的角》优秀版课件
- 渗滤液处理站运行方案
- 4制度安排及公共伦理课件
- 希特《战略管理:竞争与全球化》第11版配套教学课件
- 最新安全生产管理教材电子版
评论
0/150
提交评论