Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include "Gamer8r.h"
  5. #include<cstdlib>
  6. using namespace std;
  7.  
  8. void menu();
  9. int main(){
  10. string gName, gType;
  11. int points, raters, pos;
  12. double pAvr;
  13. const int cap = 5;
  14. Game* arr[cap];
  15. int i = 0;
  16. int m1s,m2s;
  17.  
  18. menu();
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. system("pause");
  26. return 0;
  27. }//EO main
  28.  
  29. void menu(){
  30.  
  31. string gName, gType;
  32. int points, points2, raters=0, pos;
  33. double pAvr;
  34. const int cap = 5;
  35. Game arr[cap];
  36. int i = 0;
  37. int m1s=10, m2s;
  38.  
  39. while (m1s != 0){
  40.  
  41. cout << "*GameR8r*" << endl;
  42. cout << "Menu" << endl;
  43. cout << "1. Add Game" << endl << "2. Review Game" << endl << "3. Delete Game" << endl << "4. List All Games" << endl << "5. Save List" << endl << "6. Load List" << endl << "0. Exit";
  44. cout << endl << " Select:";
  45. cin >> m1s;
  46. cin.ignore();
  47. system("cls");
  48. switch (m1s){
  49.  
  50. case(1) : {
  51.  
  52. cout << "* Add Game *" << endl;
  53. cout << "Enter Game-name: ";
  54. getline(cin, gName);
  55.  
  56. arr[i].setgName(gName);
  57.  
  58. cout << endl << "Enter GameType: " << endl <<
  59. "1. Emulator" << endl << "2. FPS" << endl << "3. MMO" << endl << "4. MMORPG" << endl << "5. RPG" << endl << "6. Strategy" << endl << "0. back" << endl << "Select:";
  60. cin >> m2s;
  61. cin.ignore();
  62. switch (m2s){
  63. case(1) : {
  64. gType = "Emulator";
  65. arr[i].setgType(gType);
  66. pos = i + 1;
  67. arr[i].setpos(pos);
  68. i++;
  69. }
  70. break;
  71. case(2) : {
  72. gType = "FPS";
  73. arr[i].setgType(gType);
  74. pos = i + 1;
  75. arr[i].setpos(pos);
  76. i++;
  77. }
  78. break;
  79. case(3) : {
  80. gType = "MMO";
  81. arr[i].setgType(gType);
  82. pos = i + 1;
  83. arr[i].setpos(pos);
  84. i++;
  85. }
  86. break;
  87. case(4) : {
  88. gType = "MMORPG";
  89. arr[i].setgType(gType);
  90. pos = i + 1;
  91. arr[i].setpos(pos);
  92. i++;
  93. }
  94. break;
  95. case(5) : {
  96. gType = "RPG";
  97. arr[i].setgType(gType);
  98. pos = i + 1;
  99. arr[i].setpos(pos);
  100. i++;
  101. }
  102. break;
  103. case(6) : {
  104. gType = "Strategy";
  105. arr[i].setgType(gType);
  106. pos = i + 1;
  107. arr[i].setpos(pos);
  108. i++;
  109. }
  110. break;
  111. case(0) : {
  112. menu();
  113.  
  114. }//EO sc2(c0)
  115.  
  116. }//EO sc2
  117. cout << arr[i].getgName() << "was successfully inserted into the list. (Position: " << pos << ")." << endl;
  118.  
  119. }//EO sc1(c1)
  120. break;
  121.  
  122. case(2) : {
  123. int revSel;
  124. cout << "* Review Game *" << endl;
  125. for (int i = 0; i < cap; i++){
  126. cout << arr[i].getpos() << " " << arr[i].getgName() << " ( " << arr[i].getgType() << " )." << endl;
  127. }
  128. cout << endl << "Review Game: ";
  129. cin >> revSel;
  130.  
  131. for (int i = 0; i < cap; i++){
  132. if (revSel == i+1){
  133. cout << "You have chosen to review " << arr[i].getgName() << endl;
  134. cout << "How many points would you like to give it? (1-5): ";
  135. cin >> points2;
  136. points=(arr[i].getpoints() + points2);
  137.  
  138. arr[i].setpoints(points);
  139. raters = arr[i].getraters()+1;
  140.  
  141. arr[i].setraters(raters);
  142. pAvr = ((arr[i].getpoints())/(arr[i].getraters()));
  143. arr[i].setpAvr(pAvr);
  144. }
  145.  
  146.  
  147. }
  148.  
  149.  
  150. }
  151. break;
  152. case(3) : {
  153.  
  154. cout << "* Delete Game *";
  155. int delSel;
  156. for (int i = 0; i < cap; i++){
  157.  
  158. cout << arr[i].getpos() << " " << arr[i].getgName() << " ( " << arr[i].getgType() << " )." << endl;
  159.  
  160. }
  161. cout << endl << "Delete Game: ";
  162. cin >> delSel;
  163. for (int i = 0; i < cap; i++){
  164. if (delSel == pos){
  165. arr[i].Game::Game();
  166. }
  167. }
  168. }
  169. break;
  170. case(4) : {
  171.  
  172. cout << "* List All Games *";
  173. cout << endl;
  174. for (int i = 0; i < cap; i++){
  175. cout << arr[i].getpos() << " " << arr[i].getgName() << " ( " << arr[i].getgType() << " )." << endl << "SCORES: " << arr[i].getpoints() << " ." << endl;
  176. cout << "Avarage: " << arr[i].getpAvr() << "/5. Number of voters: " << arr[i].getraters() << "." << endl;
  177. }
  178. }
  179. break;
  180. case(5) : {
  181.  
  182. cout << "* List Saved *"<<endl;
  183.  
  184. ofstream myfile;
  185. myfile.open("GameR8r.txt");
  186.  
  187. for (int i = 0; i < cap; i++){
  188.  
  189. int pos = arr[i].getpos();
  190. string gName = arr[i].getgName();
  191. string gType = arr[i].getgType();
  192. int points = arr[i].getpoints();
  193. double pAvr = arr[i].getpAvr();
  194. int raters = arr[i].getraters();
  195.  
  196. myfile << pos, gName, gType, points, pAvr, raters;
  197. }
  198.  
  199.  
  200.  
  201. myfile.close();
  202.  
  203. }
  204. break;
  205. case(6) : {
  206. cout << "* List Loaded *";
  207. ifstream myfile;
  208. myfile.open("GameR8r.txt");
  209.  
  210. for (int i = 0; i < cap; i++){
  211.  
  212. pos,gName,gType,points,pAvr,raters;
  213.  
  214. arr[i].setpos(pos);
  215. arr[i].setgName(gName);
  216. arr[i].setgType(gType);
  217. arr[i].setpoints(points);
  218. arr[i].setpAvr(pAvr);
  219. arr[i].setraters(raters);
  220.  
  221.  
  222. }
  223. myfile.close();
  224.  
  225.  
  226. }//EO SC1 (c6)
  227.  
  228.  
  229.  
  230.  
  231. }//EO SC1
  232.  
  233.  
  234.  
  235. }
  236. }
  237.  
  238.  
  239. #include "Gamer8r.h"
  240.  
  241. //DEFAULTCONSTRUCTOR
  242.  
  243. Game::Game(){
  244.  
  245. newpoints = 0;
  246. newpAvr = 0;
  247. newraters = 0;
  248. newpos = 0;
  249. }
  250.  
  251. //OVERLOADCONSTRUCTOR
  252.  
  253. Game::Game(string gName, string gType, int points, double pAvr, int raters, int pos){
  254. newgName = gName;
  255. newgType = gType;
  256. newpoints = points;
  257. newpAvr = pAvr;
  258. newpos = pos;
  259. }
  260.  
  261. //DESTRUCTOR
  262.  
  263. Game::~Game(){}
  264.  
  265.  
  266. //ACCESSORS
  267.  
  268. string Game::getgName(){
  269.  
  270. return newgName;
  271.  
  272. }
  273.  
  274. string Game::getgType(){
  275. return newgType;
  276. }
  277.  
  278. int Game::getpoints(){
  279. return newpoints;
  280. }
  281.  
  282. double Game::getpAvr(){
  283. return newpAvr;
  284. }
  285.  
  286. int Game::getraters(){
  287. return newraters;
  288. }
  289. int Game::getpos(){
  290. return newpos;
  291. }
  292.  
  293.  
  294. //MUTATORS
  295.  
  296. void Game::setgName(string gName){
  297. newgName = gName;
  298. }
  299.  
  300. void Game::setgType(string gType){
  301. newgType = gType;
  302. }
  303.  
  304. void Game::setpoints(int points){
  305. newpoints = points;
  306. }
  307.  
  308. void Game::setpAvr(double pAvr){
  309. newpAvr = pAvr;
  310. }
  311.  
  312. void Game::setraters(int raters){
  313. newraters = raters;
  314. }
  315.  
  316. void Game::setpos(int pos){
  317. newpos=pos;
  318. }
  319.  
  320.  
  321.  
  322. #include <iostream>
  323. #include <string>
  324. #include <fstream>
  325. using namespace std;
  326.  
  327.  
  328. #ifndef GAMER8R_H
  329. #define GAMER8R_H
  330.  
  331. class Game{
  332.  
  333. public:
  334.  
  335. Game(); //DEFAULTCONSTRUCTOR
  336. Game(string, string, int, double, int, int); //OVERLOADCONSTRUCTOR
  337. ~Game(); //DESTRUCTOR
  338.  
  339. //ACCESSORS
  340.  
  341. string getgName();
  342. string getgType();
  343. int getpoints();
  344. double getpAvr();
  345. int getraters();
  346. int getpos();
  347.  
  348. //MUTATORS
  349. void setgName(string);
  350. void setgType(string);
  351. void setpoints(int);
  352. void setpAvr(double);
  353. void setraters(int);
  354. void setpos(int);
  355. private:
  356.  
  357. string newgName;
  358. string newgType;
  359. int newpoints;
  360. double newpAvr;
  361. int newraters;
  362. int newpos;
  363. };
  364.  
  365.  
  366.  
  367. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement