登录   |   注册
    准考证打印   论文投票   报考指南   论文辅导   软考培训   郑重申明  
您现在的位置:  首页 > 软考学苑 > 软考历年真题 > 程序员-真题 >> 正文
正文
2019上半年软考程序员下午真题(六)
来源: 作者: 时间;2019-07-16 14:13:11 点击数: 尚大软考交流群:376154208
6、阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】现如今线下支付系统可以使用现金(Cash)、移动支付、银行卡(Card)(信用卡 (CreditCard)和储蓄卡(DebitCard))等多种支付方式(PaymentMethod)对物品(Item) 账单(Bill)进行支付。图6-1是某支付系统的简略类图。问题内容:【 C++代码 】#include <iostream>#include〈vector〉#include〈string
尚大教育,教育至尚,人才为大。

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

【说明】

现如今线下支付系统可以使用现金(Cash)、移动支付、银行卡(Card)(信用卡 (CreditCard)和储蓄卡(DebitCard))等多种支付方式(PaymentMethod)对物品(Item) 账单(Bill)进行支付。图6-1是某支付系统的简略类图。

1.jpg

问题内容:

【 C++代码 】

#include <iostream>

#include〈vector〉

#include〈string〉

using namespace std;

class PaymentMethod {

public: virtual void pay(int cents)=0;

};

// Cash、DebitCard和Item实现略,Item中getPrice( )获取当前物品对象的价格

class Card : public PaymentMethod {

private: string name, num;

public:

Card(string name, string num) {this->name = name; this->num = num; }

string toString( ) {

return this->getType( ) + " card[name = "+ name + ",num = " + num + "]"; )

}

void pay(int cents) {

cout<< "Payed " <<cents << " cents using " <<toString( ) <<end1;

this->executeTransaction(cents);

}

protected:

virtual string getType( )=0;

virtual void     (1)      =0:

};

class CreditCard      (2)        {

public:

CreditCard(stringname, stringnum)      (3)        {

}

protected:

string getType( ) { return " CREDIT " ; }

void executeTransaction(int cents) {

cout<<cents << " paid using " <<getType( )<< " Card." << end1;

}

};

class Bill {//包含所有购买商品的账单

private:

vector< Item*> items; //包含物品的 vector

public:

void add(Item* item){ items.push_back(item); }

int getTotalPrice( ){ /*计算所有item的总价格,代码略*/}

void pay(PaymentMethod* paymentMethod) {//用指定的支付方式完成支付

(4)        (getTotalPrice( ));

}

};

class PaymentSystem{

public:

void pay( ) {

Bill* bill = new Bill( );

Item* item1= new Item"1234",10); Item* item2 = new Item("5678",40);

bill->add(item1); bill->add(item2); //将物品添加到账单中

(5)        (new CreditCard("LI SI", "98765432101")); //信用卡支付

}

};

Intmain( ) {

(6)        = new PaymentSystem( );

payment->pay( );

return 0;

}

尚大教育,教育至尚,人才为大。
 
   各省软考办 
 
来顶一下
返回首页
返回首页
上一篇:2019上半年软考程序员下午真题(五)
下一篇:返回列表
 相关文章
 
 
跟贴共
笔 名 :   验证码:
网友评论仅供其表达个人看法,并不表明尚大教育同意其观点或证实其描述
距离2022年05月28-29日软考考试还有
尚大软考交流群:376154208
软考各地考务机构
历年真题汇总




各省市软考报名简章