电大《C++语言程序设计》第一次作业.doc
专业好文档2009年宁波电大C+语言程序设计第一次作业 一、填空题。 1一个基本语句的最后一个字符是 。 2函数调用时,实参向形参的传送分为 和 两种传送方式。 3若应用程序onefunc.cpp中只有一个函数,这个函数的名称是 。 4变量分为全局和局部两种, 变量没有赋初值时,其值是不确定的。 5常量345L占用 字节存储空间。 6执行int i,s; for(i=8,s=0;i>0;i-) s+=i; while(+i<5) s+=i; 后; s的值是 。 7执行for(int i=0;i<=20;i+) cout<<'*' 将输出 个*号。 8假定一个二维数组的定义为“char a88;”,则该数组所含元素的个数为 ,所占存储空间的字节数为 。 9把逗号表示式x>100?100:0的值赋值给变量y的赋值语句是 。 10字符串”字符串”占用 字节的空间。 11”FirstLinen2ndLine”的长度是 。 12执行int a=5,b; b=a+;后,a的值为 ,b的值为 。 13假定x=10,y=6,则表达式2+x+和+y*3的值分别为 和 。 14执行cout<<C+15;,显示在屏幕上的是 。 15假定一个枚举类型的定义为“enum RBab,ac=3,ad,aex=ad;”,则x的值为 。 16执行“cout<<143<<+<<17<<=<<143+17<<endl;”语句后得到的输出结果为 。 17利用操作符+,语句序列p=p+1;f=p+15;的功能可以由一个语句完成,这个语句是 。 18x+y<3的相反条件不用操作符!可表示为 。 19与a3+3a3b+3ab2+b3对应的C+表示式是 。 20函数定义的格式是: 函数名( )函数体。二、选择题。 1A>B&&A<=B的值为( )。 A、为true B、为false C、与A>B的值相同 D、与A<=B的值相同 2C+字符串“ABC”以 符号作为结束符,需 字节的 存储空间。( )。 A、 C,3 B、 C,4 C、'0',3 D、'0',4 3从定义unsigned var;可以看出,var是一个( )变量。 A、无符号短整型 B、无符号小整型 C、无符号整数 D、无符号长整型 4以下合法的C+字符常量是( )。 A、'B' B、 "A" C、 65 D、 A 5执行int k,d=8; k=d+*3;后,k和d的值分别为( )。 A、24 8 B、24 9 C、27 8 D、27 9 6以下程序的输出结果是( )。 A、11 B、10 C、9 D、10 11 for(j=10;j<11;j+) for(i=9;i<j;i+) if(!(j%i) break; if(i>=j-1) cout<<j; 7下列的常值变量定义中,错误的是( )。 A、const int ll=210; B、const char ch=67 C、const double d; D、const long ld=345; 8以下程序的输出结果是( )。 A、 C B、 D C、 E D、 F char ch; ch='C'+'5'-'3' cout<<ch; 9若x为一个bool型变量,则x|5的值( )。 A、为true B、为false C、与x的值相同 D、与x|5的值相反 10从以下给出的表达式中选出与while(E)语句中的(E)不能等价的表达式为( )。 A、(!E=0) B、(E>0)|(E<0) C、(E=0) D、(E!=0)三、程序改错题。不得增加语句、删除语句,只能在原句改正。1输入3个数,找出其中最大一个并显示出来。#include <iostream.h>void main() int a,j,k,m; cout<<”请输入3个整数:”; cin<<a<<j<<k; cout<<”3个数中的最大的是:”; if(a<j) j=a; if(a<k) a=k; cout<<a<<endl; 2输入10个数,计算并显示它们的合计。#include <iostream.h>void main()double x,s;cout<<”请输入10个数:”;for(int j=0;j<10;j-) cin>>x; s=x;cout<<”合计:”<<s; 四、编程序题。1设计一个程序,输入4个数,找出其中最小一个并显示出来。 2输入10个整数到一个数组中,调整这10个数在数组中的排列位置,使得其中最小的一个数成为数组的首元素,并输出处理后的数据。 五、写出下列程序运行后的输出结果。 1#include <iostream.h>void main() int s=0; for(int i=1;i<6;i+) s+=i*i; cout<<”s=”<<s<<endl; 2#include <iostream.h>void main() int n=10,y=1; while(n-) y+;+y; cout<<”y*y=”<<y*y<<endl; 3#include <iostream.h>void SB(char ch) switch(ch) case A: case a: cout<<”well!”;break; case B: case b: cout<<”good!”;break; case C: case c: cout<<”pass!”;break; default: cout<<”bad!”;break;void main() char a1=b,a2=C,a3=f; SB(a1);SB(a2);SB(a3);SB(A); cout<<endl;第一次作业参考答案:一、填空题。1. ; 2. 传值 传地址 3. main 4. 局部 5. 4 6. 46 7. 21 8. 64 649. y=x>100?100:0; 10. 7 11. 17 12. 6 5 13. 12 21 14. 8215. 4 16. 143+17=160 17. f=+p+15; 18. x+y>=3 19. a*a*a+3*a*a*a*b+3*a*b*b+b*b*b 20. 类型修饰符 形式参数表二、选择题。1.B 2.D 3.C 4.A 5.B 6.B 7.C 8.C 9.A 10.C三、程序改错题。不得增加语句、删除语句,只能在原句改正。1、cin<<a<<j<<k; 改正为:cin>>a>>j>>k; j=a; 改正为:a=j;2、double x,s; 改正为:double x,s=0; s=x; 改正为:s+=x;四、编程题。1. #include <iostream.h>void main() double a,b,c,d; cout<<”请输入4个数:”; cin>>a>>b>>c>>d; if(a>b) a=b; if(a>c) a=c; if(a>d) a=d; cout<<”最大数是:”<<a;2. #include <iostream.h>void main() int data10,m,j=0; cout<<”请输入10个整数:”; for(m=0;m<10;m+) cin>>datam; for(m=1;m<10;m+) if(datam<dataj) j=m; if(j>0) m=data0;data0=dataj;dataj=m; cout<<endl; for(m=0;m<10;m+) cout<<datam<< ;五、写出下列程序的运行结果。1. s=55 2. y*y=441 3. good!pass!bad!well!"If we don't do that it will go on and go on. We have to stop it; we need the courage to do it."His comments came hours after Fifa vice-president Jeffrey Webb - also in London for the FA's celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint.CSKA general director Roman Babaev says the matter has been "exaggerated" by the Ivorian and the British media.Blatter, 77, said: "It has been decided by the Fifa congress that it is a nonsense for racism to be dealt with with fines. You can always find money from somebody to pay them."It is a nonsense to have matches played without spectators because it is against the spirit of football and against the visiting team. It is all nonsense."We can do something better to fight racism and discrimination."This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrimination can be washed out of football."The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifa's anti-racism taskforce, is in London for the Football Association's 150th anniversary celebrations and will attend City's Premier League match at Chelsea on Sunday."I am going to be at the match tomorrow and I have asked to meet Yaya Toure," he told BBC Sport."For me it's about how he felt and I would like to speak to him first to find out what his experience was."Uefa has opened disciplinary proceedings against CSKA for the "racist behaviour of their fans" during City's 2-1 win.Michel Platini, president of European football's governing body, has also ordered an immediate investigation into the referee's actions.CSKA said they were "surprised and disappointed" by Toure's complaint. In a statement the Russian side added: "We found no racist insults from fans of CSKA."Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunda.The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, he'll be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end.Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes it's not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it won't. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there