A.while语句
B.do... while语句
C.for语句
D.if... else语句
第1题
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第2题
阅读以下说明和C++码,将应填入(n)处的字名写在对应栏内。
从下列的3道试题(试题五至试题七)中任选1道解答。
如果解答的试题数超过1道,则题号小的1道解答有效。
[说明] 编写程序,把从键盘上输入的一批整数(以-1作为终止输入的标志)保存到文本文件“a: xxk1. dat”中。
(1)
include <fstream. h >
include < stdlib. h >
void main () {
(2)
if (! four) {
cerr < <“文件没有找开!” < <end1;
exit (1);
}
int x;
cin > >x;
while((3)){
(4)
cin> >x;
}
(5)
}
第3题
阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明]
完成以下中序线索化二叉树的算法。
[函数]
Typedef int datatype;
Typedef struct node {
Int ltag, rtag;
Datatype data;
*lchild,* rchild;
}bithptr;
bithptr pre;
void inthread (p );
{if
{inthread (p->lchild );
if (p->lchild==unll ) (1);
if (P->RCHILD=NULL) p->rtag=1;
if (2)
{if (3) pre->rchild=p;
if (p->1tag==1 )(4);
}
INTHREAD (P->RCHILD );
(5);
}
}
第4题
() 阅读下列说明和C++代码,将应填入空(n)处的字句写在答题纸的对应栏内。【说明】 某中学开展中外中学生野外生存夏令营活动,由于中外学生的语言障碍,随队为外籍学员配置一名翻译。以下代码采用适配器(Adapter)模式模拟翻译适配器。其类图如下:
第5题
阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。
【说明】
在下面函数横线处填上适当的字句,使其输出结果为:
构造函数.
构造函数.
1,2
5,6
析构函数
析构函数.
【C++代码】
include "iostream.h"
class AA
{ public;
AA(int i,int j)
{A=i; B=j;
cout<<"构造函数.\n";
}
~AA(){(1);}
void print();
private:
int A, B;
};
void AA∷print()
{cout<<A<<","<<B<<endl;}
void main()
{
AA *a1, *a2;
(2)=new AA(1, 2);
a2=new AA(5, 6);
(3);
a2->print();
(4) a1;
(5) a2;
}
第6题
阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。
【说明】
已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:
第7题
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。
【说明】
阅读下面几段C++程序回答相应问题。
比较下面两段程序的优缺点。
①for (i=0; i<N; i++ )
{
if (condition)
//DoSomething
…
else
//DoOtherthing
…
}
②if (condition) {
for (i =0; i<N; i++ )
//DoSomething
}else {
for (i=0; i <N; i++ )
//DoOtherthing
…
}
第8题
阅读以下说明和Java码,将应填入(n)处的字名写在对应栏内。
[说明] 编写一个字符界面的Java Application 程序,接受用户输入的10个整数,并输出这10个整数的最大值和最小值。
import java. io. * ;
public class abc
{
public static void main(String args [ ] )
{ int i, n = 10 , max = 0 , min = 0 , temp = 0;
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(System. in) );
(1));
} catch (IOException e ) { } ;
for(i = 2 ;i <= n; i ++ ) {
try {
BufferedReader br = new BufferedReader(
new InputStreamReader (System. in) );
temp = Integer. parselnt(br. readLine() );
if (temp > max ) (2)
if (temp < min) (3)
} catch (IOExeeption e ) { } ;
System. out. println("max =" + max + "\nmin =" + min);
}
}
第9题
阅读以下说明和c++码,将应填入(n)处的字名写在对应栏内。
[说明] 从键盘输入一个字符ch,输出该字符在文本文件input.txt 的每一行中出现的次数。(必须调用函数鳋统计ch的出现次数,函数ff (str,ch)的功能是统计并返回字符ch在字符串str 中出现的次数。)。
例如:如果文件input. txt 中存放了下列数据:
every
121
I am a student
运行程序,并输入e后,输出:
2
0
1
int ff(char * str, char ch)
{ int count =0;
while ((1)) {
if(*str= =ch) count++;
str ++;
}
return count;
}
include < stdio. h >
include < stdlib. h >
void main()
{ char ch, c, s [80];
int k;
FILE *fp;
if((2)){
printf(“打不开文件!n”); return;
}
ch = getchar();
k=0;
while(! feof(fp) ) {
c = fgete(fp);
if (3)
s[k++ ] =c;
else {
s[k]= ";
printf ("%dn" ,ff(s, ch) );
k=0;
}
}
(4)
printf("% dn", ff(s, ch ) );
}
第10题
阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序为求行列式X(5,5)的值S。
【Visual Basic代码】
Private Function col (byval x (5,5 ) as integer ) as long
dim fesult as long
dim temp as long
dim I as integer
dim j as integer
dim k as imeger
result = 0
for I = to 5
(1)
for j = 1 to 5
if I+j>6 then
k= (1+j ) mod 5
else
k=1
endif
temp=temp*x (k,j )
(2)
result=(3)
(4)
(5)
End function
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!