2022年完整word版,c++课程设计任务书1421813-15

上传人:ni****g 文档编号:567310562 上传时间:2024-07-19 格式:PDF 页数:15 大小:63.42KB
返回 下载 相关 举报
2022年完整word版,c++课程设计任务书1421813-15_第1页
第1页 / 共15页
2022年完整word版,c++课程设计任务书1421813-15_第2页
第2页 / 共15页
2022年完整word版,c++课程设计任务书1421813-15_第3页
第3页 / 共15页
2022年完整word版,c++课程设计任务书1421813-15_第4页
第4页 / 共15页
2022年完整word版,c++课程设计任务书1421813-15_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《2022年完整word版,c++课程设计任务书1421813-15》由会员分享,可在线阅读,更多相关《2022年完整word版,c++课程设计任务书1421813-15(15页珍藏版)》请在金锄头文库上搜索。

1、1 面向对象程序设计课程设计任务书一、课程设计的目的与要求1、教学目的综合运用所学过的知识进行实际程序设计。2、教学要求从课程设计的目的出发,用C+编写简单的的程序,程序要求如下:(1)算法正确,容错性能好;(2)完成从用户需求分析、到上机编程、调试和应用等全过程。二、课程设计的题目、内容及要求Part 1: 小程序练习(必须全部完成)1 函数重载定义重载函数max3用于计算三个数的最大值(参数类型分别为int 和 double)。#include using namespace std; int max3(int a,int b,int c) if(ba) a=b; if(ca) a=c;

2、return a; double max3(double a,double b,double c) if(ba) a=b; if(ca) a=c; return a; int main( ) int max3(int a,int b,int c); double max3(double a,double b,double c); int i1,i2,i3,i; cout”请输入三个数:”i1i2i3; i=max3(i1,i2,i3); couti.max3=id1d2d3; d=max3(d1,d2,d3); coutd.max3=dendl; 2 类的组合定义 point类,数据成员包括x

3、,y,成员函数包括构造函数,拷贝构造函数和析构函数,以及 setx ,getx ,sety , gety 四个属性函数。定义line 类,端点由两个point类的对象组成,包括构造函数,析构函数以及计算线段长度的函数getlength。在 main函数中,定义line 的对象,并输出其长度。#include 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 1 页,共 15 页2 #include using namespace std; class point private: int x,y; public: point(int x,int y)

4、:x(x),y(y) point(point &p); int getx() return x; void setx(int x) this-x=x; int gety() return y; void sety(int y) this-y=y; point() ; point:point(point &p) x=p.x; y=p.y; class line private: point p1,p2; double len; public: line(point pt1,point pt2); line(line &l); double getlen() return len; line()

5、; line:line(point pt1,point pt2):p1(pt1),p2(pt2) double x=p1.getx()-p2.getx(); double y=p1.gety()-p2.gety(); len=sqrt(x*x+y*y); line:line(line &l):p1(l.p1),p2(l.p2) len=l.len; int main() point po1(1,2),po2(3,4); line line(po1,po2); coutthe length of line is:endl; coutline.getlen()endl; 3 对象数组和函数定义 s

6、tudent类,数据成员包括姓名name和成绩 score ,成员函数包括构造函数,拷贝构造函数和析构函数。 定义函数void highestscore(student s),输出分数最高的学生姓名和分数。在 main函数中定义 student sN,调用 highestscore函数 ,输出分数最高的学生姓名和分数。#include 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 2 页,共 15 页3 #include const int N=3; using namespace std; class student private: stri

7、ng name; int score; public: student(string n=,int s=0):name(n),score(s) student(student &stu) name=stu.name; score=stu.score; student() friend istream &operator(istream &is,student &stu) isstu.namestu.score; return is; friend void highestscore(student s); ; void highestscore(student stu) int i,h,t;

8、t=stu0.score; for(i=0;iN;i+) if(tstui.score) t=stui.score; h=i; coutname:stuh.namescore:stuh.scoreendl; void main() student s1N; for(int i=0;is1i; highestscore(s1); 4 静态数据成员设计一个书类,能够保存书名、定价,所有书的本数和总价。(将书名和定价设计为普通数据成员;将书的本数和总价设计为静态数据成员)#include #include using namespace std; class book private: string

9、 name; int price,num; static int count,sum; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 3 页,共 15 页4 public: book(string na,int p,int n):name(na),price(p),num(n) count+=num; sum+=num*price; void display() cout 书名 :nameendl; cout 价格 :priceendl; cout 所有书的本数:numendl; cout 总价 :sumendl; book() ; int bo

10、ok:count=0; int book:sum=0; void main() book a(c grammer,100,10),b(c+ grammer,50,6); a.display(); b.display(); 5 动态内存分配定义 point类,数据成员包括x,y,成员函数包括构造函数,拷贝构造函数和析构函数,以及 setx ,getx ,sety ,gety 四个属性函数。在main函数中,用new 和 delete分配和释放N 个 point的数组。( N 是const常量, N=10 )#include using namespace std; class point pri

11、vate: int x,y; void setx(int x) this-x=x; void sety(int y) this-y=y; public: point(int x=0,int y=0); point(const point &p) x=p.x; y=p.y; void setxy(int x,int y) setx(x); sety(y); int getx() return x; int gety() 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 4 页,共 15 页5 return y; void showpoint() cou

12、tx=x y=yx=x; this-y=y; void main() point *pt=new point10; (*pt).setxy(1,2); (*pt).showpoint(); delete pt; 6 类的继承定义一个point类,包含私有数据成员x,y,成员函数包括无参构造函数,带参构造函数,set 和 get属性函数。定义circle类,从 point类公有派生,增加数据成员半径r,成员函数包括无参构造函数,带参构造函数,计算面积函数getarea。在 main函数中定义一个circle的对象,并计算其面积。#include using namespace std; clas

13、s point private: int x,y; public: point():x(0),y(0) point(int x,int y):x(x),y(y) int getx() return x; void setx(int x) this-x=x; int gety() return y; void sety(int y) this-y=y; point() ; class circle:public point private: int r; public: circle(int x,int y,int r):point(x,y),r(r) int getr() return r;

14、void setr(int r) 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 5 页,共 15 页6 this-r=r; void getarea() coutarea:r*r*3.14endl; ; int main() circle c(1,2,3); c.getarea(); 7 虚基类定义 vehicle类, 数据成员包括私有的weight, 公有的构造函数, 析构函数和输出函数dispaly ; 从 vehicle类公有派生car类,增加数据成员载人数personnum,公有的构造函数,析构函数和输出display ;从vehicle

15、类公有派生truck 类, 增加数据成员载货量laod, 公有的构造函数, 析构函数和输出函数display ;从 car 类和 truck类共同公有派生出pickup类,包括公有的构造函数和输出函数。在 main函数中, 定义 pickup类对象,并输出其基本信息。#include using namespace std; class vehicle private: int weight; public: vehicle(int w):weight(w) void display() coutweight:weightendl; vehicle() ; class car:virtual

16、public vehicle private: int personnum; public: car(int p,int w):vehicle(w),personnum(p) void display() coutpersonnum:personnumendl; car() ; class truck:virtual public vehicle private: int load; public: truck(int w,int l):vehicle(w),load(l) void display() coutload:load, 功能。在main函数里测试该类。#include using

17、 namespace std; class counter private: double number; public: counter(double num=0):number(num) friend counter operator +(counter &c,int); friend counter operator -(counter &c,int); friend counter operator +(counter &c); friend counter operator -(counter &c); friend istream &operator(istream &is,cou

18、nter &c) isc.number; return is; friend ostream &operator(ostream &os,counter &c) osc1; c2=operator+(c1,2); coutcount before:c2 count after:c1endl; 9 虚函数和抽象类定义一个抽象类shape ,包括公有的计算面积area函数,计算体积volume函数,输出基本信息函数printinfo(三个函数均为纯虚函数)。从shape公有派生point类,增加私有数据成员x,y 坐标,以及构造函数, 析构函数。 从 point公有派生circle类,增加私有数据

19、成员半径r,以及构造函数, 析构函数。从 circle公有派生cylinder类,增加私有数据成员高度h,以及构造函数,析构函数。(在定义三个派生类的过程中,自己考虑需要重定义哪个虚函数)。在main函数中,定义shape类的指针,指向派生类的对象,输出三类对象的基本信息,面积,体积;(将shape指针改为引用再尝试)。#include using namespace std; class shape public: virtual double area()=0; virtual double volume()=0; virtual void printinfo()=0; ; class p

20、oint:public shape private: int x,y; public: point(int x,int y):x(x),y(y) double area() return 0; double volume() return 0; void printinfo() coutpoint:x=x,y=yendl; point() ; class circle:public point private: int r; public: 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 8 页,共 15 页9 circle(int x,int y

21、,int r):point(x,y),r(r) double area() return 3.14*r*r; void printinfo() coutarea:areaendl; circle() ; class cylinder:public circle private: int h; public: cylinder(int x,int y,int r,int h):circle(x,y,r),h(h) double volume() return circle:area()*h; void printinfo() coutvolume:volumeprintinfo(); void

22、main() point p(1,1); circle c(1,1,3); cylinder C(1,1,3,4); /*p.printinfo(); c.printinfo(); C.printinfo();*/ fun(&p); fun(&c); fun(&C); 10 模板设计一个堆栈的类模板Stack ,在模板中用类型参数T表示栈中存放的数据,用非类型参数MAXSIZE 代表栈的大小。#include const int Maxsize=5; template class stack private: T elemMaxsize; int top; public: stack() to

23、p=0; void push(T e) if (top=Maxsize) 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 9 页,共 15 页10 cout 栈已满! endl; return ; elemtop=e; top+; T pop() if(top=0) cout 栈空! endl; return -1; top -; return elemtop; ; void main() stack s; s.push(1); s.push(2); s.push(3); s.push(4); s.push(5); s.push(6); couts

24、.pop()endl; 11 文件读写定义学生类数组,有N 个人( N=5 ),包括姓名和语数外三名课的成绩,通过重载运算符实现学生数组的文件读写。(姓名用string name;)#include #include using namespace std; class stu private: char name10; int chi,mat,eng; public: stu(char s=,int c=0,int m=0,int e=0) strcpy(name,s); chi=c; mat=m; eng=e; friend ostream&operator(ostream &os,stu

25、 &s) oss.name s.chi s.mat s.eng(istream &is,stu &s) iss.names.chis.mats.eng; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 10 页,共 15 页11 return is; ; const int N=5; void main() stu sN; int i=0; fstream iof(c:student.txt,ios:out|ios:binary); if(!iof.is_open () coutfile open failedendl; return ; else

26、 for(int i=0;isi; coutsi; iof.write(char *)&si,sizeof(stu) ; iof.close (); stu s1N; iof.open(c:student.txt,ios:out|ios:binary); if(!iof.is_open() return ; else int i=0; iof.read(char *)&s1i,sizeof(stu); while(!iof.eof() couts1i; i+; iof.read(char *)&s1i,sizeof(stu); iof.close(); Part 2: 小型软件的开发(选做一题

27、,且由个人独立开发完成)1 教师通信录的设计基本要求:定义教师 (teacher )类,其中至少包括姓名、性别、 电话、 地址、 邮政编码、 邮箱、 QQ号和类别 (例如:同学、朋友等)。功能要求: 1、设计菜单实现功能选择; 2、输入功能:输入人员信息,并保存到文件中; 3、查询功能: 1)能够根据姓名、电话精确查询人员信息;精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 11 页,共 15 页12 2)能够根据地址进行模糊查询人员信息; 3)根据人员类别查询人员信息 4、根据姓名对人员信息排序输出 5、能根据姓名、电话修改人员信息 6、能根据姓

28、名、电话删除人员信息2 职工工资管理基本要求:定义职工( employee )类,其中至少包括姓名、性别、工号、电话、所在科室和工资。功能要求: 1、设计菜单实现功能选择; 2、输入功能:输入职工信息,并保存到文件中; 3、查询功能: 1)能够根据工号精确查询职工信息; 2)能够根据姓名、科室查询职工信息 3)分科室进行工资统计,计算各科室的平均工资 4、根据职工的工资排序输出 5、根据工号修改职工信息 6、根据工号删除职工信息#include #include using namespace std; class employee private: string name,sex,offic

29、e; int id,phone number,salary; public: employee() 3 公司员工管理系统基本要求:设计一个虚基类Staff (员工) ,包括编号、 姓名和年龄保护数据成员以及相关的成员函数;由 Staff派生出工程师类Engineer 包含专业和职称保护数据成员以及相关的成员函数,再由 Staff派生出领导类Leader ,包括职务和部门保护数据成员以及相关的成员函数;然后由Engineer和 Leader 类派生出主任工程师类Chairman。功能要求:1、增加员工数据信息2、更新员工数据信息3、查询员工数据信息4、删除员工数据信息5、良好的人际交互界面、方便

30、操作精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 12 页,共 15 页13 4 三角形的种类与面积基本要求:定义点( point )类,包含点的坐标x 和 y;通过继承点类派生出线段(line )类;通过线段(line )类的组合定义三角形(triangle )类。功能要求: 1、设计菜单实现功能选择; 2、输入三角形的三个顶点坐标; 3、判断三角形的种类(一般三角形、等腰三角形、等边三角形、直角三角形和不能构成三角形); 4、计算并输出三角形的面积。5 字符串类的设计基本要求:定义点字符串(string)类,包含存放字符串的字符数组和字符串中

31、字符的个数。功能要求: 1、设计菜单实现功能选择; 2、字符串的输入与赋值; 3、字符串的运算,包括: 1)连接 2)复制 3)查找 4)交换 5)求子串 6)比较 4、字符串的输出6 学生成绩管理基本要求:定义学生( student )类,其中至少包括姓名、性别、学号、班级和四门功课的成绩。功能要求: 1、设计菜单实现功能选择; 2、输入功能:输入学生信息,并保存到文件中; 3、计算每个学生的总分与平均分并排序 4、能根据学号修改学生信息 5、能根据学号删除学生信息 6、查询功能: 1)能够根据学号查询学生信息; 2)能够根据姓名、班级查询学生信息 3)统计学生成绩,按照班级和科目计算平均分

32、。7 几何体的表面积与体积基本要求:定义一个抽象类形状(shape),包含输入基本图形的信息函数input()、显示基本图形信息函数disp()、计算表面积的函数area() 、计算体积的函数volume() ,它们均为纯虚函数。通过继承形状类派生出球体类、正方体类、长方体类、圆柱体类。功能要求: 1、设计菜单实现功能选择; 2、输入各种形状信息; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 13 页,共 15 页14 3、显示各种形状信息; 4、计算各种形状的表面积; 5、计算各种形状的体积;8 学生信息管理基本要求:定义学生( studen

33、t )类,其中至少包括姓名、性别、学号、班级和联系电话。功能要求: 1、设计菜单实现功能选择; 2、输入功能:输入学生信息,并保存到文件中; 3、能按照学生的学号排序 4、能根据学号修改学生信息 5、能根据学号删除学生信息 6、查询功能: 1)能够根据学号查询学生信息; 2)能够根据姓名、学号、班级等查询学生信息 3)按照班级统计学生人数。9 教职工信息管理基本要求:定义职工( employee )类,其中至少包括姓名、性别、工号、电话、所在系部和职称。功能要求: 1、设计菜单实现功能选择; 2、输入功能:输入职工信息,并保存到文件中; 3、查询功能: 1)能够根据工号精确查询职工信息; 2)

34、能够根据姓名、科室查询职工信息 3)分系部进行职称统计,计算各职称的人数 4、根据职工的职称排序输出 5、根据工号修改职工信息 6、根据工号删除职工信息10 复数计算器基本要求:定义复数( complex )类,其中至少包括实部和虚部,对复数类实现尽可能丰富的运算。功能要求:1)建立复数类2)复数信息的初始化3)复数信息的输出4)将复数信息保存为文件5)求复数的绝对值6)实现复数的加、减、乘、除、乘方、自加、自减等运算三、源程序清单和执行结果:源程序清单中应有足够的注释。精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 14 页,共 15 页15 四

35、、课程设计完成时间:二周。五、课程设计的成绩评定1、程序设计结果(30)2、课程设计报告(40)3、平时表现(30)附:课程设计实习报告的书写格式一、设计题目二、运行环境(软、硬件环境)三、算法设计的思想四、算法的流程图五、算法设计分析六、源代码七、运行结果分析八、收获及体会六、上机时间安排表课程设计的时间及教师安排专业班级周次机房安排上机时间指导老师软件工程1421813-15 第 16-17 周核工楼 308 周三( 1,2,3,4)周四( 1,2,3,4)周五( 1,2,3,4,5,6,7,8)魏振华许志文精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 15 页,共 15 页

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号