题目:
【流程图】 注1: “循环开始”框内给出循环控制变量的初值、终值和增值(默认为1),格式为: 循环控制变量=初值,终值[,增值]注2: 函数int(x)为取x的整数部分,即不超过x的最大整数。
考点:流程图
题目:
【问题】设有如下数组定义: int data1 = 4, 2, 6, 3, 1; int data2 = 4, 2, 6, 3, 1; int data3 = 4, 2, 6, 3, 1;请分别给出下面的函数调用执行后,数组data1、data2和data3各自的元素序列。 (1)bubbleSort(data1, 5, less); (2) bubbleSort(data2, 5, larger); (3) bubbleSort(data3, 3, larger);
考点:C程序设计案例
题目:
【Java代码】 Import java.util. ArrayList; import java.util.List; interface PaymentMethod public (1) ;// Cash、DebitCard和Item实现略,Item中getPrice( )获取当前物品对象的价格abstract class Card (2) private final String name, num; public Card(String name, String num) this.name = name; this.num = num; @Oveiride public String toString ( ) return String.format(“%s cardname = %s, num = %s”,this.getType (), name, num); @Override public void pay(int cents) System.out.println(“Payed + cents + “ cents using “ + toString( )); this.executeTransaction(cents); protected abstract String getType( ); protected abstract void executeTransaction(int cents);class CreditCard (3) public CreditCard(String name, String num) (4) ; @Override protected String getType( ) return CREDIT; @Override protected void executeTransaction(int cents) System.out.println(cents + paid using Credit Card. ’); class Bill //包含所有购买商品的账单 private List<Item> 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(String args) (6) = new PaymentSystem( ); payment.pay( );
考点:Java程序设计案例
题目:
【 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( ) + cardname = + 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 PaymentSystempublic: void pay( ) Bill* bill = new Bill( ); Item* item1= new Item1234,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;
考点:C++程序设计
其它类目题库