简答题

课程名称:程序员

题目:阅读以下说明和C++代码,将应填入(  )处的字句写在答题纸的对栏内。  【说明】  现如今线下支付系统可以使用现金(Cash)、移动支付、银行卡( Card)(信用卡( Creditcard)和储蓄卡( Debitcard))等多种支付方式( PaymentMethod)对物品(tem)账单(Bill)进行支付。图 5-1 是某支付系统的略类图。 【C++代码】 #include <iostream> #include (vector) #include(string) using namespace std class PaymentMethod t public: 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 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(tem2);∥将物品添加到账单中 (2) ( new CreditCard("LI SI","98765432101”);∥信用卡支付 } }; Intmain( ) {         (6) =new PaymentSystem( );     payment->pay ( ); return 0; }

简答题

课程名称:程序员

题目:阅读以下说明和Java代码,将应填入(  )处的字句写在答题纸的对栏内。  【说明】  现如今线下支付系统可以使用现金(Cash)、移动支付、银行卡( Card)(信用卡( Creditcard)和储蓄卡( Debitcard))等多种支付方式( PaymentMethod)对物品(tem)账单(Bill)进行支付。图 5-1 是某支付系统的略类图。 【Java代码】 import java. util. Array List; import java. util. List; interface PaymentMethod {     Public  ( 1 ) } ∥cash、 Debitcard和ltem 实现略,ltem中getPrice( )取当前物品对象的价格 abstract class Card   (2)  {     private final String name, num;     public Card(string name, String num){this.name= name; this, num = num; }     @Overide     public String toString  ( ) {         return String. format(“%s card[name = %s, num =%s}”, this. getType( ), name, num);       @override     public void pay(int cents) {           System. out. printin(“Payed"+ cents+"cents using"+toString( ));         this, execute Transaction(cents);   }    protected abstract String getType( ):    protected abstract void execute Transaction(int cents) } class CreditCard   ( 3 )  {    public CreditCard(String name, String num){  (4)   ;}     @Override    protected String getType( ){ return"CREDIT";}     @Override    protected void execute Transaction(int cents) {        System. out. Println(cents +"paid using Credit Card. ");    } }   Class Bill {//包含所有购买商品的账单    private List<ltem> items =new ArrayList< >( );    public void add(Item item) { items. add(item): }    public intgetTotalPrice( ) {/*计算所有 item 的总价格,代码略*/}    public void pay( PaymentMethod paymentMethod) {//用指定的支付方式完成支付 (5)   (getTotalPrice():   } } public 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);//将物品添加到账单中        Bill.pay(new Creditcard("LI SI”, "98765432101"))∥信用卡支付 }      public static void main(Stringl args) {            (6) = new Paymentsystem( );          payment pay( );     } }

简答题

课程名称:程序员

题目:阅读以下说明和代码,填写程序中的空(1)-(5),将解答写入答题细的对应栏内。【说明】下面程序运行时,对输入的表达式进行计算并输出计算结果。设表达式由两个整数和一个运算符(+或-)构成,整数和运算符之间以空格分隔,运算符可以出现在两个整数之前、之间或之后,整数不超过4位,输入的两个整教和运算符都用字符串表示 例如,输入分别为 “25+7”、“+257”、“257+”时,输出均为“25+7=32”。【C 代码】#include<stdio. h>   Int strain (char*s);                       //将数字字符串转换为整数   Int isOperator(char*str);                 //判断字符串的开头字符是否为运算符   void cal (char op, char a[ ], charb[ ]);      //将数字串转化为对应证书后进行所要求的计算      int main ( )   {         char a[ 10] ,b[10 ],c[10];         scanf ("%s%s%s, a, b, c);         //输入数据的有效性检测略,下面假设输入数据有效、正确         Solve(a, b, c);          Retune ( )   }   int strain (char*s); {     Int val=0       while(*s)       val= (1)+(*s-’0’);                    ∥将数字字符串转换为十进制整数          (2)                         //令字符指针指向下一个数字字符       }        Return val;   }    int isoperator(char* str)   {        return (*str==’+’II*str==’-’):   } Void cal ( char op,char a [ ],char b[ ]) { switch(op) {          case ‘+’:              printf("%s+%s=%d", a, b, straint(a)+straint(b));              break.          case ‘-’:              printf("%s-%s=%d", a, b, strain(a)-straint(b));              Break;        } } void solve(char a[ ], char b[ ], char c [ ]) {//解析输入的3 个字符串,输出表达式及计算结果      if (seperator(a)){            ∥运算符在两个整数之前         ca((  3  );     }      else if(opErator(b)){         ∥运算符在两个整数之间         ca((  4  );      else {                           ∥运算符在两个整数之后         ca((  5  ); } }

简答题

课程名称:程序员

题目:阅读以下说明和C 代码,填写程序的空缺,将解答写入答纸的对应栏內内。 【说明】某市根据每天早上5点测的雾霾指数(PM2.5值)决定是否对车辆进行限行。规则如下: (1)限行时间为周内(即周一到周五),周六周日不限行; (2)根据车牌号的尾号(最后1 位数字)设置限行车辆(车牌号由英文字母和十进制数字构成,长度为6位,至少包含1 位数字); (3)雾霾指数低于 200时,不限行; (4)雾霾指数在区间[200,400)时,一周内每天限行两个尾号的汽车:周一限行1和6 周二限行2和7,周三限行3和8 周四限行4和9;周五限行5和 0,即尾号除以5 的余数相同者在同一天限行; 5)雾霾指数大于等于400时,周内每天限行五个尾号的汽车:周一、周三和周五限行1,3.5,7,9,周二和周四限行0,2,4,6,8,即尾号除少2 的余数相同者在同天限行;下面程序运行时,输入露霾指数、星期(数字1 表示星期一,数字2 表示星期二,…,数7 表示星期日)和车号,输出该车牌号是否跟行的信息【C代码】#include < stdio.h >  #define PM25_L1 200 #define PM25_L2 400 typedef enum {YES, NO} MARKTAG; int is Digit (char ch) {//判断ch 是否为十进制数字字符,是则返回 1,否则返回0        return (ch>= ‘0’&& ch<=’g’); } void prt_msg(char *msg, MARKTAG fiag) {       if(flag == YES)           printf("%s: traffic restrictions\n’’, msg);       else           printf("%s: free\n’’, msg);   Int is Matched (int weekday,int t,int d)//判断是否符合限行规则,是则返回1,否则返回0 {return(weekday%d ==t%d);} void proc(int pm25, int weekday, char * licence) {}     int i,lastd;     if (weekday ==6 II weekday ==7l l   (1)  )         Prt _msg(licence, NO); Else{  for(i=5;i>O;=i--)               if (isDigit(licence[i])){                     lastd=    (2)    // 获取车牌号的尾号                     Break;              }            if(pm25>=PM25_L2) { //限行5个尾号的汽车                if (isMatched(   (3)   ))                    prt_ msg(licence, YES);                 else                    prt msg(licence, NO);             }             else{ //限行2 个尾号的汽车                    if (is Matched(   (4)   ))                        prt msg(licence, YES):                    else                        prt_msg(licence, NO);                  }         } } int main( ) {     int weekday =0, pm25=0;     char licence[7]:    scanf(’’%d % d %s", &pm25, &weekday, licence);   //输入数据的有效性检测略,下面假设输入数据有效、正确    Proc(   (5)   );    return 0; }