阅读下列程序说明和C++代码,将应填入(n)处的字句写在对应栏内。[说明]①定义私有数据成员code、english分别用于表示考生的编号、英语成绩,它们都是int型的数据。②完成成员函数void Student::inputinformation()的定义,该函数用于用户输入一个考生对象的信息,输入格式如下:输入编号:英语成绩:计算机成绩:③利用已实现的类Student的成员函数,完成函数void firstname(Student *A[],int uum)的定义,该函数根据考生信息A[],输出num

题目

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

[说明]

①定义私有数据成员code、english分别用于表示考生的编号、英语成绩,它们都是int型的数据。

②完成成员函数void Student::inputinformation()的定义,该函数用于用户输入一个考生对象的信息,输入格式如下:

输入编号:

英语成绩:

计算机成绩:

③利用已实现的类Student的成员函数,完成函数void firstname(Student *A[],int uum)的定义,该函数根据考生信息A[],输出num个考生中总分最高者的编号及其相应的总分,在此不考虑总分相同的情况。

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

include < iostream. h >

class Student

(1)

int computer;

int total;

public

void getinformation( );

void computesum( );

int getcode( );

int gettotalscore( );

~Student( );

};

void Student: :getinformation( )

{

(2)

cout <<"英语成绩:";

cin> >english;

cout <<"计算机成绩:";

cin > > computer;

void Student:: computesum ( )

total = english + computer;

cout <<"编号" << code <<"总分:" <<total << endl;

int Student::getcode( )

return code;

}

int Student:: gettotalscore ( )

{

return total;

}

void firstname(Student * A[] ,int num)

{

(3)

tempsum = ( * A[0] ). gettotalscore( );

for( int i=1; i <num; i++)

{

if ( ( ( * A[i] ). gettotalscore( ) ) > tempsum)

{

tempcode = ( * A[i] ). getcode( );

tempsum = ( * A[i] ). gettotalscore( );

}

}

cout <<"总分最高者--" << tempcode <<":" << tempsum <<endl;

}

void main( )

{

Student * A[3];

int i,n =3

for(i=0;i<n;i ++)

A[i] = new Student;

A[i] -> getinformation( )

for(i=0;i<n;i ++)

{

A[i] -> computesum( )

firstname ( A,3 );

}


相似考题
更多“阅读下列程序说明和C++代码,将应填入(n)处的字句写在对应栏内。 [说明] ①定义私有数据成员code、en ”相关问题
  • 第1题:

    试题三(共 15 分)

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


    正确答案:

  • 第2题:

    阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。

    【C++代码】 #include using namespace std; class invoice{ public: (1){ cout<<"This is the content of the invoice!"<

    答案:
    解析:
    (1) virtual void printInvoice() (2) ticket->printInvoice() (3) Decorator::printInvoice() (4) Decorator::printInvoice() (5) &a
    【解析】

    试题分析
    1.Invoice类下,义虛函数,按类图,函数名是printInvoice
    2.前面定义对象名是ticket,那么在ticket不为空的时候调用函数printInvoice
    3.这部分填写发票的抬头,看类图应该实现函数printInvoice ,Decorator装饰模式使用该方法
    4.这部分是发票的脚注,看类图应该实现函数printlnvoice,Decorator装饰模式使用该方法
    5.FootDecorator a(NULL) ;脚步的装饰参数是a,调用a参数,

  • 第3题:

    阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。



    答案:
    解析:
    1: void update()2: Observer3: obs.update()4: Subject5: Attach(this)

  • 第4题:

    阅读下列说明和 C ++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 6-1 所示。

    【C++ 代码】#includeusing namespace std;class BrakeBehavior{public:(1) ; /*其余代码省略*/};class LongWheelBrake : public BrakeBehavior{public:void stop(){cout <<"模拟长轮胎刹车痕迹! "<< end1;} /*其余代码省略*/};class ShortWheelBrake : public BrakeBehavior{public:void stop(){cout<"模拟短轮胎刹车痕迹! "<< end1;} /*其余代码省略*/};class Car{protected: (2) wheel;public:void brake(){ (3) ; } /*其余代码省略*/};class ShortWheelCar : public Car{public:ShortWheelCar(BrakeBehavior* behavior){ (4);} /*其余代码省略*/};int main(){BrakeBehavior* brake= new ShortWheelBrake();ShortWheelCar car1(brake):car1. (5) ;return 0;}


    答案:
    解析:
    1. virtual void stop( )=02. BrakeBehavior*3. Wheel->stop( )4. wheel=behavior5. brake( )

  • 第5题:

    阅读下列说明和C++代码,回答问题,将解答填入答题纸的对应栏内。
    【说明】某航空公司的会员积分系统将其会员划分为:普卡 (Basic)、银卡(Silver)和金卡 (Gold) 三个等级。非会员 (NonMember) 可以申请成为普卡会员。会员的等级根据其一年内累积 的里程数进行调整。描述会员等级调整的状态图如图 5-1 所示。现采用状态 (State) 模式实现上述场景,得到如图 5-2 所示的类图。




    【问题1】(15分)阅读上述说明和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。


    答案:
    解析:
    注意:原版的题目应该是Cbasic、CSilve。(1) virtual double travel(int miles,FrequentFlyer* context)=0(2)context->setState(context->Cbasic)(3)context->setState(context->CSilve)(4)context->setState(context->Cbasic)(5)context->setState(context->CSilve)

  • 第6题:

    阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。
    【说明】
    阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。
    【说明】
    某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种
    类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。






    答案:
    解析: