填空题阅读以下说明和C++代码,回答问题。 [说明] 已知类SubClass的getSum方法返回其父类成员i与类SubClass成员i的和,类SuperClass中的getSum为纯虚拟函数,程序中的第23行有错误,请修改该错误并给出修改后的完整结果,然后完善程序中的空缺,分析程序运行到第15行且尚未执行第15行的语句时成员变量j的值,最后给出程序运行后的输出结果。 [C++代码] 01 #inclUde<iostream> 02 using namespace std; 03 class SuperClass 04 private: 05 int i; 06 publiC: 07 SuperClass()(i=5;) 08 virtual iht getValueO(return i ;) 09 virtual int getSum()=0; 10 ; 11 class SubClass:public SuperClass 12 int J ; 13 public: 14 SubClass(int j):j(0) 15 (1) =j; //用参数j的值更新数据成员 16 ; 17 int getValue()return j;) 18 int getSum() 19 return (2) getValue()+j; 20 21 ; 22 void main(void) 23 SuperClass s=new SubClass(-3); 24 cout<<s->getValue()<<""; 25 tout<<s->getSum()<<endl; 26 delete s; 27
填空题【说明】 下面的程序中定义了两个方法求自然数1~100的和。具体如下:int suml(int n);利用循环求1~n的和,int sum2(int n);利用递归方法求和1~n的和;在main()方法中调用这两个方法求1~100的和并显示。在程序的每条横线处填写一个适当的语句,使程序的功能完整。 public class Sum public static void main (1) //1. 调用sum1(int n),求1~100的和 //标准输出 (2) ("1~100的和:" +sum1(100)); //2. 调用sum2(int n),求1~100的和 //标准输出 (2) ("1~100的和:"+sum2(100)); static iht sum1( int n) int result=0; for(int i=1;i<=n;i++) (3) retrun result; static int sum2(int n) if (4) return 1 else (5)
填空题[说明]
本程序将利用文本框txtInput 输入的一行字符串中的所有字母加密,加密,加密结果在文本txtCode中显示。加密方法如下:将每个字母的序号移动5个位置,即“A”->“F”“a”->“f”,“B”->“G”……“Y”->“D”,“Z”->“E”。程序段如下:
[Visual Basic 代码]
Private Sub Form_ Click()
Dim strInput As String*70 ; 输入字符串
Dim Code as String*70 ;加密结果
Dim strTemp As String*1 ;当前处理的字符
Dim i as Integer
Dim Length As Integer ;字符串长度
Dim iAsc As Integer ;第i个字ASCII码
{{U}} (1) {{/U}} ;取字符串
i=1
Code=“”
{{U}} (2) {{/U}} ;去掉字符串右边的空格,求真正的长度
Do While(i<=Length)
{{U}}(3) {{/U}} ;取第i个字符
If (strTemp>="A" And strTemp<="Z',) Then
iAsc= Asc (strTemp)+5
If iAsc>Asc(“Z”)Then iAsc=iAsc-26
Code=Left$(Code,i-1)+Chr$ (iAsc)
ElseIf (strTemp>="a" And strTemp<="z") Then
iAsc=Asc(strTemp)+5
If iAsc>Asc (“z”) TheniAsc=iAsc-26
Code=Left$(Code,i-1)+Chr$(iAsc)
Else
Code=Left$(Code,i-1)+strTemp
End If
{{U}} (4) {{/U}}
Loop
{{U}} (5) {{/U}} ;显示加密结果
End Sub
填空题【流程图】下面的流程图描述了对16位二进制整数求补的算法。计算过程是:从二进制数的低位(最右位)开始,依次向高位逐位查看,直到首次遇到“1”时,停止查看。然后,对该“1”位左面的更高位(如果有的话),逐位求反,所得的结果就是对原二进制数求补的结果。例如:对二进制整数1011100110101000求补的结果是0100011001011000。设16位二进制整数中的各位,从低位到高位,依次存放在整型数组BIT的BIT[1]~BIT[16]中。例如,二进制整数1011100110101000存放在数组BIT后,就有BIT1[1]=0,BIT[2]=0,……,BIT[15]=0,BIT[16]=1。流程图(如图1所示)中(1)处按“循环变量名:循环初值,增量,循环终值”格式描述。若流程图中存在空操作,则用NOP表示。
填空题[说明] 设计一个类模板Sample用于对一个有序数组采用二分法查找元素下标。 [c++程序] #include<iostream. h> #define Max 100 //最多元素个数 template<class T> class Sample T A [Max]; //存放有序数序 int n; //实际元素个数 Public: Sample //默认构造函数 Sample(T a[] ,int i); //初始化构造函数 int seek(T c); void disp for (int i=0; i<n; i++) cout<<A [i]<<" "; cout<<endl; ; template<class T> Sample<T>::Sample(T a[],int i) n=I; for (int j=0; j<I; j++) (1) ; template<class T> int Sample<T>::seek(T c) int low=0,high=n-1,mid; while( (2) ) mid=(low+high)/2; if( (3) ) return mid; else if ( (4) ) low=mid+1; else (5) ; return-1; void main() char a[]="acegkmpwxz"; Sample<char>s(a,1.); cout<<"元素序列:" ;s. disp(); cout<<"元素'g' 的下标: "<<s. seek('g')<<endl;
填空题【说明】 以下程序实现了利用鼠标任意移动该圆形的位置,仔细阅读代码和相关注释,将程序补充完整。 【代码6】 import java.awt.*; import java.awt.event.*; public class CIUSAMPLE extends Frame implements MouseMotionListener, MouseListener static CIUSAMPLE frm=new CIUSAMPLE (); int x=70,y=60,posX=70,posY=60,dx,dy; public static void main ( String args[]) frm.setTitle ("Dragging a circle"); frm.setSize ( 200,150 ); (1) frm.addMouseMotionListener ( frm ); frm. setVisible ( true ); public void mousePressed ( MouseEvent e ) (2) dy=e.getY () -posY; public void mouseDragged ( MouseEvent e ) (3) y=e.getY () -dy; if ( dx>0 (4) public void paint ( Graphics g ) g.setColor ( Color. pink ); // 设置绘图颜色为粉红 g.fillOval ( x,y,50,50 ); //以基准点为图形的左上角绘出圆形 (5) posY=y; public void mouseMoved ( MouseEvent e ) public void mouseReleased ( MouseEvent e ) public void mouseEntered ( MouseEvent e ) public void mouseExited ( MouseEvent e ) public void mouseClicked ( MouseEvent e )
填空题[说明] 下面程序定义了一个类Point及其成员函数,然后从类Point派生出类Circle及其成员函数。 [C++程序] //POINT. H #ifndef POINT_H # define POINT_H class Point public: Point (float x=0,float y=0) ; void setPoint (float, float) ; float getX () const return x; float getY () const return y; protected: float :x,y; ; #endif //POINT.CPP #include <iostream.h> #include " point .h " Point :: Point (float a, float b) x=a; y=b void Point::setPoint(float a,float b) x=a; y=b //CIRCLE . H #ifndef CIRCLE_H #define CIRCLE_H #include "point.h" class Circle: (1) public : Circle (float r=0.0, float x=0, float y=0) ; void setRadius (float) ; float getRadius () const; float area() const; protected: float radius; ; //CIRCLE.CPP #include "iostream.h" #include "circle .h " Circle::Circle(float r,float a,float b) : (2) radius=r; void Circle::setRadius (float r) radius=r; float Circle::getRadius () const return radius; float Circle::area () const return 3 .14159*radius*radius ; //text.cpp #include <iostream.h> #include " point .h " #include " circle .h " main () Circle c(2.5,3.7,4.3) ; cout<< "X coordinate is "<<c.getX () <</n Radius is: "<<c.getRadius (); (3) ; //设置新的圆心 (2,2) 。 Point &pRef=c; cout<<"/n Circle printed as a point is:" <<"]"<< (4) <<"."<< (5) <<"]";
填空题阅读以下函数说明和C语言函数,将应填入{{U}} (n) {{/U}}处的字句写在对应栏内。 [说明1] 函数void fun(char*w,char x,int*n)用来在w数组中插入x,w数组中的数已按由小到大顺序存放,n指存储单元中存放数组中数据的个数,插入后数组中的数仍有序。 [C函数1] void fun(char*W,char x,int*n) { int i,P; p=0; w[*n]=x; while(x>w[p]){{U}} (1) {{/U}}; for(i=*n,i>p;i--)w[i]={{U}} (2) {{/U}}; w[p]=x; ++*n; } [说明2] 函数void revstr(char*s)将字符串s逆置。例如:字符串“abcde”,经过逆置后变为“edcba”。 [C函数2] void revstr(char*s) { char*p,c; if(s==NULL)return; p={{U}} (3) {{/U}}; /*p指向字符串s的最后一个有效字符*/ while(s<p){ /*交换并移动指针*/ C=*s; {{U}} (4) {{/U}}=*p; {{U}} (5) {{/U}}=c; } }
填空题已知类Stock和类JavaMain都定义在JavaMain.java文件中,类Stock的定义中有四处错误,分别在代码的第01、02、06、07行。请修改错误并给出修改后该行的完整代码,并写出改正错误后程序运行的输出结果。
填空题[说明]
若S和T是用结点大小为1的单链表存储的两个串,试设计一个算法找出S中第一个不在T中出现的字符。查找过程是这样的,取S中的一个字符(结点),然后和T中所有的字符一一比较,直到比完仍没有相同的字符时,查找过程结束,否则再取S中下一个字符,重新进行上述过程。
[函数]
typedef struct node {
char data;
struct node *next;
}LinkStrNode; //结点类型
typedef LinkStrNode *LinkString; //LinkString 为链串类型
LifikString S; //S 是链串的头指针
char SearchNoin ( LinkString S, LinkString T )
{//查找不在T中出现的字符
LinkStrNode *p, *q;
{{U}} (1) {{/U}};
q=T;
while ({{U}} (2) {{/U}})
{//取S中结点字符
while({{U}} (3) {{/U}})//进行字符比较
q=q->next;
if(q==NULL) return {{U}}(4) {{/U}};//找到并返回字符值
q=T;//指针恢复串T的开始结点
({{U}} (5) {{/U}});
}
printf("there's no such character.");
return NULL:
}
填空题【说明】下列流程图(如图4所示)用泰勒(Taylor)展开式sinx=x-x3/3!+x5/5!-x7/7!+…+(-1)n×x2n+1/(2n+1)!+…【流程图】计算并打印sinx的近似值。其中用ε(>0)表示误差要求。
填空题阅读以下函数说明和C语言函数,将应填入 (n) 处的字句写在对应栏内。 [说明] 某银行共发出M张储蓄卡,每张储蓄卡拥有唯一的卡号,每天每张储蓄卡至多支持储蓄卡持有者的N笔“存款”或“取款”业务。程序中用数组card[M][N+3]中的每一行存放一张储蓄卡的有关信息,其中: card[i][0]存放第i张卡的卡号; card[i][1]存放第i张卡的余额; card[i][2]存放第i张卡的当日业务实际发生笔数; card[i][3]~card[i][N+2]存放第i张卡的当日存取款金额,正值代表存款,负值代表取款。 当持卡者输入正确的卡号、存款或取款金额后,程序进行相应的处理;若输入不正确的数据,程序会提示持卡者重新输入;若输入的卡号为负数时,银行终止该卡的当日业务。 [C程序] #include<stdio.H> #define M 6 #define N 5 long card[M][N+3]=9801,2000,0,,9812,2000,2,,9753,3000,1,, 8750,500,0,,9604,2800,3,),(8901,5000,5,; int locate(long card[][N+3],int m,long no) int i; for(i=0;i<m;i++) if( (1) ==no) return i; (2) ; main() long cardNo,money; int k; while(1) printf("请输入卡号:/n"); scanf("%1d", if(cardNo<0) break; k=locate(card,M,cardNo); if(k==-1) printf("不存在%id号的储蓄卡/n",cardNo); continue; printf("请输入金额(正值代表存款,负值代表取款):/n"); scanf("%id", if(card[k][1]+money<0) printf("存款余额不足,不能完成本次的取款业务/n"); continue; if(card[k][2]==N) printf("已完成本卡的当日业务/n"); continue; /*处理一笔业务的数据*/ card[k] (3) =money; (4) ; (5) ;
填空题阅读以下说明和C++程序,将应填入{{U}} (n) {{/U}}处的字句写在对应栏内 [说明] 以下程序的功能是计算三角形、矩形和正方形的面积并输出。 程序由4个类组成:类Triangle,Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述三种图形面积的通用接口。 [C++程序] #include<iostream.h> #include<math.h> class Figure{ public: virtual double getArea()=0; //纯虚拟函数 }; class Rectangle:{{U}} (1) {{/U}}{ protected: double height; double width; public: Rectangle(){}; Rectangle(double height,double width){ This->height=height; This->width=width; } double getarea(){ return{{U}} (2) {{/U}}; } }; class Square:{{U}} (3) {{/U}} public: square(double width){ {{U}} (4) {{/U}}; } }; class triangle:{{U}} (5) {{/U}}{ double la; double lb; double lc; public: triangle(double la,double lb,double lc){ this->la=la;thiS->ib;this->lc; } double getArea(){ double s=(la+lb+lc)/2.0; return sqrt(s*(s-la)**(s-lb)*(s-lc)); } }; viod main(){ figure*figures[3]={ new triangle(2,3,3),new Rectangle(5,8),new Square(5)}; for(int i=0; i<3;i++){ cout<<"figures["<<i<<"]area="<<(figures)->getarea()<<endl; } } };
填空题[说明] 下面程序是一个小型公司工资管理的程序。该公司主要有4类人员:经理、兼职技术人员、销售员和销售经理。基类为employee,由它派生出technician类,manager类,salesman类,最后由manager类和salesman类派生出salesmanager类。月工资计算办法是:经理拿固定月薪8000;兼职技术人员按每小时100元领取月薪; 销售按当月销售额的4%提成; 销售经理既拿固定月工资也领取销售提成,固定月工资5000元,销售提成为所管辖部门当月销售总额的0.5%。 [C++程序] #include<iostream.h> #include<string.h> class employee protected: int no; char name [10] ; float salary; public : employee () cout<< "职工编号: " ; cin>>no ; cout<<"职工姓名:"; cin>>name ; salary= 0 ; void pay () void display () ; class technician:public employee private : float hourlyrate; int workhours; public : technician() hourlyrate=100; void pay () cout<<name本月工作时数: " ; cin>>workhours ; salary=hourlyrate*workhours; void display () cout<<"兼职技术人员"<<name<<"(编号为"<<no/ <<")"<<"本月工资:"<<salary<<endl; ; class salesman: (1) protected: float commrate; float sales; public: salesman() commrate=0.04; void pay() cout<<name<<"本月销售额:"; cin>>sales; salary= (2) ; void display() cout<<"销售额"name<<"(编号"<<no<</ <<")"<<"本月工资:"<<salary<<endl; ; class manager: (3) protected: float monthlypay; public: manager()monthlypay=8000; void pay()salary=monthlypay; void display() cout<<"经理"<<name<<"(编号为"<<no/ <<")"<<"本月工资:"<<salary<<endl; ; class salesmanager: (4) public: salesmanager() monthlypay=5000; commrate=0.005; void pay() cout<<name<<"所管部门月销售量:"; cin>>sales: salary= (5) ; void display() cout<<"销售经理"<<name<<"(编号为"<<no/ <<")"<<"本月工资:"<<salary<<endl; ;
填空题【说明】 以下程序的功能是计算正方体、球体和圆柱体的表面积和体积并输出。 程序由4个类组成:类cube、sphere和cylinder分别表示正方体、球体和圆柱体;抽象类 container为抽象类,提供了两个纯虚拟函数surface_area()和volum(),作为通用接口。 【C++程序】 #include<iostream.h> #define pi 3.1416 class container{ protected: double radius; public: container(double radius) container::radius=radius; virtual double surface_area()=0; virtual double velum()=0; ; class cube: (1) //定义正方体类 public: cube(double radius):container(radius); double surface_area () return 6 * radius * radius; double volum() return radius * radius * radius; ; class sphere: (2) //定义球体类 public: sphere(double radius): container(radius); double surface_area() return (3) ; double volum() return pi * radius * radius * radius * 4/3; ; class cylinder: (4) //定义圆柱体类 double height; public: cylinder(double radius,double height):container(radius) container::height=height; double surface_are a () return 2 * pi * radius * (height+radius); double volum () return (5) ; ; void main() container * p; cube obj1 (5); sphere obj2(5); cylinder obj3(5,5); p= cout<<“正方体表面积”(<<p->surface_area()<<end1; cont<<“正方体体积”<<p->volume()<<end1; p= cout<<“球体表面积”<<p->surface_area()<<end1; cout<<“球体体积”<<p->volume()<<end1; p= cout<<“球体表面积”<<p->surface_area()<<end1; cout<<“球体体积”<<p->volume()<<end1;
填空题【说明】
以下程序为求行列式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
{{U}}(1) {{/U}}
for j = 1 to 5
if I+j>6 then
k= ( 1+j ) mod 5
else
k=1
endif
temp=temp*x ( k,j )
{{U}} (2) {{/U}}
result={{U}} (3) {{/U}}
{{U}}(4) {{/U}}
{{U}}(5) {{/U}}
End function
填空题[函数8.1说明]
现考虑编写一个扑克游戏:只用一副无大小王的扑克,扑克的花色(suit)分为Spade、Heart、Diamond和Club,每门花色的牌共13张,面值(rank)分别为2、3、4、5、6、7、8、9、10、Jack、Queen、King和Ace,每张扑克牌应包含如下信息:惟一的ID号(1~52)、花色、面值、背面图案的编号等。每张扑克牌的操作有:判断两张扑克牌是相同花色吗?相同面值吗,判断一张扑克牌是给定的花色吗?是给定的面值吗?请补充扑克牌类Card类的声明和实现代码,要求选取适当形式的数据成员描述每张扑克牌的信息,同时以成员函数的形式实现指定的操作。
[C++程序]
const enum SUIT {SPADE=0,HEART,DIAMOND,CLUB};
const enum RANK{TWO=0 THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING,ACE};
class Card。
{
public:
{{U}} (1) {{/U}}(int id):mID (id),mSuit((id 1)/13),mRank((id-1)%13) {}
bool IsSameSuit (const Card
int b;
public:
vector (int x=0,int y=0):a(x),b(y){}
double operator*({{U}} (4) {{/U}})
{
double c;
{{U}} (5) {{/U}};
return c;
}
void input (int x, int y)
{a=x;
b=y;
}
void output ()
{cout<<'('<<a<<',' <<b<<") "<<end1;
}
};
void main()
{
vector x(10,20),y; //定义x, y, z三个矢量类对象,并将x置初值(10,20)
doubled;//定义实数d以存放点乘结果
y. input (2,3); //给y赋值为(2,5)
d=x*y;//两矢量点乘
x. output (); //输出矢量x
y. output (); //输出矢量y
cout<<d<<end1; //输出点乘结果
}
填空题【说明】
下面程序的功能是找出所有三位数中,个、十、百位数字的立方和等于该数本身的三位数并显示。在程序的每条横线处填写一个适当的词或语句,使程序的功能完整。
public{{U}} (1) {{/U}}class cube_Root {
public static void{{U}} (2) {{/U}}main(String args[]) {
System. out. println ("个、十、百位数字的立方和等于该数本身的三位数有:");
for(int n=100;n<1000;n++)
{
int a,b,c;
{{U}} (3) {{/U}}
b=n/10%10;
{{U}} (4) {{/U}}
if({{U}} (5) {{/U}})
System.out.println(n);
}
}
}
填空题[函数说明3.1]假设两个队列共享一个循环向量空间(参见右图),其类型Queue2定义如下:typedefstructDateTypedata[MaxSize];intfront[2],rear[2];Queue2;对于i=0或1,front[i]和rear[i]分别为第i个队列的头指针和尾指针。函数EnQueue(Queue2*Q,inti,DateTypex)的功能是实现第i个队列的入队操作。[函数3.1]intEnQueue(Queue2*Q,inti,DateTypex)//若第i个队列不满,则元素x入队列,并返回1;否则返回0。if(i<0||i>1)return0:if(Q->rear[i]==Q->front[(1)])return0:Q->data[(2)]=x;Q->rear[i]=[(3)];return1:[函数说明3.2]函数BTreeEqual(BinTreeNode*T1,BinTreeNode*T2)的功能是用递归法判断两棵二叉树是否相等,若相等则返回1,否则返回0。函数中参数T1和T2分别为指向这两棵二叉树根结点的指针。当两棵树的结构完全相同并且对应结点的值也相同时才被认为相等。已知二叉树中的结点类型BinTreeNode定义为:structBinTreeNodechardata;BinTreeNode*left,*right;;其中data为结点值域,left和right分别为指向左、右子女结点的指针域。[函数3.2]intBTreeEqual(BinTreeNode*T1,BinTreeNode*T2)if(T1==NULL&&T2==NULL)return1;//若两棵树均为空则相等elseif((4))return0;//若一棵为空一棵不为空则不等elseif((5))return1;//若根结点值相等并且左、右子树//也相等则两棵树相等,否则不等elsereturn0:
填空题阅读以下函数说明和C语言函数,将应填入{{U}} (n) {{/U}}处的字句写在对应栏内。 [说明] 已知一棵二叉树用二叉链表存储,t指向根结点,p指向树中任一结点。下列算法为输出从t到P之间路径上的结点。 [C程序] #define Maxsize 1000 typedef struct node{ TelemType data; struct node*1child,*rchild; }BiNode,*BiTree; void Path(BiTree t,BiNode*P) { BiTree*stack[Maxsize],*stackl[Maxsize],*q; int tag[Maxsize],top=0,topl; q=t; /*通过先序遍历发现P*/ do(while(q!=NULL stack[top]=q; tag[top]=0; {{U}} (2) {{/U}}; } if(top>0) { if(stack[top]==P) break; /*找到P,栈底到栈顶为t到P*/ if(tag[top]==1)top--; else{q=stack[top]; q=q->rchild; tag[top]=1; } } } {{U}}(3) {{/U}}; top--; topl=0; while(top>0){ q=stack[top]; /*反向打印准备*/ topl++; {{U}} (4) {{/U}}; top--; } while({{U}} (5) {{/U}}){ /*打印栈的内容*/ q=stackl[topl]; printf(q->data); topl--; } }