Advertisement
Guest User

kine

a guest
Apr 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. /*
  2. Author: Jula Marius
  3. Date: 23/4/18
  4. Description: A kiosk sells newspapers, magazines and books. Each publication has a name, an editorial house, a
  5. number of pages, the number of copies and a price (no VAT). Write the class that models the publications.
  6. Introduce a static member named VAT_value (percentage) and a static method that modifies the value of
  7. this variable. Determine the total income and the average price per page for each publication type. Modify
  8. the VAT and redo the calculations. Order the printing houses by the total income and display the result.
  9. */
  10. #define _CRT_SECURE_NO_WARNINGS
  11. #define MAX 50
  12. #include <iostream>
  13. using namespace std;
  14.  
  15. class Publication {
  16. char *name;
  17. char *ed_house;
  18. int nr_pages;
  19. int nr_copies;
  20. double price;
  21. public:
  22. static int VAT;
  23. Publication();
  24. Publication(char *, char *, int, int, double);
  25. void setVAT(int);
  26. int getPages();
  27. int getCopies();
  28. double getPrice();
  29. double getIncome(Publication);
  30.  
  31. };
  32.  
  33. //Constructor w/o parameters
  34. Publication::Publication() {
  35. name = new char[MAX];
  36. ed_house = new char[MAX];
  37. strcpy(this->name, "Unknown");
  38. strcpy(this->ed_house, "Unknown");
  39. this->nr_pages = 0;
  40. this->nr_copies = 0;
  41. this->price = 0.0;
  42. }
  43.  
  44. int Publication::VAT = 19; //we set the VAT to 19%
  45.  
  46. //Constructor w/ parameters
  47. Publication::Publication(char *newName, char *newEdHouse, int newNrPages, int newNrCopies, double newPrice) {
  48. name = new char[MAX];
  49. ed_house = new char[MAX];
  50. strcpy(this->name, newName);
  51. strcpy(this->ed_house, newEdHouse);
  52. this->nr_pages = newNrPages;
  53. this->nr_copies = newNrCopies;
  54. this->price = newPrice;
  55. }
  56.  
  57. //Getter for the number of pages
  58. int Publication::getPages() {
  59. return this->nr_pages;
  60. }
  61.  
  62. //Getter for the number of copies
  63. int Publication::getCopies() {
  64. return this->nr_copies;
  65. }
  66.  
  67. //Getter for the price
  68. double Publication::getPrice() {
  69. return this->price;
  70. }
  71.  
  72. //Setter for the VAT
  73. void Publication::setVAT(int newVAT) {
  74. this->VAT = newVAT;
  75. }
  76.  
  77. //Method to compute the total income of a publication
  78. double Publication::getIncome(Publication x) {
  79. double total_income = 0.0, price_withVAT = 0.0;
  80. price_withVAT = x.getPrice() + 0.19 * x.getPrice();
  81. total_income = x.getCopies() * price_withVAT;
  82. return total_income;
  83. }
  84.  
  85.  
  86.  
  87.  
  88. int main() {
  89. Publication journal("Adevarul", "Libris", 15, 500, 5.5);
  90. Publication magazine("Cancan", "Daisler", 40, 1000, 11.99);
  91. Publication book("Limbajul C/C++", "UTCN", 600, 1500, 32.5);
  92.  
  93. cout << book.getIncome(book);
  94.  
  95. cout << "\nPress any key to exit . . . ";
  96. getchar();
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement