OOクラス用にSaleとRegisterの2つのクラスを作成しようとしています。これが2つのヘッダーです。
セールヘッダー:
enum ItemType {BOOK, DVD, SOFTWARE, CREDIT};
class Sale
{
public:
Sale(); // default constructor,
// sets numerical member data to 0
void MakeSale(ItemType x, double amt);
ItemType Item(); // Returns the type of item in the sale
double Price(); // Returns the price of the sale
double Tax(); // Returns the amount of tax on the sale
double Total(); // Returns the total price of the sale
void Display(); // outputs sale info (described below)
private:
double price; // price of item or amount of credit
double tax; // amount of sales tax (does not apply to credit)
double total; // final price once tax is added in.
ItemType item; // transaction type
};
ヘッダーを登録します。
class Register{
public:
Register(int ident, int amount);
~Register();
int GetID(){return identification;}
int GetAmount(){return amountMoney;}
void RingUpSale(ItemType item, int basePrice);
void ShowLast();
void ShowAll();
void Cancel();
int SalesTax(int n);
private:
int identification;
int amountMoney;
int listSize;
int numSales;
Sale* sale;
};
Registerクラスでは、Saleオブジェクトの動的配列を保持する必要があります。私はこれを行うことができます。私の問題は、「登録」のRingUpSale()関数にあります。その関数から「Sale」のプライベートメンバーデータにアクセスして変更できる必要があります。例えば:
sale[numSales]->item = item;
sale[numSales]->total = basePrice; // Gets an error
if(item == CREDIT){
sale[numSales]->tax = 0; // Gets an error
sale[numSales]->total = basePrice; // Gets an error
amountMoney -= basePrice;
}
else {
sale[numSales]->tax = 0.07*basePrice; // Gets an error
sale[numSales]->total = (0.07*basePrice)+basePrice; // Gets an error
amountMoney += basePrice;
}
このアクセスを可能にする方法がわかりません。たぶん、継承や友達の構造を通して?
そして、これのデザインをぼろぼろにする前に、これは宿題のためであることを覚えておいてください、それでばかげた制限があります。そのうちの1つは、私が書いたものから「Sale.h」を変更できないことです。そして、私は「Register.h」にプライベート関数を追加することしかできません。
RingUpSale()関数の説明:
- RingUpSaleこの関数を使用すると、販売のアイテムタイプと基本価格をパラメーターとして渡すことができます。この関数は、販売を販売リストに保存し、レジの金額を適切に更新する必要があります。購入したアイテムは、レジスターにお金を追加します。販売するアイテムの基本価格に消費税を追加する必要があることに注意してください。販売タイプがクレジットの場合は、レジスターから金額を差し引く必要があります。
またこれ:
-(ヒント:レジスタ内では、Saleオブジェクトの動的配列を保持していることに注意してください。これは、これらの関数のほとんどがこの配列を使用して作業を行うことを意味します-また、Saleクラスのメンバー関数を呼び出すこともできます)。