阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。[C++程序]include <iostream.h>class crop_assessment{int actual_crop;int ideal_crop;public:void set(int in_actual,int in_ideal){actual crop=in_actual;ideal_crop=in_ideal;}int get_actual_crop(void

题目

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

[说明]

下面程序输出一个矩形面积,以及矩形区域上的假想的作物产量。

[C++程序]

include <iostream.h>

class crop_assessment

{

int actual_crop;

int ideal_crop;

public:

void set(int in_actual,int in_ideal)

{

actual crop=in_actual;

ideal_crop=in_ideal;

}

int get_actual_crop(void){ (1) ;}

int get_ideal_crop(void){ (2) ;)

};

Class lot_size

{

int length;

int width;

(3) crop;

public:

void set(int 1,int w,int a,int i)

{

length=1;

width=w;

crop.set(a,i);

}

int get_area(void){return length*width;}

int get_data(void){return (4) ;}

int get_data2(void)freturn (5) ;}

}

int main()

{

Los_size small,medium;

small.set(5,5,5,25);

medium.set(10,10,10,50);

cout<<"For a small lot of area"<<smallget_area()<<“\n”;

cout<<"the actual crops are$"<<small.get_data2()<<"\n";

cout<<"and ideal crops are$”<<small.get_data()<<"\n";

cout<<"For a medium Lot of area"<<medium.get area()<<:\n”;

cout<<"the actual crops are$"<<medium.get_data2()<<"\n";

cout<<"and ideal crops are$"<<medium.get_data()<<"\n";

return 0;

}


相似考题
更多“阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。 [说明] 下面程序输出一个矩形面积, ”相关问题
  • 第1题:

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

    [函数2.1说明]

    下面程序的功能是计算x和y的最小公倍数。

    [函数2.1]

    main()

    { int m,n,d,r;

    seanf("%d %d",&m,&n);

    if(m<n) {r=m;m=n;n=r;}

    (1);

    while (d%n! =0) (2);

    printf("%d\n",d);

    }

    [函数2.2说明]

    下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。

    [函数2.2]

    include <stdio.h>

    main()

    { char c,preChar='\0';

    c = getchar();

    while(c! = '.'){

    if((3)) putchar(c);

    else if(preChar! =' ') putchar(c);

    (4);

    c=(5);

    }

    }


    正确答案:(1)d=m (2) d+=m或d=d+m (3) c!=‘’ (4) preChar=c (5) getchar()
    (1)d=m (2) d+=m或d=d+m (3) c!=‘’ (4) preChar=c (5) getchar() 解析:(1)下文使用了变量d,因此需在此初始化,由下面循环的条件“d%n!=0”知初值不能是n,因此必为m;
    (2)此处while循环生成最小公倍数d,其终止条件是n整除d,因此循环过程中需要保证m整除d并且d尽可能地小,于是d应以m为增量递增;
    (3)当输入的字符非空格时,原样输出;
    (4)程序中变量preChar用于记录上一次读入的字符,循环过程中应不断更新其值;
    (5)接收下一个输入。

  • 第2题:

    ●试题二

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

    【说明】

    该程序运行后,输出下面的数字金字塔

    【程序】

    include<stdio.h>

    main ()

    {char max,next;

    int i;

    for(max=′1′;max<=′9′;max++)

    {for(i=1;i<=20- (1) ;++i)

    printf(" ");

    for(next= (2) ;next<= (3) ;next++)

    printf("%c",next);

    for(next= (4) ;next>= (5) ;next--)

    printf("%c",next);

    printf("\n");

    }

    }


    正确答案:
    ●试题二【答案】(1)(max-′0′)(2)′1′(3)max(4)max-1(5)′1′【解析】该程序共有9行输出,即循环控制变量max的值是从1~9。每行输出分3部分,先用循环for语句输出左边空白,(1)空填"(max-′0′)";再用循环输出从1到max-′0′的显示数字,即(2)空和(3)空分别填1和max;最后输出从max-′1′~1的显示数字,即(4)空和(5)空分别填和max-1和′1′。

  • 第3题:

    阅读下列说明和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参数,

  • 第4题:

    阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。

    [说明]

    下面的流程图用于计算一个英文句子中最长单词的长度(即单词中字母个数)MAX。假设该英文句子中只含字母、空格和句点“.”,其中句点表示结尾,空格之间连续的字母串称为单词。

    [流程图]


    正确答案:(1)MAX←0 (2)←L+1 (3)MAX←L (4)≠ (5)L←0
    (1)MAX←0 (2)←L+1 (3)MAX←L (4)≠ (5)L←0 解析:本题用到的三个变量及其作用分别为:A,存放输入的一个字符;MAX,存放当前为止最长单词的长度;L,存放当前单同的长度。
    (1)使用变量MAX应先赋予初值,由上下文知其初值为0;
    (2)读取当前单词时,每读人一个字母,单词长度值L应增1;
    (3)当前单词长度L比MAX时,应更新MAX的值;
    (4)若当前字符不是句点,应当继续读取字符;
    (5)读取下一个单词前,应当重置L的值。

  • 第5题:

    试题三(共 15 分)

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


    正确答案:

  • 第6题:

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






    答案:
    解析: