欢迎来到天天文库
浏览记录
ID:37086258
大小:164.23 KB
页数:8页
时间:2019-05-17
《实验一熟悉VisualStudio开发环境》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.本科实验报告课程名称:C++面向对象程序设计实验项目:实验地点:明向校区专业班级:软件1419学号:2014006061学生姓名:刘国鑫指导教师:王丽娟2015年5月10日..实验名称实验一熟悉VisualStudio开发环境实验目的1.了解和使用VisualStudio集成开发环境;2.熟悉VisualStudio环境的基本命令和功能键;3.了解面向对象程序设计方法的基本原理及主要特点——抽象、封装、继承和多态;4.学习完整的C++程序开发过程。实验要求1.完善、编写程序,并调试程序。要给出邪恶是数据和实验结果;2.整
2、理上机步骤,总结经验和体会;3.完成实验报告和上交程序。实验内容1.编写重载函数area()和perime(),分别计算圆、长方形、正方形的面积和周长,并在主函数中测试;2.完善程序,并上机运行;3.定义一个复数类Complex,复数的实部Real与虚部Image定义为私有数据成员。用复数类定义复数对象c1、c2、c3,用默认构造函数将c1初始化为c1=20+40i,将c2初始化为c2=0+0i,用拷贝函数将c3初始化为c3=20+40i。用公有成员函数Display()显示复数c1、c2和c3的内容;4.定义一个矩形类R
3、ectangle,矩形的左上角(Left,Top)与右下角坐标(Right,Bottom)定义为保护数据成员。用公有成员函数Diagonal()计算出矩形对角线的长度,公有成员函数Show()显示矩形左上角与右下角坐标及对角线的长度。在主函数中用new运算符动态建立矩形对象r1,初值为(10,10,20,20)。然后调用Show()显示矩形左上角与右下角坐标及对角巷长度。最后用delete运算符回收为矩形动态分配的存储空间。主要仪器设备台式或笔记本电脑实验记录(1,3,4写出代码及运行结果,2补全代码并写出运行结果)1.#
4、include"iostream"#includeusingnamespacestd;#definepi3.141592doubleArea(doubleR);doubleArea(doublea,doubleb);doublePerim(doubleR);doublePerim(doublea,doubleb);intmain(){doubler;doublem;doublen;cout<<"请输入圆的半径:"<>r;cout<<"圆的面积为:"<5、:"<>m>>n;cout<<"长方形的面积为:"<>m;cout<<"正方形的面积为:"<6、;s=pi*R*R;returns;}doubleArea(doublea,doubleb){doubles;s=a*b;returns;}doublePerim(doubleR){doublep;p=2*pi*R;returnp;}doublePerim(doublea,doubleb){doublep;p=2*(a+b);returnp;}运行结果:..2.#includeusingnamespacestd;classRectangle{public:Rectangle(doublel,double7、w):len(l),wid(w){}doublearea(){doublearea;area=len*wid;returnarea;}private:doublelen,wid;};classSquare{public:Square(doublel):len(l){}doublearea(){doublearea;area=len*len;returnarea;}private:doublelen;};classCircle{public:Circle(doubler):radius(r){}doublearea(){do8、ublearea;area=3.14*radius*radius;returnarea;}private:doubleradius;};intmain(){cout<<"Inputshape:"<
5、:"<>m>>n;cout<<"长方形的面积为:"<>m;cout<<"正方形的面积为:"<6、;s=pi*R*R;returns;}doubleArea(doublea,doubleb){doubles;s=a*b;returns;}doublePerim(doubleR){doublep;p=2*pi*R;returnp;}doublePerim(doublea,doubleb){doublep;p=2*(a+b);returnp;}运行结果:..2.#includeusingnamespacestd;classRectangle{public:Rectangle(doublel,double7、w):len(l),wid(w){}doublearea(){doublearea;area=len*wid;returnarea;}private:doublelen,wid;};classSquare{public:Square(doublel):len(l){}doublearea(){doublearea;area=len*len;returnarea;}private:doublelen;};classCircle{public:Circle(doubler):radius(r){}doublearea(){do8、ublearea;area=3.14*radius*radius;returnarea;}private:doubleradius;};intmain(){cout<<"Inputshape:"<
6、;s=pi*R*R;returns;}doubleArea(doublea,doubleb){doubles;s=a*b;returns;}doublePerim(doubleR){doublep;p=2*pi*R;returnp;}doublePerim(doublea,doubleb){doublep;p=2*(a+b);returnp;}运行结果:..2.#includeusingnamespacestd;classRectangle{public:Rectangle(doublel,double
7、w):len(l),wid(w){}doublearea(){doublearea;area=len*wid;returnarea;}private:doublelen,wid;};classSquare{public:Square(doublel):len(l){}doublearea(){doublearea;area=len*len;returnarea;}private:doublelen;};classCircle{public:Circle(doubler):radius(r){}doublearea(){do
8、ublearea;area=3.14*radius*radius;returnarea;}private:doubleradius;};intmain(){cout<<"Inputshape:"<
此文档下载收益归作者所有