阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【程序2.1说明】
已知一个排好序的数组,现输入一个数,要求按原来的顺序规律,将它插入到数组中。
【程序2.1】
include <stdioh>
define N 100
void main()
{
float a[N+l],x;
int i,p;
printf("输入已经排好序的数列: ");
for(i=0; i<N; i++)
scanf(%f",&a[i]);
printf("输入要插入的数:");
scanf("%f",&x);
for(i=0,p=N; i<N; i++)
if(x<a[i])
{
(1)
break;
}
for(i=N-1; i>=p; i--)
(2)
(3)
for(i=0; i<=N; i++)
prinff("%f\t",a[i]);
}
【程序2.2说明】
本程序用变量count统计文件中字符的个数。
【程序2.2】
include <stdio.h>
include <stdlib.h>
void main()
{
FILE *fp;
long count=0;
if((fp=fopen("letter.txt","r"))==NULL)
{
printf("can not open file\n");
exit(0);
}
while(!feof(fp))
{
(4)
count++;
}
printf("count=%d\n",count);
(5)
}
第1题
阅读以下应用说明及Visual Basic部分程序代码,将应填入(n)处的字句写在对应栏内。
【说明】
在窗体上画一个名称为Combo1的组合框,画两个名称分别Labe11、Labe12及Caption属性分别为“城市名称”和空白的标签。程序运行后,当在组合框中输入一个新项后按回车键 (ASCII码为13)时,如果输入的项在组合框的列表中不存在,则自动添加到组合框的列表中,并在Labe12中给出提示“已成功添加输入项”;如果存在,则在Labe12中给出提示“输入项已在组合框中”。
【程序】
Private Sub Combo1 (1) (KeyAscii As Integer)
If KeyAscii=(2) Then
For i=0 To (3)
If Combo1. Text=(4) Then
Labe12. Caption ="输入项已在组合框中"
Exit Sub
End If
Next i
Label2. Caption ="已成功添加输入项"
Combo1. (5) Combo1.Text
End If
End Sub
第2题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【说明】
编写程序,对于从键盘输入的3个实数a、b、c,计算实系数一元二次方程的根并输出所求的根。
【函数】
include<sldio.h>
include<sldlib.h>
include<math.h>
Main()
{
float a,b,c,delta,x1,x2;
printf("Enter a,b,c");
scanf("%f%f%f",&a,&b,&c));
if((1))
if((2))
printf("Input error!\n");
else
printf("The single root is%f\n",(3));
else
{
delta=b*b-4*a*c;
if((4))
{
x1=(-b+sqrt(delta))/(2*a);
x2=(-b-sqrt(delta))/(2*a);
printf("x1=%8.2f\nx2=%8.2f\n",x1,x2,);
}
else if(delta==0)
printf("x1=x2=%8.2f\n",(5);
else
{
Printf("z2=%8.2f+%8.2f*i\n",-b/(2*a),sqrt(-delta)/)(2*abs(a)));
Printf("z2=%8.2f-%8.2f*i\n",-b/(2*a),sqrt(-delta)/(2*abs(a)));
}
}
}
第3题
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
下面程序完成从键盘读入一个字符串,然后采用parseInt方法将其转换为一个相应的整数。
import java.io.*;
public class testThrows{
public static (1) readString() (2) IOException{
int ch;
String r="";
boolean done=false;
while((3)){
ch=System.in.read();
if(ch<0 || ch=0xd) //处理回车符中第一个符号
done=true;
else
r=r+(char)ch;
}
return r;
}
public static void main(Stling args[]){
String str;
(4) {
str=readString();
} (5) (IOException e){
System.out.println("error");
return;
}
System.out.println("input integer: "+Integer.parselnt(str));
}
}
第4题
阅读以下应用说明及Visual Basic程序代码,将应填入(n)处的字句写在答题纸的对应栏内。
应用说明
某单位举办了一场知识竞赛,有300名选手参加竞赛,依次从1~300为选手编号。竞赛时间为9:00~11:00。8道竞赛题目依次从“A”~“H”编号,选手可按任意次序答题,每完成一道题目,可立即提交答案。若答案正确(Y),则选择其他题目进行解答,否则,可继续做该题目或选择其他题目进行解答,直至竞赛结束。
选手提交答案的情况及判定结果由专人即时录入,录入数据包括提交答案的时间、选手编号、题目编号(A~H)、是否正确(Y/N)。
对竞赛情况进行统计和排名的规则如下:
1.若选手X在竞赛时提交的题目P解答正确,则解答该题目所用时间如下计算:
解答题目P的用时=提交题目P正确的时间-竞赛的开始时间+罚时
罚时;提交题目P错误解答的次数×20
例如:设14号选手在10:27提交了题目A的正确解答,则该选手正确解答该题目所用时间为87分钟,由于他在09:37和09:52两次提交了题目A的错误解答,因此罚时为2×20=40分钟,所以14号选手解答题目A的用时=87+40=127(分钟)。
2.已经提交正确答案的题目再次提交时不再计算。
3.竞赛结束时,选手的总用时为所有解答正确的题目用时累加所得,解答不正确的题目不计时。
4.排名时,完成题目数量多者排名靠前;若完成的题目数相同,则用时少者排名靠前:若完成的题目数和所用时间均相等,则名次相同;完成题目数为0的选手不参加排名。
本应用程序的运行窗口如下图所示:
窗口中的两个文本框为Txt_time和Txt_player,分别用于录入提交答案的时间和选手编号。组合列表框Combol提供题目编号(A~H),录入时从中选择。检查框Chk yn用于输入解答是否正确信息。当单击“确定”按钮(Cmd_comfirrn)时,录入的提交信息加入组合列表框Listl中,排名情况在列表框List2输出。单击“关闭”按钮时退出应用程序。
在开发过程中,需要编写的部分程序代码如下:程序代码
Private Tyve Info
no As Integer '选手编号
hum As Integer '完成的题目数量
time As Integer '完成题目的总用时
d(8) As Integer 'd[i]用于记录提交第i个题目错误答案的次数
a(8) As Boolean 'aC[i]用于记录第i个题目是否已经提交正确答案
End Type
Dim R(301) As Info 'R[j]用于统计编号为j的选手提交答案的情况
Dim Maxlndex As Integer 'MaxIndex记录提交答案的选手中编号最大者
Private Sub Form_Load()
For i=1 To 8
Combol.Addltem Chr( (1) )
Next
Combol.Text = Combol.List(0): Txt_time. Text= "": Txt_player. Text= ""
For i = 1 To 300
R(i).num=0: R(i).time = 0: R(i).no = I
Forj = 1 To 8
R(i).d(j) = 0: R(i).a(j) = False
Next j, i
End Sub
Private Sub Crud_confirm_Click()
Dimh, m, k, time As Integer, ch, pass, sl As String
k = InStr(Txt_time.Text, ":"): If k < 2 Then GoTo errorl
h = Val(Left(Txt_time. Text, k - 1 )): m = Val(Mid(Txt_time. Text, k + 1 ))
Ifh > 11 Or h = 11 And m > 0 Or m >= 60 Then GoTo errorl
time=(2) '计算答题时间,以分钟为单位
If Txt player. Text < 1 Or Txt_player. Text> 300 Then GoTo errorl
ch=(3) '取题目编号
pass = llf(Chk_yn. (4)= 0, "N", "Y")
s1 = Txt__time. Text+ Space(4)+ Txt_player. Text
s1 = s1 + Space(10 - Len(Txt_player. Text))+ ch + Space(8) + pass
Listl .Addltem s1
k = Val(Txt_player. Text) 'k为选手编号
R(k).no = k '编号为K的选手的提交信息记录在下标在K的数组元素中
If k > Maxlndex Then Maxlndex = k
m = Asc(ch) - Ase("A")
Ifpass <> "Y" Then '编号为K的选手提交第m个题目的解答不正确
R(k).d(m) = R(k).d(m) + 1
Elself R0(k).a(m) <> True Then '已经提交正确的题目的解答不再计算
R(k).a(m) = True: R(k).num = R(k).num + I
R(k).time = R(k).time +(5)
Call Statistic '调用过程 Statistic 进行实时排名和输出
End If
Exit Sub
errorl: MsgBox "录入信息有误!", vbOKOnly
End Sub
第5题
阅读以下说明和C++代码,将应填入(n)处的字句写在对应栏内。
【说明】
C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为std。vector模板类的部分方法说明如下表所示:
【C++代码】
include <iostream>
include <vector>
using namespace (1);
typedef vector< (2) > INTVECTOR;
const int ARRAY_SIZE = 6;
void ShowVector (INTVECTOR &theVector);
int main() {
INTVECTOR theVector;
// 初始化 theVector, 将theVector的元素依次设置为0至5
for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++}
theVector.push_back((3));
ShowVector(theVector); // 依次输出theVector中的元素
theVector.erase (theVector.begin () + 3};
ShowVector(theVector);
}
void ShowVector (INTVECTOR &theVector) {
if (theVector.empty ()) {
cout << "theVector is empty." << endl; return;
}
INTVECTOR::iterator (4);
for (theIterator=theVector.begin(); theIterator !=theVector.end(); theIterator++) {
cout << *theIterator;
if (theIterator != theVector.end()-1) cout << ", ";
}
cout << end1;
}
该程序运行后的输出结果为:
0,1,2,3,4,5
(5)
第6题
阅读以下说明和C函数,将应填入(n)处的字句写在对应栏内。
【说明】
已知某二叉树的非叶子结点都有两个孩子结点,现将该二叉树存储在结构数组Ht中。结点结构及数组Ht的定义如下:
define MAXLEAFNUM 30
struct node{
char ch; /*当前结点表示的字符,对于非叶子结点,此域不用*/
char *pstr; /*当前结点的编码指针,非叶子结点不用*/
int parent; /*当前结点的父结点,为0时表示无父结点*/
int lchild,rchild;
/*当前结点的左、右孩子结点,为0时表示无对应的孩子结点*/
};
struct node Ht[2*MAXLEAFNUM]; /*数组元素Ht[0]不用*/
该二叉树的n个叶子结点存储在下标为1~n的Ht数组元素中。例如,某二叉树如果其存储结构如下图所示,其中,与叶子结点a对应的数组元素下标为1,a的父结点存储在Ht[5],表示为Ht[1].parent=5。Ht[7].parent=0表示7号结点是树根,Ht[7].child=3、Ht[7].rchild=6分别表示7号结点的左孩子是3号结点、右孩子是6号结点。
如果用0或1分别标识二叉树的左分支和右分支(如上图所示),从根结点开始到叶子结点为止,按所经过分支的次序将相应标识依次排列,可得到一个0、1序列,称之为对应叶子结点的编码。例如,上图中a,b,c,d的编码分别是100,101,0,11。
函数LeafCode(Ht[],n)的功能是:求解存储在Ht中的二叉树中所有叶子结点(n个)的编码,叶子结点存储在Ht[1]~Ht[n]中,求出的编码存储区由对应的数组元素pstr域指示。
函数LeafCode从叶子到根逆向求叶子结点的编码。例如,对上图中叶子结点a求编码的过程如下图所示。
typedef enum Status {ERROR,OK} Status;
【C函数】
Status LeafCode(struct node Ht[], int n)
{
int pc, pf; /*pc用于指出树中的结点,pf则指出pc所对应结点的父结点*/
int i,start;
char tstr[31] = {'\0'}; /*临时存储给定叶子结点的编码,从高下标开始存入*/
for(i = 1;(1); i++){ /*对所有叶子结点求编码,i表示叶结点在HT数组中的下标*/
start = 29;
pc = i; pf = Ht[i].parent;
while (pf !=(2)) { /*没有到达树根时,继续求编码*/
if ((3).lchild == pc ) /*pc所表示的结点是其父结点的左孩子*/
tstr[--start] = '0';
else
tstr[--start] = '1';
pc =(4); pf = Ht[pf].parent; /*pc和pf分别向根方向回退一层*/
}/* end of while */
Ht[i].pstr = (char *) malloc(31-start);
if (!Ht[i].pstr) return ERROR;
strcpy(Ht[i].pstr,(5));
}/* end of for */
return OK;
}/* and of LeafCode */
第7题
阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。
【说明】
本程序的功能是实现任意两个大整数的乘法运算,例如:
输入整数1:8934793850094505800243958034985058
输入整数2:234584950989689084095803583095820923
二者之积:
209596817742739508050978890737675662366433464256830959194834854876 8534
【C++代码】
include<iostream.h>
const int MAXINPUTBIT=100;
const int MAXRESULTBIT=500;
class LargeNumber{
int i,j;
int temp;
int one[MAXINPUTBIT+1];
int onebit; //one的位数
int two[MAXINPUTBIT+1];
int twobit; //two的位数
int result[MAXRESULTBIT+1];
public:
LargeNumber();
~LargeNumber();
int inputone(); //出错返叫0,否则返回1
int inputtwo(); //同上
void multiplication(); //乘
void clearresult(); //清零
void showresult(); //显示
};
LargeNumber∷LargeNumber()
{
for(i=0;i<=MAXINPUTBIT;i++)
{
one[i]=0;
two[i]=0;
}
nebit=0;
twobit=0;
inputone();
inputtwo();
}
LargeNumber∷~LargeNumber()
{
}
int LargeNumber∷inputone()
{
char Number[MAXINPUTBIT+1];
cout<<"Please enter one:";
cin>>Number;
i=0;
j=MAXINPUTBIT;
while(Number[i]!='\0')
i++;
nebit=i;
for(i--;i>=0;i--,j--)
{
if(int(Number[i])>=48&&int(Number[i])<=57)
(1); //由字符转换为数字
else
return 0;
}
return 1;
}
int LargeNumber∷inputtwo()
{
char Number[MAXINPUTBIT+1];
cout<<"Please enter two:";
cin>>Number;
i=0;
j=MAXINPUTBIT;
while(Number[i]!='\0')
i++;
twobit=i;
for(i--;i>=0;i--,j--)
{
if(int(Number[i])>=48&&int(Number[i])<=57)
two[j]=int(Number[i]-48); //由字符转换为数字
else
return 0;
}
return 1;
}
void LargeNumber∷multiplication() //乘法
{
clearresult();
int m;
for(i=MAXINPUTBIT;i>=0;i--)
{
temp=two[i];
for(j=(2),m=MAXINPUTBIT;m>=0;m--,j--)
{
result[j]+=temp*one[m];
if(result[j]>9)
{
result[j-1]+=result[j]/10;
(3);
}
}
&n
第8题
阅读以下程序说明和C语言程序,将应填入(n)处的字句写在对应栏内。
【说明】
希赛教育集团公司为发展生产向社会公开招聘M个工种的工作人员,每个工种各有不同的编号(1至M)和计划招聘人数。每位应聘者需申报两个工种,并参加公司组织的考试。公司将按应聘者的成绩从高分至低分的顺序进行排队录取。公司的录取原则是:从高分到低分依次对每位应聘者先按其第一志愿录取;当不能按其第一志愿录取时,便将他的成绩扣去5分后,重新排队,并按其第二志愿考虑录取。
程序为输出各工种实际招聘的应聘人员,每个工种都保留一个录取者的有序队列。录取处理循环直至招聘额满或已对全部应聘者都做了录取处理。
程序中,类型STU包含有应聘者的基本信息:编号、成绩、志愿、排队成绩和录取志愿号。数组rz[]的每个元素对应一个工种,包含有计划招聘人数和已录取的人数。
【程序】
include<stdio.h>
include<malloc.h>
define M 20
define PEMARK 5
typedef struct stu{
int no, total, z[2], sortm, zi;
struct stu *next;
}STU;
struct rzmode{
int Imt, count;
STU *next;
}rz[M];
STU *head=NULL, *over=NULL;
int all
FILE *fp;
char dataf[]="pp07.dat";
print(STU *p){
for(;p!=NULL;p=p->next)
printf("%d(%d)\t",p->no,p->total);
}
insert(STU **p, STU *u){
STU *v, *q;
for(q=*p;q!=NULL;v=q,(1))
if(q->sortm<u->sortm)break;
if(q==*p)(2);
else (3);
U->next=q;
}
main(){
int zn, i, no, total, z1, z2;
STU *p, *v, *q;
fp=fopen(dataf, "r");
if(fp==NULL){
printf("Can't open file %s.\n",dataf);
exit(0);
}
fscanf(fp, "%d",&zn);
for(all=0,i=1;i<=zn;i++){
fscanf(fp,"%d",&rz[i].Imt);
rz[i].count=0;rz[i].next=NULL;
all+=(4);
}
for(;;){
if((fscanf(fp, "%d%d%d%d",&no,&total,&z1,&z2))!=4)
break;
p=(STU*)malloc(sizeof(STU));
p->no=no;
p->total=p->sortm=total;
p->zi=0;p->z[0]=z1;p->z[1]=z2;
(5);
}
fclose(fp);
for(;all && head !=NULL;){
p=head; head=head->next;
if(rz[p->z[p->zi]].count<(6)){
rz[p->z[p->zi]].count++;
insert(&rz[p->z[p->zi]].next,p);
all--;
continue;
}
if(p->zi>=1){
p->next=over;over=p;
continue;
}
p->sortm-=DEMARK; (7);
insed(&head,p);
}
for(i=1;i<=zn;i++){
printf("%d:\n",i);
print(rz[i].next);
printf("\n");
}
printf("over:\n");print(head);
print(over);printf("\n");
}
第9题
阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。
【说明】
本程序利用非递归算法实现二叉树后序遍历。
【函数】
include<stdio.h>
include<stdlib.h>
typedef struct node{/*二叉树的结点数据结构类型*/
char data;
struct node *left;
struct node *right;
}BTREE;
void SortTreelnsert(BTREE **tree, BTREE *s)
{
if(*tree==NULL)*tree=s;
else
if(s->data<(*tree)->data)
SortTreelnsert((1),s);
else if(s->data>=(*tree)->data)
SortTreelnsert((2),s);
}
void TraversalTree(BTREE *tree)
{
BTREE *stack[1 000],*p;
int tag[1000],top=0;
p=tree;
do{
while(p !=NULL)
{
stack[++top]=p;
(3);
tag[top]=0; /*标记栈顶结点的左子树已进行过后序遍历*/
}
while(top>0&&(4))/*栈顶结点的右子树是否被后序遍历过*/
{
p=stack[top--];
putchar(p->data);
}
if(top>0)/*对栈顶结点的右子树进行后序遍历*/
{
(5);
tag[top]=1;
}
}while(top>0);
}
void PrintSortTree(BTREE *tree)
{
if(tree !=NULL)
{
printSortTree(tree->left);
putchar(tree->data);
pdntSortTree(tree->right);
}
}
main()
{
BTREE *root=NULL, *node;
char ch;
ch=getchar();
while(ch !='')
{
node=(BTREE*)malloc(sizeof(BTREE));
node->data=ch;
node->left=node->right=NULL;
SortTreelnsert(&root, node);
ch=getchar();
}
PrintSortTree(root);
putchar('\n');
TraversalTree(root);
}
第10题
阅读以下说明和Java代码,将解答写入对应栏内。
【说明】
下面的程序的功能是利用实现Runnable接口的方法来创建线程,并利用它来执行响应的一些操作。最后使得m的执行结果:100,如图3。
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
class ClassName (1) Runnable {
int n;
(2) {
try{
Thread. sleep (2000);
n=100;
}catch( (3) e) {}
}
public static void main(String[ ]args) {
try{
ClassName a = new ClassName( );
(4)
threadl. (5) ();
threadl, join( );
int m=a.n;
System. out. println("m=" + m);
}catch( (3) e){}
}
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!