C++实验设计报告Word文档下载推荐.docx
- 文档编号:972275
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:20
- 大小:51.40KB
C++实验设计报告Word文档下载推荐.docx
《C++实验设计报告Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C++实验设计报告Word文档下载推荐.docx(20页珍藏版)》请在冰点文库上搜索。
(1)掌握C++语言数据类型,熟悉如何定义变量,以及对它们赋值的方法。
(2)学会使用C++有关算术运算符,以及包含这些运算符的表达式。
(3)进一步熟悉C++程序的结构。
(4)进一步熟悉C++程序的编辑、编译、连接和运行的过程。
题2-2
charc1='
C'
c2='
+'
c3='
Isay:
\"
c1<
c2<
c3<
'
\t\t"
Hesays:
C++isveryinteresting!
\n'
题2-3
#include<
inti,j,m,n;
i=8;
j=10;
m=++i+j++;
n=(++i)+(++j)+m;
i<
\t'
j<
m<
n<
题2-4-
(1)
charc1,c2,c3,c4,c5;
c1='
c2='
h'
c3='
i'
c4='
n'
c5='
a'
China的密码是:
c1=c1+4;
c2=c2+4;
c3=c3+4;
c4=c4+4;
c5=c5+4;
c4<
c5<
题2-4-
(2)
T'
o'
d'
c4='
c5='
y'
Today的密码是:
题2-4-(3)
c1=c1-4+26;
c2=c2-4;
c3=c3-4;
c4=c4-4;
c5=c5-4+26;
实验3C++程序设计初步
(1)掌握简单的C++程序的编写和调试方法。
(2)掌握C++程序中使用最多的语句--赋值语句和输入输出的使用方法。
(3)掌握结构化程序的3种基本结构(顺序结构、选择结构、循环结构)在C++中的实现。
2.实验内容
题3-1
cmath>
iomanip>
{intx,y;
cout<
pleaseenterx="
cin>
x;
if(x<
1)y=x;
if(x<
10&
&
x>
=1)y=2*x-1;
if(x>
=10)y=3*x-11;
cout<
y="
y<
return0;
题3-2
一个数如果恰好等于它的因子之和,这个数就称为完数,例如,6的因子为1,2,3。
而6=1+2+3因此6是“完数”,编程序找出1000之内的所有完数,并按下面格式输出其因子:
6,itsfactorsare1,2,3
要求用两种不同的方法编程序,并做比较。
程序代码:
intm,i,sum=0;
请输入m=:
cin>
m;
for(m=1;
=1000;
m++)
for(i=1;
=(m-1);
i++)
if(m%i==0)
sum=sum+i;
if(sum=m)
cout<
itsfactorsare:
sum"
题3-3
intmain()
doublex1,x2,p=0,a;
请输入a的值:
a;
if(a<
0)
{
a的值应当是正值,请重新输入a的值:
cin>
}
x1=a/2;
while((fabs(x1-x2))>
1e-5)
{x2=0.5*(x1+a/x1);
p=x1;
x1=x2;
x2=p;
a的平方根为:
x1<
题3-4-1
inti,j,k;
for(j=1;
=4;
j++)
=2*j-1;
{
cout<
*"
}
=3;
for(k=7;
k>
=2*j+1;
k--)
{
题3-4-2
intmain()
{
inti,j;
intx=4;
for(i=1;
=x*2;
i+=2)
for(j=0;
=x-i/2+1;
j++)cout<
"
=i;
for(i=(x-1)*2;
i>
=1;
i-=2)
=x-i/2+2;
i;
}
题3-5
intA=1,B=2,C=3;
intx,y,z;
三队参赛选手分别为:
for(x=1;
x<
x++)
for(y=1;
y++)
for(z=1;
z<
z++)
{
if(x!
=A)
if(z!
=C)
if(x!
if(x!
=y&
x!
=z&
y!
=z)
{
switch(x)
{
case1:
cout<
A--x"
break;
case2:
cout<
B--x"
case3:
C--x"
}
switch(y)
case1:
A--y"
B--y"
C--y"
switch(z)
{
A--z"
B--z"
C--z"
}
}
实验四函数与预处理
(1)熟悉定义函数的方法、函数实参与形参的对应关系以及“值传递”的方式。
(2)熟悉函数的嵌套调用和递归调用的方法。
(3)熟悉全局变量、局部变量概念和使用方法。
(4)熟悉编译预处理的应用。
(5)掌握多文件的程序的编译和运行的方法
实验4-3
voidmove(charx,chary,charz,intn);
inttemp;
intnum;
请输入要从A移到C的盘子个数:
num;
move('
A'
'
B'
num);
将"
num<
盘子从A移到C总共移动"
temp<
次。
voidmove(charx,chary,charz,intn)
n=n-1;
if(n>
=1)
move(x,z,y,n);
最上的盘移到"
temp=temp+1;
move(y,x,z,n);
else
题5-1
#include<
inti,j,min,temp,a[11];
enterdata:
for(i=1;
=10;
a["
]="
a[i];
endl<
Theoriginalnumbers:
for(i=1;
a[i]<
=9;
min=i;
for(j=i+1;
if(a[min]>
a[j])min=j;
temp=a[i];
a[i]=a[min];
a[min]=temp;
Thesortednumbers:
题5-2
constintn=7;
inti,number,top,bott,mid,loca,a[n];
boolflag=true,sign;
charc;
a[0];
i=1;
while(i<
n)
if(a[i]>
=a[i-1])
i++;
else
enterthisdataagain:
for(i=0;
n;
while(flag)
inutnumbertolookfor:
number;
sign=false;
top=0;
bott=n-1;
if((number<
a[0])||(number>
a[n-1]))
loca=-1;
while((!
sign)&
(top<
=bott))
mid=(bott+top)/2;
if(number==a[mid])
loca=mid;
cout<
Find"
number<
itspositionis"
loca+1<
sign=true;
elseif(number<
a[mid])
bott=mid-1;
else
top=mid+1;
if(!
sign||loca==-1)
hasnotfound."
continuornot(Y/N)?
c;
if(c=='
N'
||c=='
)
flag=false;
题5-4
string>
constintn=10;
stringname[n];
intnum[n],score[n];
inti;
voidinput_data();
input_data();
thelistoffailed:
if(score[i]<
60)
name[i]<
num[i]<
score[i]<
return0;
voidinput_data()
inputname,numberandscoreofstudent"
i+1<
:
name[i]>
num[i]>
score[i];
题5-5
constintn=4,m=5;
inti,j,a[n][m],max,maxj;
boolflag;
for(i=0;
for(j=0;
cin>
a[i][j];
for(i=0;
max=a[i][0];
maxj=0;
for(j=0;
if(a[i][j]>
max)
{
max=a[i][j];
maxj=j;
}
flag=true;
for(intk=0;
k<
k++)
if(max>
a[k][maxj])
{
flag=false;
continue;
}
if(flag)
cout<
]["
["
maxj<
max<
break;
if(!
flag)
itdoesnotexist!
return0;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 实验设计 报告