Dynamic Array of Objects Sans Vector Class
Posted
by
Connor Black
on Stack Overflow
See other posts from Stack Overflow
or by Connor Black
Published on 2012-06-22T03:12:37Z
Indexed on
2012/06/22
3:16 UTC
Read the original article
Hit count: 153
c++
|dynamic-arrays
I am doing a homework assignment for my summer OO class and we need to write two classes. One is called Sale
and the other is called Register
. I've written my Sale
class; here's the .h
file:
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
};
For the Register
class we need to include a dynamic array of Sale
objects in our member data. We cannot use the vector class. How is this done?
Here's my 'Register' '.h'
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;
};
© Stack Overflow or respective owner