《C++程序设计》实验报告格式.docx
- 文档编号:11562596
- 上传时间:2023-03-19
- 格式:DOCX
- 页数:13
- 大小:70.32KB
《C++程序设计》实验报告格式.docx
《《C++程序设计》实验报告格式.docx》由会员分享,可在线阅读,更多相关《《C++程序设计》实验报告格式.docx(13页珍藏版)》请在冰豆网上搜索。
《C++程序设计》实验报告格式
C++程序设计
实验报告
课程名称:
C++程序设计
姓名:
张建超
实验名称:
简单的C++程序
学号:
20093608
实验编号:
Lab_1
专业:
信息安全
任课教师:
关兴
班级:
软信1班
指导教师:
陈东明
组号:
实验日期:
2010年3月26日
实验时间:
14时00分-17时20分
实验成绩:
批阅教师签字:
一、实验目的
(1)学习编写简单的C++程序,并掌握C++程序的基本格式与规范。
(2)理解C++程序结构的特点。
(3)掌握函数的定义和调用方法。
(4)练习重载函数的使用。
(5)练习函数模板的使用。
(6)练习使用系统函数。
(7)学习使用VC++的debug调试功能,使用stepinto追踪到函数内部。
二、实验内容与实验步骤
实验内容:
(1)输人并运行所给的参考程1,并将程序中的注释部分也输人计算机,体会和理解程序的基本格式规范。
(2)编写一个函数把华氏温度转换为摄氏温度,转换公式为C=(F一32)*5/9。
(3)编写重载函数Maxl可分别求取两个整数,三个整数,两个双精度数,三个双精度数的最大值。
(4)使用重载函数模板重新实现上小题中的函数Maxl。
(5)使用系统函数pow(x,y)计算xy的值,注意包含头文件math.h。
(6)用递归的方法编写函数求Fibonacci级数,观察递归调用的过程。
原理分析:
1:
intadd(inta,intb)
{
intc;
c=a+b;
returnc;
}
2:
intzhuang(inta)
{
intx;
x=(a-32)*5/9;
returnx;
}
3:
intMax1(inta,intb)
{
return((a>b)?
a:
b);
}
intMax1(inta,intb,intc)
{
return((c>((a>b)?
a:
b))?
c:
((a>b)?
a:
b));
}
doubleMax1(doublea,doubleb)
{
return((a>b)?
a:
b);
}
doubleMax1(doublea,doubleb,doublec)
{
return((c>((a>b)?
a:
b))?
c:
((a>b)?
a:
b));
}
4:
template
TMax1(Ta,Tb)
{
return((a>b)?
a:
b);
}
template
TMax1(Ta,Tb,Tc)
{
return((c>((a>b)?
a:
b))?
c:
((a>b)?
a:
b));
}
5:
intx,y,z;
cout<<"pleaseinputtwonumber:
\n";
cin>>x>>y;
z=pow(x,y);
cout<<"theresultis:
"< return0; 6: intfib(intn) { intx; if(n==1) x=1; else if(n==2) x=1; else x=fib(n-1)+fib(n-2); returnx; } 三、实验环境 操作系统: windowsXP 开发平台的名称及版本: MicrosoftVisualC++6.0 四、实验过程与分析 1: --------------------Configuration: oier-Win32Debug-------------------- Compiling... iwedf.cpp c: \programfiles\microsoftvisualstudio\myprojects\oier\iwedf.cpp(8): errorC2065: 'cout': undeclaredidentifier c: \programfiles\microsoftvisualstudio\myprojects\oier\iwedf.cpp(8): errorC2297: '<<': illegal,rightoperandhastype'char[25]' c: \programfiles\microsoftvisualstudio\myprojects\oier\iwedf.cpp(8): errorC2065: 'endl': undeclaredidentifier c: \programfiles\microsoftvisualstudio\myprojects\oier\iwedf.cpp(9): errorC2065: 'cin': undeclaredidentifier c: \programfiles\microsoftvisualstudio\myprojects\oier\iwedf.cpp(9): warningC4552: '>>': operatorhasnoeffect;expectedoperatorwithside-effect c: \programfiles\microsoftvisualstudio\myprojects\oier\iwedf.cpp(11): errorC2297: '<<': illegal,rightoperandhastype'char[17]' Errorexecutingcl.exe. oier.exe-5error(s),1warning(s) 通过比较书中的范例找到未写usingnamespacestd;写后问题解决。 五、实验结果总结 1 2 3 4 5 6 六、思考题 1.VisualC++6.0环境下是如何管理项目和文件的? 2.C++提供的输入输出操作与C语言的输入输出操作的异同点? 3.C++引入的内联函数与其它函数有何不同? 4.重载函数时通过什么来区分? 七、参考文献 Visualc++面向对象的程序设计 八、附录 1: intmain() { intx,y,sum; cout<<"Entertwonumber: \n"; cin>>x; cin>>y; sum=add(x,y);cout<<"thesumis: "< return0; } intadd(inta,intb)//求和 { intc; c=a+b; returnc; } 2: intmain() { intc,f; cout<<"pleaseinputthenumber: "< cin>>f; c=zhuang(f); cout<<"temperatureis: "< return0; } intzhuang(inta)//转换成温度 { intx; x=(a-32)*5/9; returnx; } 3: intmain() { inta,b,c,d; doublef,x,y,z; cout<<"pleaseinputtwointnumber: \n"; cin>>a>>b; d=Max1(a,b); cout<<"theMaxis: "< cout<<"pleaseinputthreeintnumber: \n"; cin>>a>>b>>c; d=Max1(a,b,c); cout<<"theMaxis: "< cout<<"pleaseinputtwodoublenumber: \n"; cin>>f>>x; y=Max1(f,x); cout<<"theMaxis: "< cout<<"pleaseinputthreedoublenumber: \n"; cin>>f>>x>>z; y=Max1(f,x,z); cout<<"theMaxis: "< return0; } intMax1(inta,intb)//比较两个整数大小 { return((a>b)? a: b); } intMax1(inta,intb,intc)//比较三个整数大小 { return((c>((a>b)? a: b))? c: ((a>b)? a: b)); } doubleMax1(doublea,doubleb)//比较两个浮点数大小 { return((a>b)? a: b); } doubleMax1(doublea,doubleb,doublec)//比较三个浮点数大小 { return((c>((a>b)? a: b))? c: ((a>b)? a: b)); } 4: TMax1(Ta,Tb)//比较两个数大小 { return((a>b)? a: b); } template TMax1(Ta,Tb,Tc)//比较三个数大小 { return((c>((a>b)? a: b))? c: ((a>b)? a: b)); } intmain() { inta,b,c,d; doublef,x,y,z; cout<<"pleaseinputtwointnumber: \n"; cin>>a>>b; d=Max1(a,b); cout<<"theMaxis: "< cout<<"pleaseinputthreeintnumber: \n"; cin>>a>>b>>c; d=Max1(a,b,c); cout<<"theMaxis: "< cout<<"pleaseinputtwodoublenumber: \n"; cin>>f>>x; y=Max1(f,x); cout<<"theMaxis: "< cout<<"pleaseinputthreedoublenumber: \n"; cin>>f>>x>>z; y=Max1(f,x,z); cout<<"theMaxis: "< return0; } 5: intmain() { intx,y,z; cout<<"pleaseinputtwonumber: \n"; cin>>x>>y; z=pow(x,y);//求幂 cout<<"theresultis: "< return0; } 6: intmain() { intn,f; cout<<"pleaseinputthenumber: \n"; cin>>n; f=fib(n); cout<<"theFibonacciis: "< return0; } intfib(intn)//递归函数 { intx; if(n==1) x=1; else if(n==2) x=1; else x=fib(n-1)+fib(n-2); returnx; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+程序设计 C+ 程序设计 实验 报告 格式
