填空题【说明】
该程序的功能是从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中,以行为单位对行中以空格或标点符号为分隔的所有单词进行倒排。最后把已处理的字符串(应不含标点符号)仍按行重新存入字符串数组xx中,最后把结果xx输出到文件OUT6.DAT中。
例如:原文:You He Me
I am a student.
结果:Me He You
student a am I
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
【函数】
#include<string.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
char xx[50] [80];
int maxline=0; /*文章的总行数*/
int ReaaDat(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)
p2=p1;
while({{U}} (1) {{/U}})p1--;
if(p1==xx[i])
if(isalpha(*p1))p1--;
else if(!isalpha(*(p1+1)))break;
p2++;
{{U}} (2) {{/U}};
strcat(t, p1+1);
strcat(t," ");
}
strcpy(xx[i],t);
}
}
void main( )
{
if({{U}} (3) {{/U}}) {
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={{U}} (4) {{/U}}
fclose(fp);
return 0;
}
void WriteDat(void)
{
FILE * fp;
int i;
fp=fopen("e://a//out6,dat","w");
for(i=0;i<{{U}} (5) {{/U}};i++){
printf("%s/n",xx[i]);
fprintf(fp,"%s/n",xx[i])
}
fclose(fp)
}
填空题[说明] 下面程序定义了一个类Shape及其成员函数,然后从类Shape派生出类Point、 类Circle、类Cylinder,以及它们的成员函数。 [C++程序] #include "iostream.h" class Shape public: virtual void printShapeName() const=0; //纯虚函数 virtual float area() const return 0.0; virtual float volumn() const return 0.0; ; class Point: public Shape public: Point (float a=0, float b=0) (x=a; y=b; ) void setPoint(float a,float b) (x=a; y=b;) float getX() constreturn x; float getY() constreturn y; virtual void printShapeName()const (1) ; private: float x,y; ; class Circle: (2) public: Circle(float r=0.0, float a=0.0, float b=0 .0) :Point (a,b) radius=r>0 ? r:0; void setRadius(float r) radius=r>0? r:0; float getRadius () const return radius; virtual float area () const return 3 .14 259*radius*radius ; virtual void printShapeName () const cout<<"circle:"; private : float radius; ; class Cylinder: (3) public : Cylinder(float h=0.0,float r=0.0,float x=0.0,float y=0.0) : (4) height=h>0 ? h:0; void setHeight (float h) height=h>0 ?h:0; virtual float area () const return (5) ; virtual float volumn () const float r=Circle:: getRadius (); return 3.14159*r*r*height; virtual void printShapeName () const (cout<<"cylinder: " ; private : float height;
填空题
阅读以下说明和C++程序代码,将应填入{{U}} (n) {{/U}}处的字句写在答题纸的对应栏内。
[说明]
在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDecorator与FootDecorator分别完成打印票据的抬头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。
这是票据的抬头! 这是票据正文! 这是票据的脚注!
-------------------------------------- 这是票据的抬头!
这是票据的脚注! [C++程序代码]
#include<iostream> using namespace std;
class SalesTicket{ public;
{{U}} (1) {{/U}}printTicket(){cout<<"这是票据正文!"<<endl;}
}; class Decorator:public SalesTicket{
SalesTicket *ticket; public:
Decorator (SalesTicke *t){ticket=t;}
void printTicket (){ if
(ticket!=NULL)
ticket->printTicket() ; }
}; class HeadDecorator:public Decorator{
public: HeadDecorator(SalesTicket *t):{{U}}
(2) {{/U}}{} void
printTicket(){ cout<<"这是票据的抬头!"
<<endl;
Decorator::printTicket(); }
}; class FootDecorator:public Decorator{
public: FootDecorator(SalesTicket *t):{{U}}
(3) {{/U}}{} void
printTicket(){
Decorator::printTicket();
cout<<"这是票据的脚注!"<<endl; }
}; void main (void){
SalesTicket t; FootDecorator
f( HeadDecorator h({{U}} (4)
{{/U}}); h.printTicket();
cout<<"---------------------"<<endl;
FootDecorator a(NULL); HeadDecorator b({{U}}
(5) {{/U}}); b.printTicket();
}
填空题【说明】本程序是一个可进行数制转换的应用程序,图1所示是其运行界面。txtDec为TextBox控件名,Lblkes为转换结果label控件名。图1【程序代码】OptionExplicitPrivateFunctionconvert(pintDecAsIntege,pintSAsInteger)AsStringDimintCtAsInteger,intRAsIntegerDimstrCovAsString,strResAsStringintR=pintDecModpintSDoWhile(1)strCov=strCov&Str(intR)(2)intR=pintDecModpintsLoopForintCt=(3)To1Step-1strRes=strRes&Mid(strCov,intCt,1)NextintCtconvert=strResEndFunctionPrivateSubcmdQuit_Click()′退出UnloadMeEndSubPrivateSuboptBin_Click()′二进制IblRes.Caption="转换结果:"&(4)EndSubPrivateSuboptHex_Click()′十六进制IblRes.Caption="转换结果:"&(5)EndSubPrivateSuboptOct_Click()′八进制IblRes.Caption="转换结果:"&Oct(Val(txtDec.Text))EndSub
填空题【说明】 下面一段程序从给定的数组b中找出值最小的元素,并输出该元素的数组下标、内存地址minaddr以及元素值本身。函数findmin负责在给定的数组中查找最小值,并返回最小值所在的内存地址,函数有三个参数:array是所要处理的数组;size是数组的大小;index负责从函数返回具有最大值的元素在数组中的数组下标。请填充空白,使其成为一个合乎要求的完整程序。 【程序】 //程序开始 #include<iostream.h> int *findmin(int *array, int size, int void main() /****** 变量定义部分 ***********/ int b[10] = 34, 34, 23, 89, 1, 2, 13, 42, 5, 54; (1) ; int idx; /******* 寻找最小值 ************/ minaddr = findmin(b, sizeof(b)/sizeof(int), idx); /******* 输出最小值的有关信息 ************/ cout << "Min value index: "<<idx<<end1 <<"Min value address: "<<minaddr<<end1 <<"Min value: "<< (2) <<end1; /******* 函数findmin的定义部分 ************ int *findmin(int *array, int size, int //max 是当前具有最小值的数组元素下标值 for(int i = 1; (3) ; i++) if(array[i]< (4) ) min = i; (5) ; return array + min;//返回最小值所在内存地址
填空题[说明]下面的流程图,用来完成计算一组数组中的中值,其方法是:将数组中的一个值与其他值比较,并计算大于等于被比较数的数值的个数,以及小于等于被比较数的数值的个数,如果两数都大于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
