niusouti.com

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include include阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include < string. h >define Max 1000class Bank{int index;char date [Max] [10]; // 记录交易日iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱int rest[ Max]; //

题目
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include

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

【C++程序】

include < stdio. h >

include < string. h >

define Max 1000

class Bank

{

int index;

char date [Max] [10]; // 记录交易日

iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱

int rest[ Max]; // 记录每次交易后余额

static iht sum; // 账户累计余额

public:

Bank( ) {index =0;}

void deposit( char d[ ] , int m) //存入交易

{

strcpy ( date [ index ], d);

amount[ index] = m;

(1);

rest[ index] = sum;

index++;

}

void withdraw (char d[ ], int m) //取出交易

{

strcpy( date[ index] ,d);

(2);

(3);

rest[ index] = sum;

index++;

}

void display( );

};

int Bank:: sum = 0;

void Bank:: display ( ) //输出流水

{

int i;

printf("日期 存入 取出 余额\n");

for (4)

{

printf(" %8s" ,date[i] );

if (5)

printf(" %6d" , -amount[i] );

else

printf( "%6d ",amount[i] );

printf( "% 6d\n" ,rest[i] );

} }

void main( )

{

Bank object;

object. deposit ( "2006.2.5", 1 00 );

object. deposit( "2006.3.2" , 200);

object. withdraw( "2006.4.1", 50);

object. withdraw( "2006.4.5", 80);

object. display ( );

}

本程序的执行结果如下:

日期 存入 取出 余额 2006.2.5 100 100

2006.3.2 200 300

2006.4.1 50 250

2006.4.5 80 170


相似考题
更多“阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include ”相关问题
  • 第1题:

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

    【说明】

    下面程序的功能是计算并输出某年某月的天数。

    【C++程序】

    include<iostream>

    using namespace std;

    (1) Month{Jan,Feb,Mar,Art,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec};

    class Date{

    public:

    Date(int year,Month m_month){

    (2) =year;

    if (m_month<Jan‖m_month>Dec) month=Jan;

    else month=m_month;

    };

    ~Date(){};

    bool IsLeapYear(){

    return ((year%4==0 && year%1001!=0)‖year%400==0);

    };

    int CaculateDays(){

    switch( (3) ){

    case Feb:{

    if( (4) )return29;

    e1Se return 28;

    }

    case Jan:case Mar:case May:case Jul:case AUg:case Oct:

    case Dec:retllrn 31;

    case Apr:case Jun:Case Sep:case Nov:roturu30;

    }

    };

    private:

    int year;

    Month month;

    };

    void main(){

    Date day(2000,Feb);

    tout<<day. (5) ();

    }


    正确答案:(1)enum (2)this->year (3)month (4)IsLeapYear() (5)Cacu lateDays
    (1)enum (2)this->year (3)month (4)IsLeapYear() (5)Cacu lateDays 解析:程序的空(1)所在行的目的是定义一枚举类型用来表示一年12个月,所以空1应填上enum;在类Data中定义了两个私有变量year和m_month分

    别用来存储年份和月份,在Data类的构造函数中,要求给出年份和月份来构造一个Data类的对象,因为构造函数中参数名称和私有变量的名称

    相同,为了在构造函数中使用私有变量year,必须加上 this指针,所以空(2)应填上this->year。
    函数CaculateDays用宋计算某一年某个月的天数,不论是否是闰年,除2月份以外,所有的大月都是31天,小月都是30天;如果是闰年,2

    月份是29天,否则是28天。根据分析,空(3)应填上m month用来判断月份是大月、小月或者二月,空(4)用来判断是否是闰年,调用函数

    IsLeapYear()即可得到结果。

  • 第2题:

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

    【说明】

    阅读下面几段C++程序回答相应问题。

    比较下面两段程序的优缺点。

    ①for (i=0; i<N; i++ )

    {

    if (condition)

    //DoSomething

    else

    //DoOtherthing

    }

    ②if (condition) {

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

    //DoSomething

    }else {

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

    //DoOtherthing

    }


    正确答案:程序1优点:程序简洁;缺点:多执行了N-1次逻辑判断并且程序无法循环“流水”作业使得编译器无法对循环进行优化处理降低了效率。 程序2优点:循环的效率高;缺点:程序不简洁。
    程序1优点:程序简洁;缺点:多执行了N-1次逻辑判断,并且程序无法循环“流水”作业,使得编译器无法对循环进行优化处理,降低了效率。 程序2优点:循环的效率高;缺点:程序不简洁。

  • 第3题:

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






    答案:
    解析:

  • 第4题:

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

    【说明】

    下面程序的功能是计算并输出某年某月的天数,函数IsLeap Year()能够判断是否是闰年。

    【C++程序】

    include < iostream >

    using namespace std;

    (1) Month {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };

    class Date {

    public:

    Date( int year, Month m_ month) {

    this→year = year;

    if( (2) ) month: Jan;

    else month = m_ month;

    };

    ~Date(){};

    bool IsLeap Year( ) {

    return ((year%4= =0 &&year% 100 ! =0)|| year%400= =0);

    };

    int CaculateDays( ) {

    switch(m_month ) {

    case (3) ;{

    if (4) return 29;

    else return 28;

    }

    case Jan: case Mar: case May: case Jul: case Aug: case Oct: case Dec: return 31;

    case Apr: case Jun: case Sop: case Nov: return 30;

    }

    }

    private:

    int year;

    Month month;

    };

    void main( ) {

    Date day(2000,Feb);

    cout < <day. (5) ( );

    }


    正确答案:(1)enum
    (1)enum 解析:枚举类型变量month定义,这里填入enum。

  • 第5题:

    试题三(共 15 分)

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


    正确答案: