填空题[说明]下面的流程图,用来完成计算一组数组中的中值,其方法是:将数组中的一个值与其他值比较,并计算大于等于被比较数的数值的个数,以及小于等于被比较数的数值的个数,如果两数都大于n/2,则已经找到了中值,否则继续之前的步骤。注:流程中循环开始的说明按照“循环变量:循环初值,循环终值,增量”格式描述。[问题]将流程图的(1)~(5)处补充完整。
填空题[说明] 本程序求3~100之间的所有素数(质数)并统计个数;同时将这些素数从小到大依次写入顺序文件 E:/dataout.txt;素数的个数显示在窗体Form1上。 [Visual Basic 代码] Private Sub Command1 Click ( ) Dim count as integer, flag as Boolean Dim t1 as Integer, t2 as Integer (1) Count=0 For t1=3 to 100 (2) For t2=2 to Int (Sqr (t1)) If (3) Then flag=False Next t2 (4) count=count +1 write #1, t1 End if Next t1 (5) Close #1 End Sub
填空题[说明] 设一个环上有编号为0~n-1的n粒颜色不尽相同的珠子(每粒珠子颜色用字母表示,n粒珠子的颜色由输入的字符串表示)。从环上的某两粒珠子间剪开,则环上珠子形成一个序列然后按以下规则从序列中取走珠子:首先从序列左端取走所有连续的同色珠子; 然后从序列右端在剩下的珠子中取走所有连续的同色珠子,两者之和为该剪开处可取走珠子的粒数。在不同位置剪开,能取走的珠子也不尽相同。 本程序所求的是在环上哪个位置剪开,按上述规则可取走的珠子粒数最多。程序中用数组存储字符串。例如:10粒珠子颜色对应字符串为“aaabbbadcc”,在0号珠子前剪开,序列为aaabbbadcc,从左端取走3粒a色珠子,从右端取走2粒c色珠子,共取走5粒珠子。若在3号珠子前剪开,即bbbadccaaa,共取走6粒珠子。 [函数] int count (char *s,int start,int end) int i,c=0, color=s[start],step=(start>end)?-1:1; for i=start; s[i] ==color; i+=step) if (step>0 && i>end || (1) ) break; (2) ; return c: void main() char t,s[120]; int i,j,c,len,maxc,cut=0; printf("请输入环上代表不同颜色珠子字符串:"); scanf("%s”,s); len=strlen(s); for (i=maxc=0; i<len; i++)( /*尝试不同的剪开方式*/ c=count (s, 0,len-1); if(c<len) c+=count( (3) ); if (c>maxc)cut=i; maxc=c; /*数组s的元素循环向左移动一个位置*/ t=s[0]; for(j=1; j<len; j++) (4) ; (5) ; printf("在第%d号珠子前面剪开,可以取走%d个珠子./n",cut,maxc);
填空题阅读以下说明和Java程序,将应填入 (n) 处的字句写在对应栏内。 [说明] 下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。 [Java程序] public class MainJava public static void main(String[] args) Lot_size small=new Lot_size(); Lot_size medium=new Lot_size(); small.set(5,5,5,25); medium.set(10,10,10,50); System.out.println("For a small lot of area" +small.get_area()+"/n"); System.out.println("the actual crops are $" +small.get_data2()+"/n"); System.out.println("and ideal crops are $" +small.get data()+"/n"); System.out.println("For a medium lot of area" +medium.get_area()+“/n”); System.out.println("the actual crops are $" +medium.get_data2()+"/n"); System.out.println ("and ideal crops are $" +medium.get_data()+"/n"); class Crop_assessment private int actual_crop; private int ideal_crop; public void set(int in_actual,int in ideal) actual_crop=in_actual; ideal_crop=in_ideal; public int get_actual_crop()return (1) ; public int get_ideal_crop()(return (2) ;class Lot_size private int length; private int width; private Crop_assessment crop= (3) ; public void set(int 1,int W,int a,int i) length=1; width=W; crop.set(a,i); public int get_area()return length*width; public int get_data()freturn (4) ; public int get_data2()(return (5) ;
填空题【说明】
输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
【函数】
main ( )
{
int number[10];
input (number);
max min (number);
output (number);
}
input (number)
int number[10];
{int i;
for ( i=0;i<9;i++ )
scanf ( "%d,",
scanf ( "%d",
}
max_min ( array )
int array[10];
{int *max,*min,k,1;
int *p,*arr_end;
arr end={{U}} (1) {{/U}};
max=min=array;
for ( p={{U}} (2) {{/U}};p<arr_end;p++ )
if({{U}} (3) {{/U}}) max=p;
else if ( *p<*min ) min=p;
{{U}}(4) {{/U}};
l=*min;
{{U}}(5) {{/U}};array[0]=1;1=*p;
*p=array[9];array[9]=k;k=*p;
return;
}
output ( array )
int array[10];
{ int *p;
for ( p=array;p<array+9;p++ )
printf ( "%d,",*p );
printf ( "%d/n",array[9] );
}
填空题【说明】 以下程序为求行列式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
填空题阅读以下函数说明和C语言函数,将应填入 (n) 处的字句写在对应栏内。 [说明] 本程序实现对指定文件内的单词进行计数。其中使用二叉树结构来保存已经读入的不同单词,并对相同单词出现的次数进行计数。此二叉树的左孩子结点的字符串值小于父结点的字符串值,右孩子结点的字符串值大于父结点的字符串值。函数getword(char*filename,char*word)是从指定的文件中得到单词。char*strdup(char*S)是复制S所指向的字符串,并返回复制字符串的地址。 [C程序] #include <stdio.h> #include <ctype.h> #include <string.h> #define MAXWORD 100 struct node char*word; int count; struct node*left; struct node*right; struct node*addtree(struct node*P,char*w) int cond; if(p==NULL) /*向树中插入结点*/ P=(struct node*)malloc(sizeof(struct node)); P->word=strdup(w); P->count=1; (1) ; elseif((oond=strcmp(w,p->word))==0) (2) ; else if(cond<0)p->left= (3) ; else p->right= (4) ; return p; main() Struct node*root; char word[MAXWORD]; root=NULL; filename="example.dat"; while(getword(filename,word)!=EOF)) root= (5) ;
填空题【说明】设计一个评选优秀教师和学生的程序,其类结构如图6所示。当输入一系列教师或学生的记录后,将优秀学生及教师的姓名列出来。【程序】#include<iostream.h>#include<stdio.h>enumboolean{False,True}classbase{protected:charname[8];public:voidgetname(){cout<<"姓名:";cin>>name;}voidprintname(){cout<<"姓名:"<<name<<endU3virtualbooleanisgood()=0;}classstudent:{{U}}(1){{/U}}{intnum;public:voidgetnum()cout<<"考试成绩:"cin>>num;booleanisgood(){return{{U}}(2){{/U}};{};classteacher:{{U}}(3){{/U}}publicbaseintnum;public:voidgetnum()cout<<"每年发表论文数:";cin>>num;booleanisgood(){return{{U}}(4){{/U}};}};voidmain()base*p[50];student*pstud;teacher*ptech;charch;intcount=0;docout<<"输入教师(t)或学生(s):"cin>>ch;if(ch=='s'){pstud=newstudent;pstud->getname();pstud->getnum();p[count++]=pstud;}elseif(ch=='t'){ptech=newteacher;ptech->getname()ptech->getnum();p[count++]=ptech;}elsecout<<"输入错误<<endl;cout<<"继续输入码(Y/n)";cin>>ch;}while(ch=='y')for(inti=0;i<count;i++){ if({{U}}(5){{/U}})//若为优秀,则输出p[i]->printname();}}
填空题阅读以下函数说明和C语言函数,回答问题。 [说明] 为参加网球比赛的选手安排比赛日程。 设有n(n=2k)位选手参加网球循环赛,循环赛共进行n-1天,每位选手要与其他n-1位选手赛一场,且每位选手每天赛一场,不轮空。试按此要求为比赛安排日程。 设n位选手被顺序编号为1,2,…,n。比赛的日程表是一个n行n-1列的表,i行j列的内容是第i号选手第j天的比赛对手。用分治法设计日程表,就是从其中一半选手(2m-1位)的比赛曰程,导出全体(2m位)选手的比赛日程。从只有2位选手的比赛日程出发,反复这个过程,直到为n位选手安排好比赛日程为止。 [C函数] #include<stdio.h> #define MAXN 64 int a[MAxN+1][MAXN]; void main() int twoml,twom,il,j,m,k; printf("指定n(n=2的k次幂)位选手,清输入k。/n"); scanf("%d", a[1][1]=2; /*预设2位选手的比赛日程*/ a[2][1]=1; m=1;twoml=1; while(m<k) (1) ; twoml+=twoml; /*为2m位选手安排比赛日程*/ (2) ; /*填日程表的左下角*/ for(il=twoml+l;il<=twom;i1++) for(j=1;j<=twoml-1; j++) a[i1][J]=a[i1-twoml][j]+twoml; (3) ; for(i1=2;i1<=twom;i1++)a[i1][twoml]=a[i1-1][twom1]+l; for(j=twoml+1;j<twom;j++) for(i1=1;i1<twoml;i1++) a[i1][j]=a[i1+1][j-1]; (4) ; /*填日程表的右下角*/ for(j=twoml;j<twom;j++) for(ii=i;i1<=twoml;i1++) (5) ; for(i1=1;i1<=twom;i1++) for(j=1;J<twom;j++) printf("%4d",a[i1][J]); printf("/n"); printf("/n");
填空题[说明] 从文件in.dat中读取一篇英文文章存入到字符串数组xx中,以行为单位对行中以空格或标点符号为分隔的所有单词进行倒排。最后把已处理的字符串(应不含标点符号)仍按行重新存入字符串数组xx中,最后把结果xx输出到文件OUT6.DAT中。 原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。 [函数] #include<string.h> #include<conio .h> #include<ctype.h> #include<stdio.h> char xx[50][80]; int maxline = 0 ; /*文章的总行数*/ int ReadDat (void) ; void WriteDat (void) ; void StrOL(void) char *p1,*p2,t [80]; int i; for (i=0; i<maxline; i++) p1=xx[i];t[0]=0; while (*p1) p1++; while (p1>=xx [i]) while (! isalpha (*p1) &&p1 ! =xx [i]) p1--; p2 =p1; while( (1) )p1--; if (p1==xx [i]) if (isalpha (*p1) p1--; else if (! isalpha (* (p1+1;)) break; p2++; (2) ; strcat (t,p1+1) ; strcat (t, " ") ; strcpy (xx [i] ,t) ; void main if( (3) ) printf ("数据文件in.dat不能打开! /n/007") ; return; StrOL (); writeDat (); getch; int ReadDat (void) FILE *fp; int i=0; char *p; if ((fp=fopen ("e://a///in.dat " , "r")) ==NULL) return 1; while (fgets (xx [i] , 80, fp) ! =NULL) p=strchr (xx [i] , '/n') ; if(p)*p=0 i++ ; maxline= (4) ; fclose (fp); return 0; void WriteDat (void) FILE *fp; int i; fp=fopen("e: //a//out6 .dat" ,"w"); for (i=0; i<( (5) ) ; i++) printf("%s/n" ,xx [i]); fprintf (fp, "%s/n", xx[i]); fclose(fp);
填空题阅读以下函数说明和C语言函数,将应填入{{U}} (n) {{/U}}处的字句写在对应栏内。 [说明] 这是一个求解Josephus问题的函数。用整数序列1,2,3…,n表示顺序围坐在圆桌周围的人,并采用数组表示作为求解过程中使用的数据结构。Josephus问题描述,设n个人围坐在一个圆桌周围,现在从第s个人开始报数,数到第m个人,让他出局;然后从出局的下一个人重新开始报数,数到第m个人,再让他出局,…如此反复直到所有的人全部出局为止。 [C函数] void Josephus(int A[],int n,s,m) (int i,j,k,temp; if(m==O){ printf("m=0是无效的参数!/n"); return; } for(i=0;i<n;i++) A[i]=i+1; /*初始化,执行n次*/ i={{U}} (1) {{/U}} /*报名起始位置*/ for(k=n;k>1;k-){ if({{U}} (2) {{/U}}) i=0; i={{U}} (3) {{/U}} /*寻找出局位置*/ if(i!=k-1){ tmp=A[i]; for(j=i;J<k-1;j++){{U}} (4) {{/U}}; {{U}}(5) {{/U}}; } } for(k=0;k<n/2;k++){ tmp=A[k];A[k]=A[n-k+1];A[n-k+1]=tmp; } }
填空题阅读以下函数说明和C语言函数,回答问题。 [说明1] 函数void convelt(chal *a,int n)是用递归方法将一个正整数n按逆序存放到一个字符数组a中,例如,n=123,在a中的存放为'3'、'2'、'1'。 [C函数1] void convert(char *a,int n) int i; if((i=n/10)!=0; convert( (1) ,i); *a= (2) ; [说明2] 函数int index(char *s,char *t)检查字符串s中是否包含字符串t,若包含,则返回t在s中的开始位置(下标值),否则返回-1。 [C函数2] int index(char *s,char *t) int i,j=0;k=0; for(i=0;s[i]!:'/0';i++) ( for( (3) ;(t[k]!='/0') if( (5) ) return(i); return(-1);
填空题【说明】在一些应用场合中,需要对用户的输入数据进行检查监控。以下VisualBasic程序实现了对新添加到List列表的内容进行监控,拒绝向List列表添加重复信息。例如,在List列表中存在元素“a01001;a01002”,如果用户输入数据为“a01001”或“a01002”,系统则弹出提示信息,拒绝将新数据加入List列表;如果用户输入的数据不同于List列表中的任何一个元素,则作为新元素加入List中。VisualBasic界面显示如图所示。根据程序功能说明,完成程序代码。【代码5-1】BeginVB.FormFormlCaption="List列表拒绝添加重复信息"//...窗体描述(略)BeginVB.CommandButtonCommand2Caption="退出"//...窗体描述(略)EndBeginVB.CommandButtonCommandlCaption="添加"//...窗体描述(略)EndBeginVB.TextBoxText1//...窗体描述(略)EndBeginVB.ListBoxList1Height=1860ItemData="Form1.fix":0000Left=1020List="Form1.fix":0002TabIndex=0Top=525Width=2580EndBeginVB.Labe1Labe11BackStyle=0'TransparentCaption="请输入编号"//...窗体描述(略)EndEnd【代码5-2】AttributeVBName="Form1"AttributeVB_GlobalNameSpace=FalseAttributeVBCreatable=FalseAttributeVBPredeclaredId=TrueAttributeVB_Exposed=FalsePrivateSubFormLoad()List1.AddItem"a01001"List1.AddItem"a01002"EndSubPrivateSubCormnand1Click()DimMyvalAsLongFori=0To{{U}}(1){{/U}}{{U}}(2){{/U}}If{{U}}(3){{/U}}ThenMsgBox"系统不允许重复输入,请重新输入"ExitSubEndIf{{U}}(4){{/U}}{{U}}(5){{/U}}EndSub
填空题[说明] 已知类Stock和类cxyjava都定义在cxyjava.java文件中,类Stock的定义中第14行前共有四行出现了错误,将下面代码修改正确并完善后的输出结果为: 0:0 1:23
填空题[说明] 下面Application程序根据ManKind类中的sex属性输出“Man!”或“Woman!”。程序全部写在Main.java文件中。程序中存在两个错误,分别在第01和14行,请将其改正或删除相应语句,并指出程序运行的输出结果。 [Java程序] 01 public class ManKind 02 int sex; //默认,是公有成员 03 public void manOrWoman()//公有方法 04 ifsex ==0 //表示男人 05 System.out.print "Man!”; 06 else //女人 07 System.out.print "Woman!"; 08 09 10 11 public class Main 12 public static void main(String[] args 13 ManKind somePerson, somePerson2; 14 SomePerson. sex=1; 15 somePerson=new ManKind(); 16 SomePerson.sex=1; 17 somePerson.manOrWoman(); 18 SomePerson2=somePerson; 19 SomePerson2.sex=0: 20 somePerson2 .manOrWoman(); 21 somePerson.manOrWoman(); 22 23
填空题[说明]
编写一个字符界面的Java Application 程序,接受用户输入的10个整数,并输出这10个整数的最大值和最小值。
[Java 代码]
import java. io.* ;
public class abc
{
public static void main ({{U}} (1) {{/U}})
{int i, n=10, max=0, min=0, temp=0;
try {
BufferedReader br = new BufferedReader (
new InputStreamReader ( System.in ) );
max = min =Integer. parselnt ( br. readLine ( ) );
}.{{U}} (2) {{/U}}( IOExccption e ) {} ;
for ( i=2 ; i<=n ; i++ ) {
try {
BufferedReader br = new{{U}} (3) {{/U}}(
new InputStreamReader ( System. in ) );
temp ={{U}} (4) {{/U}}( br. readLine ( ));
if (temp>max ) max=temp;
if (temp<min){{U}} (5) {{/U}}
} catch (IOException e ) {};
}
System.out.println ( "max="+max+"/nmin="+min );
}
}
填空题[说明] 阅读下面程序,指出其中代码的错误及原因。 [C++程序] 01 #include <iostream.h> 02 class employee 03 private: 04 short age; 05 float salary ; 06 friend void funcl () ; 07 protected: 08 char* name; 09 public: 10 employee (char* nn, short ag, float salr) ; 11 void print () const ; 12 ~employee () ; 13 ; 14 manage:public employee 15 char* department; 16 //... 17 public: 18 void print () ; 19 void setEmployee () ; 20 //... 21 22 //... 23 void manage::print () 24 25 cout <<"name: " name<<endl; 26 cout<<"salary: "<<salary<<endl; //-- (1) 27 28 void manager::setEmployee(char* dept) 29 30 employee::employee(char* nm,short ag,float salr) ; //-- (2) //-- (3) 31 department=dept; 32 33 void funcl () 34 35 cout <<"department:"<<department 11-- (4) 36 <<",name: "<<name<<endl; 37 //... 38 39 void main () 40 41 employee aemp; //-- (5) 42 manager amngr (" Kng " , 35, 578. 9); 43 //... 44
填空题在Visual Basic中,工程文件、窗体文件和标准模块文件的扩展名是什么?请从下列选项中选择:
prg、prj、exe、vbp、form、frm、win、fra、std、bas、vbs、vbm
2.设某窗体上有一个命令按钮,其名称为CmdSave,运行时该按钮上显示有“保存(S(下划线))”字样的信息。为使热键Alt+S与该命令按钮相关联,应该对按钮CmdSave的Caption属性设置什么样的属性值?
3.设某窗口内有一个图像框Imagel,以及两个命令按钮“放大”和“缩小”。单击“放大”按钮就会使该图像框的长和宽都放大10%;单击“缩小”按钮就会使该图像框的长和宽都缩小 10%(该图像框的左上角不动)。请分别写出这两个命令按钮的单击事件过程中的程序代码。
4.为使某个单选按钮初始时默认被选中,在开发时应怎样做?
5.若有语句Tmpval=MsgBox(“非法操作!”,vbOKCancel+vbCritical,“提示”),请简要描述程序运行时弹出的消息框的主要特征。
填空题阅读下列说明、图和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。[说明]已知对某载客车辆(Car)进行类建模,如图6-1所示,其中类Engine表示发动机引擎,类Wheel表示车轮,类Body表示车身,类Driver表示司机,类Passenger表示乘客。[Java代码]classBody//此处代码省略;//车身类classPassenger//此处代码省略;//乘客类classWheel//此处代码省略;//车轮类classDriver//司机类publicStringname;//表示第几路公交车司机publicDriver(StringdriverName)name=driverName;)//构造函数;classEngine//引擎类publicStringengineNo;//引擎编号publicEngine(StringengineNo)this.engineNo=engineNo;)//构造函数;publicclassCar//汽车类staticfinalint(1)=7;//定义最多载客数staticfinalintMAXWHEELS=5;//定义最多轮胎数protectedEngineengine;protectedDriverdriver;protectedBodybody=newBody();protectedWheel[]wheels;protectedPassenger[]passengers;publicCar(Driverdriver)//构造函数(2).driver=driver;engine=newEngine("TX6536型号引擎");wheels=newWheel[MAXWHEELS];passengers=newPassenger[MAX_PASSENGERS];for(intindex=0;index<MAX_WHEELS;index++)wheels[index]=newWheel();for(intindex=0;index<MAX_PASSENGERS;index++)passengers[index]=null;intgetPassengerNumber()//获取车上乘客数量//此处代码省略return0;voidgetOnPassenger(PassengeraPassenger)//乘客上车//此处代码省略voidrun()//开车if((3))System.out.println("司机尚未上车!");return;//此处代码省略publicstaticvoidmain(Stringargs[])Driverdriver=newDriver("第五路公交车司机");Carcar=newCar((4));for(intindex=0;index<MAX_PASSENGERS;index++)car.getOnPassenger((5)Passenger());car.run();
填空题[说明] 试从含有n个int 型数的数组中删去若干个成分,使剩下的全部成分构成一个不减的子序列。设计算法和编写程序求出数组的不减子序列的长。 [C++ 程序] #include<stdio.h> #define N 100 int b[]=9,8,5,4,3,2,7,6,8,7,5,3,4,5,9,1; int a [N]; #define n sizeofb/sizeofb[0] void main ( ) kit k,i,j; (1) (2) for (i=1;i<n; i++ ) for ( j=k; (3) ; j--); (4) ; /*长为 j+1 的子序列的终元素存储在 a[j+1]*/ if ( (5) k++; /*最长不减子序列长 k 增1*/ printf ( "K = %d/n ",k );
