题目
阅读以下说明和C++程序代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDec- orator与FootDecorator分别能够完成打印票据的台头和脚注的功能。
已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。
这是票据的台头!
这是票据正文!
这是票据的脚注!
---------------
这是票据的台头!
这是票据的脚注!
【C++程序代码】
#include
using namespace std;
class SalesTicket {
public:
(1) printTicket() { cout << " 是票据正文!" << endl;}
class Decorator : public SalesTicket{
SalesTicket *ticket;
public:
Decorator(SalesTicket *t){ ticket = t; }
void printTicket(){
if(ticket != NULL)
ticket->printTicket();
}
};
class HeadDecorator : public Decorator{
public:
HeadDecorator(SalesTicket *t): (2) { }
void printTicket() {
sour << "这是票据的台头!" << endl;
Decorator::printTicket();
}
};
class FootDecorator :public Decorator{
public:
FootDecorator(SalesTicket *t): (3)
void printTicket() {
Decorator::printTicket();
cout << "这是票据的脚注!" << endl;
}
};
void main(void) {
SalesTicket t;
FootDecorator f(&t);
HeadDecorator h((4) );
h.printTicket();
cout << "-------------------------"<< endl;
FootDecorator a(NULL);
HeadDecorator b((5) );
b.printTicket();
}
第1题
阅读以下说明,以及用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;
}
第2题
阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。
【说明】
本程序的功能是根据矩形左上角和右下角顶点坐标生成一个矩形对象,然后输出该矩形4个顶点的坐标,计算并输出该矩形的面积。
【C++代码】
include<iostream>
using namespace std;
class MyPoint(//表示平面坐标系中的点的类
double x;
double y;
public:
MyPoint (double x,double y){this->x=x;this->y=y;}
double getX()const{(1);}
double getY()const{ return y;}
void show()const{ cout<<'('<<x<<','<<y<<')';}
};
class MyRectangle{ //表示矩形的类
MyPoint upleft; //矩形的左上角顶点
MyPoint down right; //矩形的右下角顶点
public:
MyRectangle(MyPoint upleft,MyPoint downright);
MyPoint getUpLeft()const{return up_left;} //返回左上角坐标
MyPoint getDownRight()const{return down_right;} //返回右下角坐标
MyPoint getUpRight()const; //返回右上角坐标
MyPoint getDownLeft()const; //返回左下角坐标
double area()const; //返回矩形的面积
};
MyRectangle:: MyRectangle((2)):
up left(p1),down_right(p2){}
MyPoint MyRectangle::getUpRight()const
{
return MyPoint(down_right.getX(),up_left.getY());
}
MyPoint MyRectangle::getDownLeft()const
{
return MyPeint((3));
}
double (4) ::area()const
{
return (getUpLeft(),getX()-getDownRight().getX())*
(getDownRight().getY()-getUpLeft().getY());
}
int main()
{
MyRectangle r(MyPoint(0,2),MyPoint(2,0));
r.getUpLeft(),show();
r.getUpRight().show();
r.getDown Right().show();
(5);
cout<<r.area()<<end1;
return 0;
}
第3题
阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。
【说明】
本程序的功能是生成螺旋方阵,用户可以输入该方阵的行列数,然后就生成对应的螺旋方阵。例如:当n=5时,对应的螺旋方阵如下:
1 16 15 14 13
2 17 24 23 12
3 18 25 22 11
4 19 20 21 10
5 6 7 8 9
【C++代码】
include"stdio.h"
include"iostream,h"
int array[11][11];
int temp;
int ROW;
void godown(int &m,int &a)
{
for(temp=1; temp<=ROW;temp++)
if(array[temp][a]==0)
array[temp][a]=(1);
a++;
}
void goright(int &m,int &b)
{
for(temp=1;temp<=ROW;temp++)
if(array[b][temp]==0)
array[b][temp]=m++;
b--;
}
void goup(int &m.int &c)
{
for(temp=ROW;temp>0;temp-)
if(array[temp][c]==0)
array[temp][c]=m++;
c--;
}
void goleft(int &m,int &d)
{
for(temp=ROW;temp>0;temp--)
if(array[d][temp]==0)
array[d][temp]=m++;
(2);
}
void main()
{
int a,b,c,d,max,m;
cin>>ROW;
cout>>end1;
for(a=1;a<=ROW;a++)
for(b=1;b<=ROW;b++)
(3);
m=1;
a=d=1;
b=c=ROW;
max=(4);
whiie(m<=max)
{
godown(m,a);
(5) (m,b);
goup(m,c);
goleft(m,d):
}
for(a=1;a<=ROW;a++)
{
for(b=1;b<=ROW;b++)
printf("%3d ",array[a][b]);
cout<<end1;
}
}
第4题
阅读以下说明及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
第5题
阅读以下说明和c++码,将应填入(n)处的字名写在的对应栏内。
[说明] 以下函数完成求表达式
的值,请填空使之完成此功能。
float sum (float x )
{ float s=0.0;
int sign = 1;
(1);
for(inti=1;(2); i+ +)
{
t=t*x;
s=s+(3);
sign = - sign;
(4);
}
第6题
阅读以下说明和C++代码,将填入 (n) 处的字句在应栏内。
[说明]
现需要统计某企业员工的月平均:[资,即该企业本月发给员工的工资总和除以员工数。假设企业本月发给员工的工资总和为sumSalary,该企业的员工总数为employeeNumber,下面的程序代码计算该企业员工本月的平均工资,其中需要处理employNumber为0的情况。
[C++代码]
include
using namespace std;
class Department {
protected:
float average(float x, int y){
if(Y==O) throw (1)______ ;
return x/y;
}
public:
void caculate(void){
float sumSalary;
int employeeNumber;
try{
cout <<"请输入当月工资总和与员工数:"<<endl;
cin >> sumSalary >> employeeNumber:
float k=average(sumSalary,employeeNumber);
cout <<"平均工资:"<<k<<endl;
}
(2)______ (int e){
if(e==0){
cout <<"请重新输入当月工资总和与员工数:"<<endl;
cin>>sumSalary>>employeeNumber;
float k=average(sumSalary,employeeNumber);
cout<<"平均工资:"<<k<<endl;
}
}
}
};
VOid msin(){
try {
(3)______ ;
d.caculate();
}
(4)______ (int e){
if(e==0)
cout<<"程序未正确计算平均工资!"<<endl;
}
}
[问题1]
程序运行时,若输入的员工工资总和为6000,员工数为5,则屏幕输出为:
请输入当月工资总和与员工数:
6000 5
(5)______
[问题2]
若程序运行时,第一次输入的员工工资总和为6000,员工数为0,第二次输入的员工工资总和为0,员工数为0,则屏幕输出为:
请输入当月工资总和与员工数:
6000 0
(6)______
0 0
(7)______
第7题
阅读以下说明及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
第8题
() 阅读下列说明和C++代码,将应填入空(n)处的字句写在答题纸的对应栏内。【说明】 某中学开展中外中学生野外生存夏令营活动,由于中外学生的语言障碍,随队为外籍学员配置一名翻译。以下代码采用适配器(Adapter)模式模拟翻译适配器。其类图如下:
第9题
●试题五
阅读以下应用说明、属性设置及Visual Basic程序代码,将应填入(n)处在字句写在答题纸的对应栏内。
【说明】
本应用程序的运行窗口如图2所示。
只要用户单击"闪烁"按钮,文字"欢迎光临"就会以0.3秒消失、0.3秒显示反复进行闪烁;单击"停止"按钮时,闪烁停止,恢复图示的初态。
在开发过程中,需要设置的属性如表1所示。
在开发过程中,需要编写的程序代码如下:
【程序】
Private Sub CmdF_Click()
Timer1. (3) =True
Labe1.Visible=False
End Sub
Private Sub Timer1_Timer()
(4) =not Label.Visible
End Sub
Private Sub CmdT_Click()
Timer1.Enabled= (5)
Labe1.Visible=true
End Sub
第10题
阅读以下说明及Visual Basic 程序代码,将应填入(n)处的字句写在对应栏内。
[说明]
本程序求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
Flag=Tree
For t2=2 to Int(Sqr (t1 ) )
If (2) Then flag=False
Next t2
(3)
count=(4)
write 1, t1
End if
Next t1
(5)
Close 1
End Sub
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!