Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. class VideoGame
  8. {
  9.  
  10. private:
  11.  
  12. string *name;
  13. double *rating;
  14. double *price;
  15.  
  16. public:
  17.  
  18. void setName(string n){
  19.  
  20. name = new string;
  21. *name = n;
  22.  
  23. }
  24.  
  25. void setPrice(double p){
  26.  
  27. price = new double;
  28. *price = p;
  29.  
  30. }
  31.  
  32. void setRating(double r){
  33.  
  34. rating = new double;
  35. *rating = r;
  36. }
  37.  
  38.  
  39.  
  40. string getName()
  41. {
  42. return *name;
  43. }
  44.  
  45. double getRating()
  46. {
  47. return *rating;
  48. }
  49.  
  50. double getPrice()
  51. {
  52. return *price;
  53. }
  54.  
  55. void Show()
  56. {
  57.  
  58. cout << "VIDEO GAME INFORMATION" << endl;
  59. cout << "______________________" << endl;
  60. cout << endl;
  61. cout << "Video Game Title : " << *name << endl;
  62. cout << "Retail Price : $" << fixed << setprecision(2) << *price << endl;
  63. cout << "Game Rating (out of 5) : " << fixed << setprecision(1) << *rating << endl;
  64. cout << endl;
  65.  
  66. }
  67.  
  68. VideoGame()
  69. {
  70. name = new string;
  71. *name = "";
  72.  
  73. rating = new double;
  74. *rating = 0;
  75.  
  76. price = new double;
  77. *price = 0;
  78.  
  79. }
  80. VideoGame(string n, double r, double p)
  81. {
  82.  
  83. name = new string;
  84. *name = n;
  85.  
  86. rating = new double;
  87. *rating = r;
  88.  
  89. price = new double;
  90. *price = p;
  91.  
  92. }
  93.  
  94. ~VideoGame(){
  95.  
  96.  
  97. delete name;
  98. delete rating;
  99. delete price;
  100. cout << "Destructor Called" << endl;
  101.  
  102. }
  103.  
  104.  
  105. };
  106.  
  107. #include <iostream>
  108.  
  109. #include "VideoGame.h"
  110.  
  111. using namespace std;
  112.  
  113. int main(){
  114.  
  115. VideoGame *vg = NULL;
  116. vg = new VideoGame;
  117.  
  118.  
  119. //Part One, testing get's and sets, printing on screen.
  120. cout << "PART ONE" << endl;
  121. cout << endl;
  122.  
  123. vg->setName("Paper Mario Color Splash");
  124. vg->setPrice(59.99);
  125. vg->setRating(4.9);
  126.  
  127.  
  128. cout << "Game Name : " << (*vg).getName() << endl;
  129.  
  130. cout << "Price : " << (*vg).getPrice() << endl;
  131. cout << "Rating : " << (*vg).getRating() << endl;
  132.  
  133. cout << endl;
  134.  
  135. delete vg;
  136.  
  137. cout << "PART TWO" << endl;
  138. cout << endl;
  139.  
  140.  
  141.  
  142. //Part Two, using arrays to set values.
  143.  
  144. VideoGame *VideoArray = NULL;
  145.  
  146. VideoArray = new VideoGame[100]; //Set to 100 elements.
  147.  
  148. VideoArray[0] = { "Super Mario Brothers", 4.0, 39.99 };
  149.  
  150. VideoArray[1] = { "Pac-Man", 5.0, 9.99 };
  151.  
  152. int size = 2;
  153.  
  154. //A for loop to display the multiple possible elements of the array
  155. for (int i = 0; i < size; i++)
  156. {
  157.  
  158. VideoArray[i].Show();
  159.  
  160. }
  161.  
  162.  
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement