太原理工大学 c++实验报告-申嘉文 201300.docVIP

  • 23
  • 0
  • 约8.66千字
  • 约 17页
  • 2017-05-21 发布于浙江
  • 举报

太原理工大学 c++实验报告-申嘉文 201300.doc

太原理工大学c实验报告-申嘉文201300

C++实验报告 课程名称: 面向对象程序设计基础 实验项目: 二、C++基础与对象 实验地点: 艺专楼A208 专业班级: 软件13 学号: 201300 学生姓名: 申嘉文 指导教师: 崔晓红 2014年 4 月 26 日 实验二、C++基础 例(2)的程序代码: #include stdafx.h #includeiostream using namespace std; void addsub(int,int); int main() { int a=10,b=25; addsub(a,b); couta=a,b=bendl; return 0; } void addsub(intx,inty) { int t=x; x=x+y; y=t-y; } 例(2)的运行结果: (5)的程序代码: #include stdafx.h #includeiostream using namespace std; int max(int x,int y); int max(int x,int y,int z); double max(double x,double y); double max(double x,double y,double z); int main() { int a=2,b=3,c=4,i,j; double d=2.2,e=3.3,f=4.4,m,n; i=max(a,b); j=max(a,b,c); cout2个整数的最大值是iendl; cout3个整数的最大值是jendl; m=max(d,e); n=max(d,e,f); cout2个双精度数的最大值是mendl; cout3个双精度数的最大值是nendl; return 0; } int max(int x,int y) { return xy?x:y; } int max(int x,int y,int z) { x=xy?x:y; return xz?x:z; } double max(double x,double y) { return xy?x:y; } double max(double x,double y,double z) { x=xy?x:y; return xz?x:z; } (5)的运行结果: (8)的程序代码: #include stdafx.h #includeiostream using namespace std; void yuan(); void chang(); void zheng(); int main() { int i,j; cout请选择图形类型endl; cout1、圆形 2、长方形 3、正方形endl; cini; if(i==1) {cout您选择的是圆形endl; yuan(); } else if(i==2) {cout您选择的是长方形endl; chang(); } else if(i==3) {cout您选择的是正方形endl; zheng();} else cout选择错误endl; return 0; } void yuan() { float r,s; cout输入圆的半径endl; cinr; s=3.14*r*r; cout圆的面积是sendl; } void chang() { float x,y,s; cout输入长方形的长和宽endl; cinx; ciny; s=x*y; cout长方形的面积是sendl; } void zheng() { float x,s; cout输入正方形的边长endl; cinx; s=x*x; cout正方形的面积是sendl; } 实验三、类与对象 (4)的程序代码: #include stdafx.h #includeiostream using namespace std; class complex { private: int Real; int Image; public: complex(int re=20,int im=40); void Display(); }; complex::complex(int re ,int im):Real(re),Image(im){} void complex::Display() { coutReal+Imageiendl

文档评论(0)

1亿VIP精品文档

相关文档