Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 1.68 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Trouble accessing private object data
  2. enum ItemType {BOOK, DVD, SOFTWARE, CREDIT};
  3.  
  4. class Sale
  5. {
  6. public:
  7. Sale();         // default constructor,
  8.             // sets numerical member data to 0
  9.  
  10. void MakeSale(ItemType x, double amt);  
  11.  
  12. ItemType Item();        // Returns the type of item in the sale
  13. double Price();     // Returns the price of the sale
  14. double Tax();       // Returns the amount of tax on the sale
  15. double Total();     // Returns the total price of the sale
  16. void Display();     // outputs sale info (described below)
  17.  
  18. private:
  19. double price;   // price of item or amount of credit
  20. double tax;     // amount of sales tax (does not apply to credit)
  21. double total;   // final price once tax is added in.
  22. ItemType item;  // transaction type
  23. };
  24.        
  25. class Register{
  26. public:
  27.  
  28. Register(int ident, int amount);
  29. ~Register();
  30. int GetID(){return identification;}
  31. int GetAmount(){return amountMoney;}
  32. void RingUpSale(ItemType item, int basePrice);
  33. void ShowLast();
  34. void ShowAll();
  35. void Cancel();
  36. int SalesTax(int n);
  37.  
  38. private:
  39.  
  40. int identification;
  41. int amountMoney;
  42. int listSize = 5;
  43. int numSales;
  44. Sale* sale;
  45. };
  46.        
  47. void Register::RingUpSale(ItemType item, int basePrice){
  48. if(numSales == listSize){
  49.         listSize += 5;
  50.         Sale * tempArray = new Sale[listSize];
  51.         memcpy(tempArray, sale, numSales * sizeof(Sale));
  52.         delete [] sale;
  53.         sale = tempArray;
  54.     }
  55.     sale[numSales]->item = item; //this works for some reason
  56.     sale[numSales]->total = basePrice; // this doesn't
  57.     if(item == 'CREDIT'){
  58.             sale[numSales]->tax = 0; // and this doesn't
  59.             sale[numSales]->total = basePrice; // and neither does this
  60.             amountMoney -= basePrice;
  61.     }
  62.     ++numSales;
  63. }