超前自学网

 找回密码
 立即注册

奥鹏在线作业,2元一门,先做后付,微信424329

查看: 116|回复: 0

20春学期《C++程序设计》在线平时作业1

[复制链接]

3万

主题

3万

帖子

9万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
95816
发表于 2020-8-8 18:58:39 | 显示全部楼层 |阅读模式
微信公众号:超前自学网
点击这里
(37)下列程序的运行结果是<br><br>void fun(int *a, int *b)<br>{ int *k;<br>k=a; a=b; b=k;<br>}<br>main()<br>{<br>&nbsp;int a=3, b=6, *x=&amp;a, *y=&amp;b;<br>fun(x,y);<br>cout&lt;&lt;a&lt;&lt;b;<br>}
A:A) 6 3&nbsp;
B:B) 3 6&nbsp;
C:C)&nbsp;编译出错
D:D) 0 0

(14)在执行以下程序时,为了使输出结果为:t=4,则给a和b输入的值应满足的条件是<br>#include &lt;iostream&gt;<br>#include &lt;cmath&gt;<br>using namespace std;<br>int main(int argc, char* argv[])<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int s,t,a,b;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cin&gt;&gt;a&gt;&gt;b;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s=1, t=1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(a&gt;0) s=s+1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(a&gt;b) t=s+1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else if (a==b)&nbsp;&nbsp;t=5;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;&nbsp;t=2*s;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;t ;<br>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br>}<br>&nbsp; &nbsp; &nbsp;&nbsp;
A:A)a&gt;b &nbsp;&nbsp;
B:&nbsp;&nbsp;B)a&lt;b&lt;0 &nbsp;&nbsp;
C:&nbsp; &nbsp;C)0&lt;a&lt;b &nbsp; &nbsp;&nbsp;
D:&nbsp; &nbsp; &nbsp; &nbsp;D)0&gt;a&gt;b

&nbsp;若有以下程序片段:&nbsp;<br>char&nbsp;str[]="ab\n\012\\\"";&nbsp;<br>cout&lt;&lt;strlen(str);&nbsp;<br>上面程序片段的输出结果是&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br><br>
A:A)3 &nbsp; &nbsp;
B:&nbsp;B)4 &nbsp; &nbsp;&nbsp;
C:&nbsp;C)6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
D:&nbsp; &nbsp;D)12

<br>(4)&nbsp;&nbsp;&nbsp; 有如下程序:<br>#include&lt;iostream&gt;<br>using namespace std;<br>class MyClass{&nbsp;<br>public:<br>&nbsp;&nbsp;&nbsp; MyClass(int x):val(x){}<br>&nbsp;&nbsp;&nbsp; void Set(int x){val=x;}&nbsp;<br>&nbsp;&nbsp;&nbsp; void Print()const{cout&lt;&lt;"val="&lt;&lt;val&lt;&lt;'\t';}<br>private:&nbsp;<br>&nbsp;&nbsp;&nbsp; int val;&nbsp;<br>};<br>int main(){<br>&nbsp;&nbsp;&nbsp; const MyClass obj1(10);<br>&nbsp;&nbsp;&nbsp; MyClass obj2(20);<br>&nbsp;&nbsp;&nbsp; obj1.Print();&nbsp;&nbsp;&nbsp; //语句 1<br>&nbsp;&nbsp;&nbsp; obj2.Print();&nbsp;&nbsp;&nbsp; //语句 2<br>&nbsp;&nbsp;&nbsp; obj1.Set(20);&nbsp;&nbsp; //语句 3<br>&nbsp;&nbsp;&nbsp; obj2.Set(30);&nbsp;&nbsp; //语句 4<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br>其主函数中错误的语句是()。&nbsp;<br><br><br>
A:A)语句 1&nbsp;
B:B)语句 2&nbsp;
C:<br>C)语句 3&nbsp;<br><br>
D:D)语句 4

(22)若有定义:int x=0, *p=&amp;x;,则语句&nbsp;&nbsp;&nbsp;cout&lt;&lt;*p;的输出结果是<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp;
A:A)随机值&nbsp;
B:&nbsp;&nbsp; &nbsp;B)0 &nbsp;&nbsp;
C:&nbsp; &nbsp; &nbsp; &nbsp;C)x的地址 &nbsp; &nbsp; &nbsp; &nbsp;
D:&nbsp; &nbsp;D)p的地址

(26)在C++语言中,不合法的实型数据的是( )<br>&nbsp;
A:A)0.123&nbsp;
B:B)123e3
C:&nbsp;C)2.1e3.5&nbsp;
D:&nbsp;D)123.0

在以下四组中,每组有两个分别运算的函数,运算结果相同的是<br>int main(int argc, char* argv[])<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;int i, j, m=0, n=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;for(i=0; i&lt;2; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(j=0; j&lt;2; j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(j&gt;=i) m=1; n++;<br>&nbsp;&nbsp;&nbsp;&nbsp;cout&lt;&lt;n;<br>}<br>&nbsp; &nbsp; &nbsp;&nbsp;<br><br>
A:A) 4&nbsp;
B:B)&nbsp;2&nbsp;
C:C) 1 &nbsp;
D:D) 0<br>&nbsp;<br><br>

(2)&nbsp;&nbsp;&nbsp; 有如下程序:<br>#include&lt;iostream&gt;&nbsp;&nbsp;<br>using namespace std;<br>class MyClass{&nbsp;<br>public:&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; MyClass(int i=0){cout&lt;&lt;1;}<br>&nbsp;&nbsp;&nbsp; MyClass(const MyClass&amp;x){cout&lt;&lt;2;}<br>&nbsp;&nbsp;&nbsp; MyClass&amp; operator=(const MyClass&amp;x){cout&lt;&lt;3; return*this;}&nbsp;<br>&nbsp;&nbsp;&nbsp; ~MyClass(){cout&lt;&lt;4;}<br>};<br>int main()<br>{<br>&nbsp;&nbsp;&nbsp; MyClass obj1(1),obj2(2),obj3(obj1);<br>return 0:<br>}<br>运行时的输出结果是(&nbsp;)。<br><br>
A:A)112444
B:&nbsp;B)11114444
C:&nbsp;C)121444
D:&nbsp;D)11314444

)以下不合法的用户标识符是<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp;<br>
A:A)j2_KEY &nbsp;
B:&nbsp; B)Double &nbsp;
C:&nbsp;&nbsp; C)4d &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
D:&nbsp; &nbsp; D)_8_

&nbsp;&nbsp;有以下程序段<br>typedef&nbsp;struct&nbsp;node {&nbsp;int&nbsp; data;&nbsp;&nbsp;struct&nbsp; node&nbsp; *next;&nbsp; } *NODE;<br>NODE&nbsp; p;<br>以下叙述正确的是<br><br><br><br><br>
A:A)p是指向struct&nbsp;node结构变量的指针的指针
B:B)NODE&nbsp; p;语句出错
C:C)p是指向struct&nbsp;node结构变量的指针<br><br>
D:D)p是struct&nbsp;node结构变量<br><br>

算法中,对需要执行的每一步操作,必须给出清楚、严格的规定,这属于算法的<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br><br>
A:A)正当性&nbsp;
B:B)可行性 &nbsp;
C:&nbsp;C)确定性&nbsp;&nbsp;&nbsp;&nbsp;
D:&nbsp; D)有穷性

有以下程序<br>main()<br>{<br>char a1='M',a2='m';<br>&nbsp;&nbsp;cout&lt;&lt;(a1,a2)&lt;&lt;endl;<br>}<br>以下叙述中正确的是<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br><br>&nbsp;<br><br>
A:A)程序输出大写字母M &nbsp;
B:&nbsp;B)程序输出小写字母m
C:C)格式说明符不足,编译出错 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
D:&nbsp; &nbsp; D)程序运行时产生出错信息

(8)&nbsp;&nbsp;&nbsp; 有如下程序<br>#include &lt;iostream&gt;<br>#include &lt;fstream&gt;<br>using namespace std;<br>int main( ){<br>&nbsp;&nbsp;&nbsp; cout&lt;&lt;setw(8)&lt;&lt; _&lt;&lt;12.345&lt;&lt;setw(8)&lt;&lt;_&lt;&lt;34.567;<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br>若程序的输出是:<br>**12.345**34.567<br>则程序中下划线处遗漏的操作符是&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;
A:A)setprecision(3)&nbsp;
B:&nbsp;B)fixed&nbsp;&nbsp;
C:&nbsp;C)setfill('*')&nbsp; &nbsp; &nbsp;
D:D)setw(8)

&nbsp;<br>(2)&nbsp;&nbsp;&nbsp; 在 C++中,编译系统自动为一个类生成缺省构造函数的条件是( )。<br><br><br>
A:A)该类没有定义任何有参构造函数
B:B)该类没有定义任何无参构造函数
C:<br>C)该类没有定义任何构造函数<br><br>
D:D)该类没有定义任何成员函数

下列符号中,不正确的&nbsp;C++标识符是&nbsp;&nbsp;。<br>&nbsp;<br>
A:A)WHILE&nbsp;
B:B)user
C:C)_lvar&nbsp;
D:D)9stars<br><br>

&nbsp;若有以下定义和语句:<br>     char *s1="12345",*s2="1234";&nbsp;<br>     cout&lt;&lt;strlen(strcpy(s1,s2));&nbsp;<br>则输出结果是&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
A:A)4 &nbsp; &nbsp;&nbsp;
B:&nbsp; B)5 &nbsp; &nbsp;
C:&nbsp;&nbsp;C)9 &nbsp; &nbsp;<br>
D:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;D)10<br><br>

(9)&nbsp;&nbsp;&nbsp; .以下关于C++类的说法中正确的是( )<br><br><br><br>
A:A) C++语言的默认访问权限是private
B:B) C++语言中的类定义,用户一定要自己定义一个构造函数用于实例化类
C:C) C++语言中的成员函数的实现部分一定要写在类定义外<br><br>
D:D) C++语言中的类不能够嵌套定义 <br><br>

(2)&nbsp;&nbsp;&nbsp; 要利用 C++流进行文件操作,必须在程序中包含的头文件是( )。&nbsp;<br><br>
A:A)iostream
B:B)fstream&nbsp;
C:&nbsp;C)strstream
D:&nbsp;D)iomanip

(38)&nbsp;&nbsp;有如下说明<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;a[10]={1,2,3,4,5,6,7,8,9,10},*p=a;<br>则数值为9的表达式是<br>&nbsp; &nbsp;
A:&nbsp;A)*p+9
B:&nbsp; B)*(p+8)&nbsp;
C:&nbsp;C)*p+=9 &nbsp; &nbsp; &nbsp;&nbsp;
D:&nbsp; &nbsp; &nbsp;D)p+8

(8)&nbsp;&nbsp;&nbsp; 有如下程序<br>#include<br>#include<br>using namespace std;<br>class MyClass{<br>public:<br>&nbsp;&nbsp;&nbsp; MyClass( ){ cout&lt;&lt;'A'; }<br>&nbsp;&nbsp; &nbsp;MyClass(char c){ cout&lt;&nbsp;&nbsp;&nbsp; ~MyClass( ){ cout&lt;&lt;'B'; }<br>};<br>int main( ){<br>&nbsp;&nbsp;&nbsp; MyClass p1,*p2;<br>&nbsp;&nbsp;&nbsp; p2=new MyClass('X');<br>&nbsp;&nbsp;&nbsp; delete p2 ;<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br>执行这个程序屏幕上将显示输出<br>&nbsp; &nbsp; &nbsp;&nbsp;
A:&nbsp;A)ABX&nbsp; &nbsp; &nbsp;
B:&nbsp;B)ABXB&nbsp; &nbsp; &nbsp; &nbsp;
C:&nbsp;&nbsp;C)AXB&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
D:&nbsp; &nbsp;D)AXBB

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|超前自学网 ( 皖ICP备20014425号-1 )|网站地图

GMT+8, 2025-5-1 05:40

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表