题目内容 (请给出正确答案)
[主观题]

●试题六 阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。 【说明】 ①为类Ci

●试题六

阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。

【说明】

①为类Circle增加一个构造函数,该函数有一个参数,并在构造时将该参数值赋给成员radius。将该函数实现为一个非内联函数,并且使用参数列表的方式将类成员赋值。

②为类Circle增加一个成员函数print(),使得可以输出有关圆的信息,比如下列程序

Circle c;

C.SetRadius (5) ;

C.Print();

将输出:The circle has radius of 5!

③完成友元函数void CompareR(Circle *c1,Circle *c2)的定义,在屏幕中输出c1与c2比较radius大小结果,要求使用if-else结构完成。

输出结果如下:

The circle has radus of 5!

The circle has radius of 10!

c1<c2

源程序文件test7_3.cpp清单如下:

#include<iostream.h>

class Circle{

public:

Circle():radius (5) {}

(1)

void SetRadius(int r) { radius=r; }

int GetRadius() { return radius; }

(2)

friend void CompareR(Circle *c1,Circle *c2);

private:

int radius;

};

void CompareR(Circle *c1,Circle *c2)

{

(3)

cout<<"c1>c2"<<endl;

else

if ((c1->GetRadius())==(c2->GetRadius()))

cout<<"c1=c2"<<endl;

else

if ((c1->GetRadius())<(c2->GetRadius()))

cout<<"c1<c2"<<endl;

}

void main()

{

Circle c1;

c1.SetRadius (5) ;

c1.Print();

Circle c2 (10) ;

c2.Print();

CompareR(&c1,&c2);

}

提问人:网友qqcc135 发布时间:2022-01-06
参考答案
查看官方参考答案
如搜索结果不匹配,请 联系老师 获取答案
更多“●试题六 阅读下列程序说明和C++代码,将应填入(n)处的字…”相关的问题
第1题
请教:2016年计算机二级C++基础练习三简答题9如何解答?

使用VC6打开考生文件夹下的源程序文件2.cpp。阅读下列函数说明和代码,补充空出的代码。函数sum(intn)返回1,2,3,…,n的和。其中n大于0。

程序要求使用递归实现上述功能。

注意:不能修改程序的其他部分,只能补充sum函数。

试题程序:

#include

#include

intsum(intn)

{

}

voidmain()

{

cout<<"1+2+3+…+100="<

endl;

return;

}

点击查看答案
第2题
●试题六 阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。 【程序6说明】 本

●试题六

阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。

【程序6说明】

本程序实现两个多项式的乘积运算。多项式的每一项由类Item描述,而多项式由类List描述。类List的成员函数有:

createList():创建按指数降序链接的多项式链表,以表示多项式。

reverseList():将多项式链表的表元链接顺序颠倒。

multiplyList(List L1,List L2):计算多项式L1和多项式L2的乘积多项式。

【程序6】

#include<iostream.h>

class List;

class ltem{

friend class List;

private:

double quot;

int exp;

Item*next;

public:

Item(double_quot,int_exp)

{ (1) ;}

};

class List{

private:

Item*list;

public:

List(){list=NULL;}

void reverseList();

void multiplyList(List L1,List L2);

void createList();

};

void List::createList()

{Item*p,*u,*pre;

int exp;

double quot;

list=NULL;

while (1) {

cout<<"输入多项式中的一项(系数、指数):"<<endl;

cin>>quot>>exp:

if(exp<0)break;//指数小于零,结束输入

if(quot==0)continue;

p=list;

while((2) ){//查找插入点

pre=p;p=p->next;}

if(p!=NULL&&exp==p->exp){ p->quot+=quot;continue;}

u= (3) ;

if(p==list) list=u;

else pre->next=u;

u->next=p;}

}

void List::reverseList()

{Item*p,*u;

if(list==NULL)return;

p=list->next;list->next=NULL;

while(p!=NULL){

u=p->next;p->next=list;

list=p;p=u;}

}

void List::multiplyList(List L1,List L2)

{Item*pLl,*pL2,*u;

int k,maxExp;

double quot;

maxExp= (4) ;

L2.reverseList();list=NULL;

for(k=maxExp;k>=0;k--){

pL1=L1.list;

while(pL1!=NULL&&pL1->exp>k)pL1=pL1->next;

pL2=L2.list;

while(pL2!=NULL&& (5) pL2=pL2->next;

quot=0.0;

while(pL1!=NULL&&pL2!=NULL){

if(pL1->exp+pL2->exp==k){

(6) ;

pL1=pL1->next;pL2=pL2->next;

}else if(pL1->exp+pL2->exp>k)pL1=pL1->next;

else pL2=pL2->next;

}

if(quot!=0.0){

u=new Item(quot,k);

u->next=list;list=u;}

}

reverseList();L2.reverseList():

}

void main()

{ListL1,L2,L;

cout<<"创建第一个多项式链表\n";L1.createList();

cout<<"创建第二个多项式链表\n";L2.createList();

L.multiplyList(L1,L2);

}

点击查看答案
第3题
●试题六 阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 设计一个

●试题六

阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。

【说明】

设计一个类模板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<<end1:

}

};

template<class T>

Sample<T>::Sample(T a[],int i)

{

n=i;

for(intj=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+l;

else

(5) ;

}

return-1;

}

void main()

{

char a[]="acegkmpwxz";

Sample<char>s(a,1。);

cout<<"元素序列:";s.disp();

cout<<"元素′g′的下标:"<<s.seek(′g′)<<endl;

}

点击查看答案
第4题
●试题六 阅读以下说明和C++程序,将应填入(n)处的语句写在答题纸的对应栏内。 【说明】 以下程序

●试题六

阅读以下说明和C++程序,将应填入(n)处的语句写在答题纸的对应栏内。

【说明】

以下程序的功能是计算三角形、矩形和正方形的面积并输出。

程序由4个类组成:类Triangle、Rectangle和Square分别表示三角形、矩形和正方形;抽象类Figure提供了一个纯虚拟函数getArea(),作为计算上述3种图形面积的通用接口

【C++程序】

#include<iostream.h>

#include<math.h>

class Figure{

public:

virtual double getArea()=0:∥纯虚拟函数

};

class Rectangle: (1) {

protected:

double height;

double width;

public:

Rectangle(){};

Rectangle(double height,double width){

this->height=height;

this->width=width;

}

double getArea(){

return (2) ;

}

};

class Square: (3) {

public:

Square(double width){

(4) ;

}

};

class Triangle: (5) {

double la;

double Ib;

double lc;

public:

Triangle(double la,double lb,double lc){

This->la=la;this->lb=lb;this->lc=lc;

}

double getArea(){

double s=(la+lb+±c)/2.0;

return sqrt(s*(s-1a)*(s-1b)*(s-1c));

}

};

void 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[i])->getArea()<<endl;

}

}

点击查看答案
第5题
●试题六 阅读以下说明和Java代码,将解答写入答题纸的对应栏内。【说明】 下面程序的功能是显示已

●试题六

阅读以下说明和Java代码,将解答写入答题纸的对应栏内。【说明】

下面程序的功能是显示已定义的一个3行3列的二维数组每行的元素,并求所有元素的和并输出。请在程序的每条横线处填写一个适当的语句,使程序的功能完整。

public class Array{

(1) static (2) main(String args[])

{

int sum=0;

int b[][]={{11,12,13},{21,22,23},{31,32,33}};

for(int i=0; (3) i++)

{

System.out.print("b["+i+"]: ");

for(int j=0; (4) j++)

{

System.out.print(b[i][j]+" ");

(5)

}

System.out.println();

}

System.out.println("sum="+sum);

}

}

点击查看答案
第6题
●试题五 阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。 【说明】 ①定义类

●试题五

阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。

【说明】

①定义类Table的私有数据成员x和y,分别用于表示九九表中的两个乘数(x*y),它们都是int型的数据。

②完成类Table的成员函数print()的定义,该函数以"x*y=z"的格式打印出九九表中的一个乘法算式,请使用格式化输出函数printf实现。

③完成类Table9的成员函数print()的定义,该函数调用基类Table的print()函数,将九九表输出到屏幕。

④补充主函数,在屏幕上输出九九表,以便测试所定义的类的正确性。

源程序文件test8_3.cpp清单如下:

#include<iostream.h>

#include<stdio.h>

class Table

{

(1)

int z;

public:

void print(int x,int y,int z);

};

void Table::print (int x,int y,int z)

{

(2)

}

class Table9:public Table

{

public:

void print();

};

void Table9::print()

{

(3)

int x,y,z;

for (i=1;i<10;i++)

{

for(j=1;j<i+1;j++)

{

x=i;

y=j;

z=i*j;

Table::print(y,x,z);

}

printf("\n");

}

}

main()

{

//**4**

return 0;

}

点击查看答案
第7题
试题六(共15分)阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发

试题六(共15分)

阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

【说明】

某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。

试题六(共15分)阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明

【java代码】

class invoice{

public void printInvoice(){:

System.out.println ("This is the content of the invoice!");

}

}

class Decorator : extends Invoice {

protected Invoice ticket;

public Decorator(lnvoice t){

ticket = t;

}

public void printinvoice(){

if(ticket != NULL)

(1);

}

}

class FootDecorator extends Decorator{

public FootDecorator(lnvoice t){

super(t);

}

public void printinvoice (){

Systent.out.println("This is the header of the invoice! ");

(2) ;

}

}

class FootDecorator extends Decorator {

public FootDecorator(invoice t):{

super(t);

}

public void printlnvoice(){

(3) ;

Systent.out.println("This is the header of the invoice! ");

}

}

Class test {

public static void main(string[] args){

Invoice t =new invioce();

Invoice ticket;

Ticket= (4) ;

Ticket. Printinvoice();

Systent.out.println(“--------------“)

Ticket= (5) ;

Ticket. Printinvoice();

}

}

程序的输出结果为:

This is the header of the invoice!

This is the content of the invoice!

This is the footnote of the invoice!

----------------------------

This is the header of the invoice!

This is the footnote of the invoice!

点击查看答案
第8题
●试题七 阅读以下说明和C++代码,将解答写入答题纸的对应栏内。 【说明】 请编写一个函数int SeqS

●试题七

阅读以下说明和C++代码,将解答写入答题纸的对应栏内。

【说明】

请编写一个函数int SeqSearch(int list[],int start,int n,int key),该函数从start开始,在大小为n的数组list中查找key值,返回最先找到的key值的位置,如果没有找到则返回-1。请修改程序中画线部分的错误并将不同情况下的输出结果补充完整。

【程序】

文件search.cpp的内容如下:

#include <iostream.h>

int SeqSearch(int list[],int start,int n,int key)

{

for(int i=start;i<=n;i++)// (1)

{

if(list[i]=key) // (2)

{

return i;

}

}

return -1;

}

void main()

{

int A[10];

int key,count=0,pos;

cout<<" Enter a list of 10 integers: ";

for(pos=0;pos<10;pos++)

{

cin>>A; // (3)

}

cout<<"Enter a key: ";

cin>>key;

pos=0;

while((pos=SeqSearch(A,pos,10,key))!=-1)

{

count++;

pos++;

}

cout<<key<<" occurs "<<count<<(count!=1?" times":" time")<<" in the list."<<endl;

}

第一种情况:输入2 3 12 6 8 45 8 33 7 输入key:8

输出: (4)

第二种情况:输入2 3 12 6 8 45 8 33 7 输入key:9

输出: (5)

点击查看答案
第9题
●试题一 阅读下列函数说明和C代码,把应填入其中n处的字句写在答卷的对应栏内。 【函数1.1说明】

●试题一

阅读下列函数说明和C代码,把应填入其中n处的字句写在答卷的对应栏内。

【函数1.1说明】

函数strcpy(char*to,char*from)将字符串from复制到字符串to。

【函数1.1】

void strcpy(char*to,char*from)

{while((1 ) );}

【函数1.2说明】

函数merge(int a[ ],int n,int b[ ],int m,int *c)是将两个从小到大有序数组a和b复制合并出一个有序整数序列c,其中形参n和m分别是数组a和b的元素个数。

【函数1.2】

void merge(int a[ ],int n,int b[ ],int m,int *c)

{ int i,j;

for(i=j=0;i<n && j<m;)

*c++=a[i]<b[j]? a[i++]:b[j++];

while((2) )*c++=a[i++];

while((3) )*c++=b[j++];

}

【函数1.3说明】

递归函数sum(int a[ ],int n)的返回值是数组a[ ]的前n个元素之和。

【函数1.3】

int sum(int a[ ],int n)

{ if(n>0)return (4) ;

else (5) ;

}

点击查看答案
第10题
阅读下列说明和C++代码,请回答问题1至问题3。【说明】 已知下列程序运行时的输出应为: 1:1 1:1 1:1【

阅读下列说明和C++代码,请回答问题1至问题3。

【说明】

已知下列程序运行时的输出应为:

1:1

1:1

1:1

【C++程序】

01 include <iostream>

02 using namespace std;

03 class Stock{

04 protect:

05 (1) {};

06 Stock(iht n, int pr=1){

07 shares = n; share_val=pr;

08 };

09 void~Stock(){};

10 public:

11 //成员函数

12 void output(){

13 (2) << shares << ":" << share val << endl;

14 }

15 private:

16 //成员变量

17 int shares;

18 int share_val;

19 };

20

21 void main(){

22 Stock a(1); a.output();

23 Stock b; b.output();

24 Stock c = Stock(); c.output();

25 }

请补齐下述代码中的空缺1和2。

点击查看答案
账号:
你好,尊敬的用户
复制账号
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
简答题
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
简答题
点击打开微信