实验一 简单程序设计
- 格式:doc
- 大小:28.50 KB
- 文档页数:2
实验一:简单程序设计
【实验目的】
1、学会使用Visual C++6.0版本编译系统完成C++语言源程序的编译。
2、掌握C++程序的基本格式与规范,学会编写简单的C++程序。
3、理解C++程序结构的特点。
4、熟悉C++程序基本的输入输出操作。
【实验内容】
题目一:
运行下列正确程序,练习一个文件程序编译、连接、运行的方法。
//This is a C++ program
#include<iostream.h>
void main()
{
double x,y;
cout<<”Enter two float numbers:”;
cin>>x>>y;
double z=x+y;
cout<<”x+y=”<<z<<endl;
}
题目二:
将下列有错误的程序输入并调试,根据显示的错误信息对程序进行修改,直到无错为止。
main()
{
int x;
cin>>x;
int y,k=x+y;
cout<< “x+y=”<<k<<\n;
}
改正:
#include<iostream.h>
int main()
{
int x,y;
cin>>x>>y;
int k;
k=x+y;
cout<<"x+y="<<k<<endl;
}
题目三:
编程实现输入千米数,输出显示其英里数。
已知:1英里=1.60934千米(用符号常量)。
测试数据:输入1,输出:0.621373
#include<iostream.h>
void main()
{
const double YL(1.60934);
double x;
cin>>x;
double y=x/YL;
cout<<"y="<<y<<endl;
}
题目四:
输入两个正整数m、n,合并成一个正整数p。
合并的方式是:将m的十位和个位数字放在p的千位和十位上,将n的十位和个位数字放在p的个位和百位上。
例如m=75,n=69,合并后p=7956。
输出显示m、n、p的值。
测试数据:输入:75 69,输出:7956
#include<iostream.h>
void main()
{
int m,n;
cin>>m>>n;
int p;
p=100*m+n;
cout<<"p="<<p<<endl;
}
题目五:
有多项式-4x3+5.8x2-2x+2.6,输入x的值,输出多项式的值。
测试数据:输入0,输出:2.6
#include<iostream.h>
void main()
{
double x,y;
cin>>x;
y=-4*x*x*x+5.8*x*x-2*x+2.6;
cout<<"y="<<y<<endl;
}。