本帖最后由 丙丁先生 于 2024-9-8 07:33 编辑
阅读以下说明和C++代码,将应填入( )处的字句写在答题纸的对栏内。【说明】 现如今线下支付系统可以使用现金(Cash)、移动支付、银**( Card)(信用*( Creditcard)和储蓄卡( Debitcard))等多种支付方式( PaymentMethod)对物品(tem)账单(Bill)进行支付。
图 5-1 是某支付系统的略类图。
1.jpg【C++代码】
#include <iostream>
#include (vector)
#include(string)using namespace stdclass PaymentMethod tpublic: virtual void pay(int cents)=0;};
//class、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->execute Transaction(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*>tems;∥包含物品的 vector Public:
void add(Item" item items. push back(item):}
int getTotalPrice ( ) { /*计算所有 item 的总价格,代码略”/}
old pay( PaymentMethod* paymentMethod) {//用指定的支付方式完成支付(1) (getTotalPrice());}}
Class PaymentSystemPublic:void pay( ){ Bill" bill new Bill( );
Item"item1= new Item"1234”, 10);
Item*item2= new Item(“5678", 40);
Bill_>add(item1);bill>add(tem2);∥将物品添加到账单中(2) ( new CreditCard("LI SI","98765432101”);
∥信用*支付}};Intmain( ) { (6) =new PaymentSystem( );
payment->pay ( );return 0;}
通篇理解,降维打击,软考已成过去时,断章取义不可取!
|