Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Scoreboards.cpp
- #include "scoreboards.h"
- scoreboards::scoreboards()
- {
- //ctor
- }
- scoreboards::~scoreboards()
- {
- //dtor
- }
- general generals;
- void scoreboards::displayScoreboard(){
- int allscores [18][numOfplayersRead()];
- for (int i=1;i<=numOfplayersRead();i++){ //Outer for loop
- string stri ; //converts i into string
- stringstream ss;
- ss<< i;
- stri = ss.str();
- ifstream myfile;
- myfile.open ("./storage/users/scoreboards/"+ stri +".txt");
- int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17,i18;
- myfile >>i1>>i2>>i3>>i4>>i5>>i6>>i7>>i8>>i9>>i10>>i11>>i12>>i13>>i14>>i15>>i16>>i17>>i18;
- myfile.close();
- allscores[(i-1)][0] = i1;
- allscores[(i-1)][1] = i2;
- allscores[(i-1)][2] = i3;
- allscores[(i-1)][3] = i4;
- allscores[(i-1)][4] = i5;
- allscores[(i-1)][5] = i6;
- allscores[(i-1)][6] = i7;
- allscores[(i-1)][7] = i8;
- allscores[(i-1)][8] = i9;
- allscores[(i-1)][9] = i10;
- allscores[(i-1)][10] = i11;
- allscores[(i-1)][11] = i12;
- allscores[(i-1)][12] = i13;
- allscores[(i-1)][13] = i14;
- allscores[(i-1)][14] = i15;
- allscores[(i-1)][15] = i16;
- allscores[(i-1)][16] = i17;
- allscores[(i-1)][17] = i18;
- for(int x=0;x<17;x++){ //print scoreboard
- cout<<allscores[(i-1)][x]<<" ";
- }
- }
- }
- int scoreboards::numOfplayersRead(){ //This checks the file to see the current number of players on the system
- ifstream myfile;
- myfile.open ("./storage/users/numofplayers.txt");
- int total;
- myfile >> total;
- myfile.close();
- return total;
- }
- void scoreboards::enterScore(){
- string tempScore[1][18];
- for (int i=1;i<=18;i++){
- cout<<"Enter the number of strokes taken for hole: "<<i<<endl;
- cin>>tempScore[0][i-1];
- }
- //write to file
- string strcurrentPlayers ;
- stringstream ss;
- ss<< generals.getCurrentPlayer();
- strcurrentPlayers = ss.str();
- ofstream myfile;
- myfile.open ("./storage/users/scoreboards/" + strcurrentPlayers + ".txt");
- 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];
- myfile.close();
- }
- void scoreboards::calculateFreeStroke(){
- //Read index from file and store into array
- int index[1][18];
- int freeStroke [1][18];
- for (int i=0;i<18;i++){
- freeStroke[0][i]= 0 ;
- }
- ifstream myfile;
- myfile.open ("./storage/course/index.txt");
- int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17,i18;
- myfile >>i1>>i2>>i3>>i4>>i5>>i6>>i7>>i8>>i9>>i10>>i11>>i12>>i13>>i14>>i15>>i16>>i17>>i18;
- myfile.close();
- index[0][0] = i1;
- index[0][1] = i2;
- index[0][2] = i3;
- index[0][3] = i4;
- index[0][4] = i5;
- index[0][5] = i6;
- index[0][6] = i7;
- index[0][7] = i8;
- index[0][8] = i9;
- index[0][9] = i10;
- index[0][10] = i11;
- index[0][11] = i12;
- index[0][12] = i13;
- index[0][13] = i14;
- index[0][14] = i15;
- index[0][15] = i16;
- index[0][16] = i17;
- index[0][17] = i18;
- //Read the current players handicap
- string strcurrentPlayers ; //converts current player from int to string
- stringstream ss;
- ss<< generals.getCurrentPlayer();
- strcurrentPlayers = ss.str();
- ifstream myfiles;
- myfiles.open ("./storage/users/members/"+ strcurrentPlayers +".txt");
- string handicapstr,i;
- myfiles >>i >>i >>i >>handicapstr;
- myfiles.close();
- int handicap;
- handicap = stoi(handicapstr) ; //convert string to int
- cout<<"The current handicap is: "<<handicap <<endl;
- int h,j;
- //Calculate free strokes
- if(handicap>18){
- h= handicap/18; //free strokes 1- 18
- j = handicap-(h*18); // free strokes remainder
- cout<<"The h value is"
- <<h<<endl;
- }
- if (handicap<19)j=handicap;
- cout<<"The j value is "<<j<<endl;
- //h is the number of full frees and j is the number of half frees
- while(h>0){
- for (int i=0;i<18;i++){
- freeStroke
- [0][i]= (freeStroke[0][i]) +1 ;
- // cout<<index[1][i]<<endl; // go through each member of array and add on full free strokes
- }
- h--;
- }
- for (int i=0;i<18;i++){
- if(index[0][i] <= j){
- freeStroke[0][i]= (freeStroke[0][i]) +1;}
- }
- for(int x=0;x<18;x++){ //print scoreboard
- cout<<index[0][x]<<" ";
- }
- cout<<endl;
- for(int x=0;x<18;x++){ //print scoreboard
- cout<<freeStroke[0][x]<<" ";
- }
- //write freestrokes to file
- ofstream myfile3;
- myfile3.open ("./storage/users/scoreboards/freeStrokes/" + strcurrentPlayers + ".txt");
- 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];
- myfile3.close();
- }
- void scoreboards::calculateScore(){
- int tempScore[5][18]; //inport score free stroke handicap
- //Imports players score & savea to first line of array
- string strcurrentPlayers ;
- stringstream ss;
- ss<< generals.getCurrentPlayer();
- strcurrentPlayers = ss.str();
- ifstream myfiles;
- myfiles.open ("./storage/users/scoreboards/"+ strcurrentPlayers +".txt");
- 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] ;
- myfiles.close();
- // Imports free strokes to array
- myfiles.open ("./storage/users/scoreboards/freeStrokes/"+ strcurrentPlayers +".txt");
- 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] ;
- myfiles.close();
- //Import par
- myfiles.open ("./storage/course/par.txt");
- 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] ;
- myfiles.close();
- //Calculate score
- for(int i=0;i<18;i++){
- tempScore[3][i] =tempScore[0][i]-tempScore[1][i]-tempScore[2][i];
- //Calculate points
- if (tempScore[3][i]>=2 ) tempScore[4][i] =0;
- else tempScore[4][i] = 2- tempScore[3][i];
- }
- //Calculate points
- cout<<"strokes,freeStrokes, par,score,points"<<endl;
- for (int i=0;i<=4;i++){
- for(int x=0;x<18;x++){ //print scoreboard
- cout<<tempScore[i][x]<<" ";
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement