- 1
- 0
- 约4.73千字
- 约 11页
- 2017-08-18 发布于江西
- 举报
程序设计基础实践报告书 测控11-2 谷晓峰.doc
程序设计基础实践报告书
实践1 熟悉VC++6.0集成开发环境
一、目的
1、熟悉VC++6.0集成开发环境。
二、内容
VC的启动
源程序的新建、编辑和保存(结合例1.1)
#include iostream
using namespace std
int main( )
{
cout“This is a C++ program.”;
return 0;
}
源程序的打开(如,上机指导教材所附光盘中c1-1.cpp)
新建项目与添加单个源程序(结合例1.1)
只包含单个源程序的项目的编译与运行
实践2 数据类型与表达式
一、目的
熟悉C++程序的基本概念:表达式、语句。
了解C++程序的基本结构和书写规范。
熟悉C++程序的基本操作语句:变量定义、变量赋值、输入、输出。
二、内容
1、(验证)阅读习题2-4,上机验证分析结果。
实验结果为:I say:"C++" He says:"C++ is very interesting!"
#include iostream
using namespace std;
int main ( )
{ int a,b;
float x,y;
a=2;
b=3;
x=3.5;
y=2.5;
cout(float)(a+b)/2+(int)x%(int)yendl;
return 0; }
输出结果:3.5
习题2-6(6)
#include iostream
using namespace std;
int main ( )
{ int a,b;
a=12;
b=a+=a-=a*=a;
coutbendl;
return 0;
}
实践3 控制结构
一、目的
1、熟悉C++的基本概念:关系运算、逻辑运算。
2、熟悉C++程序的控制结构及关键语法:顺序、选择(if、switch)、循环(while、for)。
二、内容
1、(编程)计算习题3-8(1),3-8(5)表达式的值。
计算习题3-8(1)
#include iostream
using namespace std;
int main ( )
{
int a,b,c;
int x;
a=3;
b=4;
c=5;
x=a+bcb==c;
coutxendl;
return 0;
}
输出结果:0
习题3-8(5)
#include iostream
using namespace std;
int main ( )
{
int a,b,c;
int x;
a=3;
b=4;
c=5;
x=!(a+b)+c-1b+c/2;
coutxendl;
return 0;
}
输出结果:1
2、验证习题3-9,理解2种方法的设计思想和实现过程。
方法一:用if语句
#include iostream
using namespace std;
int main ( )
{
int a,b,c;
coutplease enter a,b,c:endl;
cinabc;
if(ab)
if(bc)
coutcendl;
else if(bc)
coutb;
else coutaendl;
return 0;
}
输出结果:
please enter a,b,c:
1 2 3
3
方法二:条件表达式
#include iostream
using namespace std;
int main ( )
{
int a,b,c,temp,max;
coutplease enter a,b,c:;
cinabc;
temp=(ab)?a:b;
max=(tempc)?temp:c;
coutmax=maxendl;
return 0;
}
输出结果:
please enter a,b,c:1 2 3
max=3
3、验证习题3-16。输入一行字符,分别统计出其中英文字母、空格、数字、和其他字符的个数。
#include iostream
using namespace std;
int main ( )
{
char c;
int letters=0,space=0,digit=0,other=0;
coutenter one line:endl;
while((c=getchar())!=\n)
{if(c=ac=z||c=Ac=Z)
letters++;
else if (c== )
space++;
else if (c=0c=9)
digit++;
else
other++;
}
coutletter:letters,space:space,digit:digit,other:otherendl;
re
原创力文档

文档评论(0)