我正在为我的暑期 OO 课做作业,我们需要写两节课。一个被称为Sale
,另一个被称为Register
。我写了我的Sale
课;这是.h
文件:
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
private:
double price; // price of item or amount of credit
double tax; // amount of sales tax
double total; // final price once tax is added in.
ItemType item; // transaction type
};
对于这个Register
类,我们需要Sale
在我们的成员数据中包含一个动态的对象数组。
所以我的两个问题是:
- 我是否需要从我的
Sale
班级继承到我的Register
班级(如果需要,如何)? - 我可以有一个动态数组的通用示例吗?
编辑:我们不能使用向量。