Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.05 KB | None | 0 0
  1. //Scoreboards.cpp
  2. #include "scoreboards.h"
  3.  
  4. scoreboards::scoreboards()
  5. {
  6. //ctor
  7. }
  8.  
  9. scoreboards::~scoreboards()
  10. {
  11. //dtor
  12. }
  13.  
  14. general generals;
  15. void scoreboards::displayScoreboard(){
  16. int allscores [18][numOfplayersRead()];
  17. for (int i=1;i<=numOfplayersRead();i++){ //Outer for loop
  18. string stri ; //converts i into string
  19. stringstream ss;
  20. ss<< i;
  21. stri = ss.str();
  22. ifstream myfile;
  23. myfile.open ("./storage/users/scoreboards/"+ stri +".txt");
  24. int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17,i18;
  25. myfile >>i1>>i2>>i3>>i4>>i5>>i6>>i7>>i8>>i9>>i10>>i11>>i12>>i13>>i14>>i15>>i16>>i17>>i18;
  26. myfile.close();
  27. allscores[(i-1)][0] = i1;
  28. allscores[(i-1)][1] = i2;
  29. allscores[(i-1)][2] = i3;
  30. allscores[(i-1)][3] = i4;
  31. allscores[(i-1)][4] = i5;
  32. allscores[(i-1)][5] = i6;
  33. allscores[(i-1)][6] = i7;
  34. allscores[(i-1)][7] = i8;
  35. allscores[(i-1)][8] = i9;
  36. allscores[(i-1)][9] = i10;
  37. allscores[(i-1)][10] = i11;
  38. allscores[(i-1)][11] = i12;
  39. allscores[(i-1)][12] = i13;
  40. allscores[(i-1)][13] = i14;
  41. allscores[(i-1)][14] = i15;
  42. allscores[(i-1)][15] = i16;
  43. allscores[(i-1)][16] = i17;
  44. allscores[(i-1)][17] = i18;
  45.  
  46.  
  47. for(int x=0;x<17;x++){ //print scoreboard
  48. cout<<allscores[(i-1)][x]<<" ";
  49. }
  50. }
  51. }
  52.  
  53.  
  54.  
  55. int scoreboards::numOfplayersRead(){ //This checks the file to see the current number of players on the system
  56. ifstream myfile;
  57. myfile.open ("./storage/users/numofplayers.txt");
  58. int total;
  59. myfile >> total;
  60. myfile.close();
  61. return total;
  62. }
  63.  
  64.  
  65. void scoreboards::enterScore(){
  66. string tempScore[1][18];
  67. for (int i=1;i<=18;i++){
  68. cout<<"Enter the number of strokes taken for hole: "<<i<<endl;
  69. cin>>tempScore[0][i-1];
  70. }
  71. //write to file
  72. string strcurrentPlayers ;
  73. stringstream ss;
  74. ss<< generals.getCurrentPlayer();
  75. strcurrentPlayers = ss.str();
  76. ofstream myfile;
  77. myfile.open ("./storage/users/scoreboards/" + strcurrentPlayers + ".txt");
  78. myfile << tempScore[0][0]<<" "<<tempScore[0][1]<<" "<<tempScore[0][2]<<" "<<tempScore[0][3]<<" "<<tempScore[0][4]<<" "<<tempScore[0][5]<<" "<<tempScore[0][6]<<" "<<tempScore[0][7]<<" "<<tempScore[0][8]<<" "<<tempScore[0][9]<<" "<<tempScore[0][10]<<" "<<tempScore[0][11]<<" "<<tempScore[0][12]<<" "<<tempScore[0][13]<<" "<<tempScore[0][14]<<" "<<tempScore[0][15]<<" "<<tempScore[0][16]<<" "<<tempScore[0][17];
  79. myfile.close();
  80. }
  81.  
  82.  
  83. void scoreboards::calculateFreeStroke(){
  84. //Read index from file and store into array
  85. int index[1][18];
  86. int freeStroke [1][18];
  87. for (int i=0;i<18;i++){
  88. freeStroke[0][i]= 0 ;
  89. }
  90.  
  91. ifstream myfile;
  92. myfile.open ("./storage/course/index.txt");
  93. int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17,i18;
  94. myfile >>i1>>i2>>i3>>i4>>i5>>i6>>i7>>i8>>i9>>i10>>i11>>i12>>i13>>i14>>i15>>i16>>i17>>i18;
  95. myfile.close();
  96. index[0][0] = i1;
  97. index[0][1] = i2;
  98. index[0][2] = i3;
  99. index[0][3] = i4;
  100. index[0][4] = i5;
  101. index[0][5] = i6;
  102. index[0][6] = i7;
  103. index[0][7] = i8;
  104. index[0][8] = i9;
  105. index[0][9] = i10;
  106. index[0][10] = i11;
  107. index[0][11] = i12;
  108. index[0][12] = i13;
  109. index[0][13] = i14;
  110. index[0][14] = i15;
  111. index[0][15] = i16;
  112. index[0][16] = i17;
  113. index[0][17] = i18;
  114.  
  115. //Read the current players handicap
  116. string strcurrentPlayers ; //converts current player from int to string
  117. stringstream ss;
  118. ss<< generals.getCurrentPlayer();
  119. strcurrentPlayers = ss.str();
  120.  
  121. ifstream myfiles;
  122. myfiles.open ("./storage/users/members/"+ strcurrentPlayers +".txt");
  123. string handicapstr,i;
  124. myfiles >>i >>i >>i >>handicapstr;
  125. myfiles.close();
  126. int handicap;
  127. handicap = stoi(handicapstr) ; //convert string to int
  128. cout<<"The current handicap is: "<<handicap <<endl;
  129. int h,j;
  130.  
  131.  
  132. //Calculate free strokes
  133. if(handicap>18){
  134. h= handicap/18; //free strokes 1- 18
  135. j = handicap-(h*18); // free strokes remainder
  136. cout<<"The h value is"
  137. <<h<<endl;
  138. }
  139. if (handicap<19)j=handicap;
  140. cout<<"The j value is "<<j<<endl;
  141. //h is the number of full frees and j is the number of half frees
  142. while(h>0){
  143. for (int i=0;i<18;i++){
  144. freeStroke
  145. [0][i]= (freeStroke[0][i]) +1 ;
  146. // cout<<index[1][i]<<endl; // go through each member of array and add on full free strokes
  147. }
  148. h--;
  149. }
  150. for (int i=0;i<18;i++){
  151. if(index[0][i] <= j){
  152. freeStroke[0][i]= (freeStroke[0][i]) +1;}
  153. }
  154. for(int x=0;x<18;x++){ //print scoreboard
  155. cout<<index[0][x]<<" ";
  156. }
  157. cout<<endl;
  158. for(int x=0;x<18;x++){ //print scoreboard
  159. cout<<freeStroke[0][x]<<" ";
  160. }
  161. //write freestrokes to file
  162. ofstream myfile3;
  163. myfile3.open ("./storage/users/scoreboards/freeStrokes/" + strcurrentPlayers + ".txt");
  164. myfile3 << freeStroke[0][0]<<" "<<freeStroke[0][1]<<" "<<freeStroke[0][2]<<" "<<freeStroke[0][3]<<" "<<freeStroke[0][4]<<" "<<freeStroke[0][5]<<" "<<freeStroke[0][6]<<" "<<freeStroke[0][7]<<" "<<freeStroke[0][8]<<" "<<freeStroke[0][9]<<" "<<freeStroke[0][10]<<" "<<freeStroke[0][11]<<" "<<freeStroke[0][12]<<" "<<freeStroke[0][13]<<" "<<freeStroke[0][14]<<" "<<freeStroke[0][15]<<" "<<freeStroke[0][16]<<" "<<freeStroke[0][17];
  165. myfile3.close();
  166. }
  167.  
  168.  
  169.  
  170. void scoreboards::calculateScore(){
  171. int tempScore[5][18]; //inport score free stroke handicap
  172. //Imports players score & savea to first line of array
  173. string strcurrentPlayers ;
  174. stringstream ss;
  175. ss<< generals.getCurrentPlayer();
  176. strcurrentPlayers = ss.str();
  177. ifstream myfiles;
  178. myfiles.open ("./storage/users/scoreboards/"+ strcurrentPlayers +".txt");
  179. myfiles >>tempScore[0][0] >>tempScore[0][1] >>tempScore[0][2]>>tempScore[0][3]>>tempScore[0][4] >>tempScore[0][5] >>tempScore[0][6] >>tempScore[0][7] >>tempScore[0][8] >>tempScore[0][9] >>tempScore[0][10] >>tempScore[0][11] >>tempScore[0][12] >>tempScore[0][13] >>tempScore[0][14] >>tempScore[0][15] >>tempScore[0][16] >>tempScore[0][17] ;
  180. myfiles.close();
  181. // Imports free strokes to array
  182. myfiles.open ("./storage/users/scoreboards/freeStrokes/"+ strcurrentPlayers +".txt");
  183. myfiles >>tempScore[1][0] >>tempScore[1][1] >>tempScore[1][2]>>tempScore[1][3]>>tempScore[1][4] >>tempScore[1][5] >>tempScore[1][6] >>tempScore[1][7] >>tempScore[1][8] >>tempScore[1][9] >>tempScore[1][10] >>tempScore[1][11] >>tempScore[1][12] >>tempScore[1][13] >>tempScore[1][14] >>tempScore[1][15] >>tempScore[1][16] >>tempScore[1][17] ;
  184. myfiles.close();
  185. //Import par
  186. myfiles.open ("./storage/course/par.txt");
  187. myfiles >>tempScore[2][0] >>tempScore[2][1] >>tempScore[2][2]>>tempScore[2][3]>>tempScore[2][4] >>tempScore[2][5] >>tempScore[2][6] >>tempScore[2][7] >>tempScore[2][8] >>tempScore[2][9] >>tempScore[2][10] >>tempScore[2][11] >>tempScore[2][12] >>tempScore[2][13] >>tempScore[2][14] >>tempScore[2][15] >>tempScore[2][16] >>tempScore[2][17] ;
  188. myfiles.close();
  189.  
  190. //Calculate score
  191. for(int i=0;i<18;i++){
  192. tempScore[3][i] =tempScore[0][i]-tempScore[1][i]-tempScore[2][i];
  193. //Calculate points
  194. if (tempScore[3][i]>=2 ) tempScore[4][i] =0;
  195. else tempScore[4][i] = 2- tempScore[3][i];
  196. }
  197. //Calculate points
  198.  
  199.  
  200. cout<<"strokes,freeStrokes, par,score,points"<<endl;
  201. for (int i=0;i<=4;i++){
  202. for(int x=0;x<18;x++){ //print scoreboard
  203. cout<<tempScore[i][x]<<" ";
  204. }
  205. cout<<endl;
  206. }
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement