
Untitled
By: a guest on
Jul 17th, 2012 | syntax:
None | size: 1.68 KB | hits: 12 | expires: Never
Trouble accessing private object data
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 = 5;
int numSales;
Sale* sale;
};
void Register::RingUpSale(ItemType item, int basePrice){
if(numSales == listSize){
listSize += 5;
Sale * tempArray = new Sale[listSize];
memcpy(tempArray, sale, numSales * sizeof(Sale));
delete [] sale;
sale = tempArray;
}
sale[numSales]->item = item; //this works for some reason
sale[numSales]->total = basePrice; // this doesn't
if(item == 'CREDIT'){
sale[numSales]->tax = 0; // and this doesn't
sale[numSales]->total = basePrice; // and neither does this
amountMoney -= basePrice;
}
++numSales;
}