资源描述:
《C++语言程序设计课程的程序分析练习题(电大考试必备)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C++语言程序设计课程的程序分析练习题一、写出下列每个程序运行后的输出结果1.#include#includevoidmain(){intx=20,y=6,z;charop=’+’;switch(op){case'+':z=x+y;break;case'-':z=x-y;break;default:{cout<<"操作符op出错,退出运行!";exit(1);}}cout<<”z=”<#includevoidmain(){char*a[5]={"stude
2、nt","worker","cadre","soldier","apen"};unsignedintn=strlen(a[0]);//求字符串a[0]的长度for(inti=1;i<5;i++){if(strlen(a[i])>n)n=strlen(a[i]);}cout<intWF(intx,inty){x=x+y;y=x+y;returnx+y;}voidmain(){cout<constintN=9;voidmain(){in
3、ta[N]={2,4,6,8,10,12,14,16,18};ints=0;for(inti=0;ivoidmain(){int*d=newint[5];inti,s=0;for(i=0;i<5;i++)d[i]=2*i+1;for(i=0;i<5;i++)s+=d[i];cout<<3*s<voidSB(charch){switch(ch){case'A':ca
4、se'a':cout<<"优!"<<’’;break;case'B':case'b':cout<<"良!"<<’’;break;case'C':case'c':cout<<"通过!"<<’’;break;default:cout<<"不通过!";break;}}voidmain(){SB(’A’);SB(’c’);cout<voidmain(){inta[6]={36,25,48,14,55,40};intx=a[0];for(inti=1;i<6;i++)if(a[i]>x)x=a[i];cout<<”x=”<5、endl;}运行结果:8.#includevoidmain(){inta[6]={32,53,27,19,12,45};for(int*p=a;pint*LG(intm){int*a=newint(m+5);returna;}voidmain(){intn1=12;int*b=LG(n1);cout<<*b<#includes
6、tructWorker{charname[15];intage;floatpay;};18voidmain(){Workerx;strcpy(x.name,"WeiRong");x.age=45;x.pay=3275;cout<voidmain(){intn=5,sum=0;while(n){sum+=n;n--;}cout<<”sum=”<constintN=6;voidmain()
7、{inta[N]={76,83,54,62,40,65};intc1,c2;c1=c2=a[0];for(inti=1;ic1)c1=a[i];elseif(a[i]voidmain(){inta[8]={4,8,15,16,20,30,48,62};in