好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

C++面向对象程序设计-三角形的种类与面积.doc

20页
  • 卖家[上传人]:枫**
  • 文档编号:490013437
  • 上传时间:2023-02-16
  • 文档格式:DOC
  • 文档大小:699.50KB
  • / 20 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 湖南人文科技学院计算机系 课程设计说明书 课 程 名 称:C++面向对象程序设计课 程 代 号:436103题 目:三角形的种类与面积年级/专业/班:2010级软件工程专业一班学 生 姓 名:学 号:指 导 教 师:开 题 时 间:2011 年 6 月 13 日完 成 时 间:2011 年 6 月 24 日目 录摘 要 3一、引 言 3二、设计目的与任务 3三、设计方案 21、总体设计 22、详细设计 43、程序清单 74、程序调试与体会 125、运行结果 13四、结 论 16五、致 谢 16六、参考文献 17摘 要C++是C语言的超集,它不仅保持了与C语言的兼容,而且还支持面向对象程序设计的特征,C++程序在可重用性、可扩充性、可维护性和可靠性等方面都较C语言得到了提高,使其更适合开发大中型的系统软件和应用程序本文论述了使用设计了判断三角形的种类和计算基面积的系统首先使用C++中的类设计了Point类、Line派生类和Triangle多级派生类;然后再编写intput()、al_line()、jud_tri()以及alg_tri()函数,它们的功能分别是输入数据、计算边长、判断种类以及计算和输出面积;最后在主程序中调用intput()、al_line()、jud_tri()以及alg_tri()函数实现整个程序的运行。

      经过多次调试,结果成功通过编译并得出了正确的结果,使我的系统可以正常实现菜单选择、输入数据、进行判断和计算并输入结果等功能关键词:VC6.0;派生类;多级派生类;AbstractC + + is C language of super set, it not only keeps up with the C language compatible, but also do it support object-oriented program design,which is the characteristics of the C + + program in the reusability, scalability, and reliability, maintainability.And in such aspects ,C++ have improved, it become more suitable for the development of large and medium-sized system software and application. This paper discusses the problem that useing the to design a system to judge the types of triangle and calculation the area of it.At first,we use the class of C++ to design a class Point,a derived class Line and a multilevel derived class Triangle.Then we write the fuctions intput(),al_line(),jud_tri() and alg_tri().Their functions are data inputting, length calculation,types judgement and area outputting.Finally,the host program can realize the whole operation by calling the functions intput(),al_line(),jud_tri() and alg_tri().Conclusively,we have past the compiling and get a right result after debugging many times.And then we have knowm our system can realize the functions are menu selection,data inputting,judgement and result outputting.Key words:VC6.0; Derived class; Multilevel derived class;《C++程序设计》课程设计------三角形的种类与面积一、引 言《面向对象程序设计课程设计》是计算机科学与技术专业和软件工程专业集中实践性环节之一,是学习完《面向对象程序设计》课程后进行的一次全面的综合练习。

      其目的在于加深对面向对象程序设计中基础理论和基本知识的理解,培养学生的实践能力,促进理论与实践的结合二、设计目的与任务通过课程设计,让学生能够熟练运用C++进行面向对象编程,建立对象模型,降低软件的复杂性,改善软件的重用性和维护性,提高软件的生产效率,全面掌握面向对象编程技术通过课程设计,掌握使用一种面向对象程序设计语言开发工具如DEV-C++ 5或Visual C++等;培养调查研究、查阅技术文献、资料、手册以及编写技术文献的能力;通过课程设计,要求学生在指导教师的指导下,独立完成实习课题的全部内容,包括:⑴ 通过调查研究和上机实习,收集和调查有关技术资料⑵ 掌握设计课题的基本步骤和方法 ⑶ 根据课题的要求进行上机实验调试任务要求 本课程设计了判断三角形的种类和计算并输出其面积的系统该系统能实现输入三角形的三个顶点坐标、判断三角形的种类以及计算并输出三角形的面积等功能三、设计方案1、总体设计经过我们分析,在本课程设计中,首先设计了如下总体设计流程图,如图1开始输入三角形的三个顶点输入选择选择操作子程序 保存文件并结束图1 总体设计流程序然后在此基础上设计了Point类、Line类、Triangle类,其框架如下:Point类class point //定义一个point类{ public: void intput(); //声明一个输入函数 float get_x() { return x; } //返回x的值 float get_y() { return y; } //返回y的值 private: float x,y; //定义对象x,y用来表示坐标};Line类class line:public point //派生类line{ public: void al_line(point& ,point& ,point&); //声明一个计算三条边长度的函数 float get_l1() { return l1; } //返回l1的值 float get_l2() { return l2; } //返回l2的值 float get_l3() { return l3; } //返回l3的值 private: float l1,l2,l3; //定义三条线段};class triangle :public line //派生类triangle{public:void jud_tri(line& ); //声明一个判断三角形的种类函数void alg_tri(line& ); //声明一个计算并输出三角形的面积函数private:float p,s; //定义s计算面积,p为中间变量};Triangle类2、详细设计 .层次(调用)关系:经过我们集体更加细致的分析和讨论,首先得出了一个详细的层次关系设计流程图,如图2输入三角形的三个顶点输入选择判断三角形的种类计算三角形的面积判断出种类计算出面积退出输入选择图2层次关系设计流程图2.2.类设计图:通过我们大家的共同努力,我们设计出了类的详细代码,如下:Point类class point //定义一个point类{ public: void intput(); //声明一个输入函数 float get_x() { return x; } //返回x的值 float get_y() { return y; } //返回y的值 private: float x,y; //定义对象x,y用来表示坐标};void point::intput() //定义输入坐标的函数{ cin>>x>>y; }Line类Line类class line:public point //派生类line{ public: void al_line(point& ,point& ,point&); //声明一个计算三条边长度的函数 float get_l1() { return l1; } //返回l1的值 float get_l2() { return l2; } //返回l2的值 float get_l3() { return l3; } //返回l3的值 private: float l1,l2,l3; //定义三条线段};void line::al_line(point& p1,point& p2,point& p3) //计算三条边的长度{ l1=sqrt((p2.get_x()-p1.get_x())*(p2.get_x()-p1.get_x())+ (p2.get_y()-p1.get_y())*(p2.get_y()-p1.get_y())); l2=sqrt((p3.get_x()-p1.get_x())*(p3.get_x()-p1.get_x())+ (p3.get_y()-p1.get_y())*(p3.get_y()-p1.get_y())); l3=sqrt((p3.get_x()-p2.get_x())*(p3.get_x()-p2.get_x())+ (p3.get_y()-p2.get_y())*(p3.get_y()-p2.get_y()));}Triangle类class triangle :public line //派生类triangle{ public: void jud_tri(line& ); //声明一个判断三角形的种类函数 void alg_tri(line& ); //声明一个计算并输出三角形的面积函数 private: float p,s; //定义s计算面积,p为中间变量};void triangle::jud_tri(line& l) //利用计算好的三边判断三角形的种类……void triangle::alg_tri(lin。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.