fork download
  1. #include<iostream>
  2. #include<string>
  3. //#include "banned.h"
  4. //#include<cassert>
  5. using namespace std;
  6.  
  7. /*2a.*/
  8. class Date
  9. {
  10. int day;
  11. int month;
  12. int year;
  13. public:
  14. Date (int, int, int) : day(1), month(1), year(1970) {}
  15. int getDay() {return day;}
  16. int getMonth() {return month;}
  17. int getYear() {return year;}
  18. };
  19.  
  20. /*2b. InventoryItem containing Name, Cost, Quantity, DatePurchased(Object of the date Class), InventoryTotal(Static Variable)*/
  21.  
  22. class InventoryItem
  23. {
  24. string Name;
  25. double Cost;
  26. int Quantity;
  27.  
  28. static int InventoryTotal;
  29.  
  30. public:
  31. Date DatePurchased; /*Object of the date class*/
  32. InventoryItem() : Name(" "), Cost(0.0), Quantity(0), DatePurchased(1,1,1970) {}
  33.  
  34. void setInventoryTotal(int amt) { InventoryTotal = amt; }
  35. string getName() {return Name;}
  36. double getCost() {return Cost;}
  37. int getQuantity() {return Quantity;}
  38. // Date getDatePurchased() { }
  39. int getInventoryTotal() {return InventoryItem::InventoryTotal;}
  40.  
  41. /*2.c friend function to change quantity of Inventory item*/
  42.  
  43. friend void changeQuantity(int);
  44. void changeQuantity(int quan) { Quantity = quan; }
  45. };
  46.  
  47. int main ()
  48. {
  49. /*3. main function that instantiates 10 InventoryItem objects using arrays; should use friend function to change
  50. the quantity of 4 InventoryItem objects*/
  51.  
  52. InventoryItem testit;
  53. /* changing quantity works
  54. testit.changeQuantity(10.00);
  55. cout << testit.getQuantity();
  56. */
  57.  
  58. cout << testit.DatePurchased.getDay(); /* this doesn't */
  59. /* 10 iterations loop */
  60. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
1