实验报告5.docx
- 文档编号:11098244
- 上传时间:2023-05-29
- 格式:DOCX
- 页数:8
- 大小:26.66KB
实验报告5.docx
《实验报告5.docx》由会员分享,可在线阅读,更多相关《实验报告5.docx(8页珍藏版)》请在冰点文库上搜索。
实验报告5
学生实验报告
学生姓名
学号
同组人无
实验项目
熟悉开发环境
□必修□选修
□演示性实验□验证性实验□操作性实验□综合性实验
实验地点
实验仪器台号
指导教师
实验日期及节次
一、实验综述
1、实验目的及要求
1.Beforeyouenterthefollowingprograminthecomputer,pleasepointouttheerrorsofit,thenanalyzeandcorrecttheerrors.
#include
intn;
voidmain()
{
doublem=3.8;
cout<<"n="< fn(); } voidfn() { cout<<"m="< cout<<"n="< } 2.Beforeyouenterthefollowingprograminthecomputer,pleasereaditandwritedowntheoutputresultsoftheprogram.Then,youcantesttheresultsinthecomputerbycompilingandrunningitinVC++6.0. #include voidfunc(); intn=1; intmain() { staticintx=5; inty; y=n; cout<<"x="< func(); cout<<"x="< func(); } voidfunc() { staticintx=4; inty=10; x+=3; n+=10; y+=n; cout<<"x="< } 3.Beforeyouenterthefollowingprograminthecomputer,pleasegivetheresultsofthefollowingprogramofMacros.Then,youcantesttheresultsinthecomputerbycompilingandrunningitinVC++6.0. #include #definef(x)x*x voidmain() { cout< cout< cout< } 4.Basedonthefollowingnamespaceandwhatwehavelearnedaboutnamespace,pleaseusetwoorthreedifferentwaystocallthenamespaceinthemainfunction.Theprogramshouldbedesignedbymodularprogrammingandtelltheroleofthenamespace. namespaceMy{ intAdd(int,int); intMul(int,int); } intMy: : Add(inta,intb) { returna+b; } intMy: : Mul(inta,intb) { returna*b; } namespaceYour{ intAdd(int,int); intMul(int,int);} intYour: : Add(inta,intb) { returna-b; } intYour: : Mul(inta,intb) { returna/b; } 2、实验仪器、设备或软件 硬件设备: 计算机、因特网。 软件环境: Windows系列操作系统,C++语言编译环境: VisualC++软件,Office系列软件,如Word、PowerPoint等。 二、实验过程(实验步骤、记录、数据、分析) 1.#include intn; doublem=3.8; voidmain() { voidfn(); fn(); } voidfn() { cout<<"m="< cout<<"n="< } 4.第一种方法: voidmain() { inta,b; cout<<"输入两个数: \n"; cin>>a>>b; usingnamespaceMy; Add(a,b); cout< } 第二种方法: voidmain() { inta,b; cin>>a>>b; usingMy: : Add;(a,b); cout< : Add(a,b)< } 三、结论 1、实验结果 1.#include intn; doublem=3.8; voidmain() { voidfn(); fn(); } voidfn() { cout<<"m="< cout<<"n="< } 2.输出结果: x=5,y=2,n=1 x=7,y=21,n=11 x=6,y=3,n=11 x=10,y=31,n=21 3. 输出结果: 24 8 28 4.第一种方法: voidmain() { inta,b; cout<<"输入两个数: \n"; cin>>a>>b; usingnamespaceMy; Add(a,b); cout< } 第二种方法: voidmain() { inta,b; cin>>a>>b; usingMy: : Add;(a,b); cout< : Add(a,b)< } 2、分析讨论 1.Ifyoumustuseamacro,encloseoccurrencesofamacroargumentnameinparentheseswheneverpossible. 2.usingdeclarationandusingdirective: Theformeristodeclareonememberinanamespace,thelatteristousethewholenamespace,eg: usingname: : matrix;//ok,usingdeclaration usingnamespacename;//ok,usingdirective 四、指导教师评语及成绩: 评语: 成绩: 指导教师签名: 批阅日期:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 报告
![提示](https://static.bingdoc.com/images/bang_tan.gif)