Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. #include <iostream> //to use cout and cin and endl// allows using cout without std::cout
  2. #include <string> // to use string data type
  3. #include <fstream>
  4. #include <iomanip>
  5. //Daniel Clutts
  6.  
  7. using namespace std;
  8.  
  9. void swap(int *xp, int *yp)
  10. {
  11. int temp = *xp;
  12. *xp = *yp;
  13. *yp = temp;
  14. }
  15. void printArray(int average[], int n)
  16. {
  17. for (int i=0; i < n-1; i++){
  18. cout << average[i] << ", ";
  19. }
  20. cout << average[n-1] <<endl;
  21. }
  22.  
  23. void highToLow(int average[], int n, int median){
  24. for (int i = 0; i < n; i++){
  25. for (int j = 0; j < n-i-1; j++){
  26. if (average[j] < average[j+1]){
  27. swap(&average[j], &average[j+1]);
  28. }
  29. }
  30. }
  31. printArray(average, n);
  32. //median=[5];
  33. cout <<" The median is " << median << endl;
  34. }
  35. int main()
  36. {
  37. ifstream myfile;
  38. ofstream myfile2; //test output
  39. myfile.open("C:/Users/wgund/Desktop/Bowlers2.txt");
  40. myfile2.open("c:/users/wgund/desktop/testttt.txt");
  41. string names[10]; //string
  42. float scores[10][3];
  43. float highest =0;
  44. float lowest =9999;
  45. int highestplayer =0;
  46. int lowestplayer =0;
  47. int player =0;
  48. int score=0;
  49. float average[10]={0,0,0,0,0,0,0,0,0,0};
  50.  
  51. string line;
  52.  
  53. cout << "Player name" << "\t\tscore 1 " << "\t\tscore 2 " << "\t\tscore 3" << "\t\t\taverage" << endl;
  54.  
  55. for(int i=0; i<40; i++){ //
  56. int v=i%4;
  57. getline(myfile,line);
  58. if(v==0){
  59. names[player]=line;
  60. player++;
  61. }
  62. else{
  63. scores[player-1][v-1] = std::stoi(line);
  64. }
  65. }
  66.  
  67. for (int i=0; i<10; i++){
  68.  
  69.  
  70. cout << names[i];
  71. myfile2 << names[i] << " ";
  72. for(int j=0; j<3; j++){
  73. myfile2 << scores[i][j] << " ";
  74. cout << '\t' << '\t' << '\t' << scores[i][j];
  75. average[i]=(average[i]+scores[i][j]); // Averages each players 3 scores
  76. }
  77. average[i]=average[i]/3.0; // averages each player 3 scores
  78. if(average[i] > highest){ // next two if statements determine highest and lowest
  79. highest=average[i];
  80. highestplayer=i;
  81. }
  82. if (average[i] < lowest){
  83. lowest=average[i];
  84. lowestplayer=i;
  85. }
  86. cout << '\t' << '\t' << '\t' << average[i] << endl;
  87.  
  88. }
  89.  
  90. float averages[] = {0,0,0};
  91. //Averages
  92. for(int i = 0; i < 10; i++){
  93. for(int j = 0; j < 3; j++){
  94. averages[j] = (averages[j] + scores[i][j])/2;
  95. }
  96. }
  97. //cout << "Game averages" << setw(18) << averages[0] << " " <<averages[1] << " " << averages[2] << endl;
  98. //cout << setw(8) << "Player " << names[lowestplayer] << " \t\thad the lowest score." << endl;
  99. //cout << "Their scores were " << scores[lowestplayer][0] << '\t' << scores[lowestplayer][1] << '\t' << scores[lowestplayer][2] << endl;
  100. //cout << "Their average was " << average[lowestplayer] << endl;
  101. //cout << setw(8) << "Player " << names[highestplayer] << " \t\thad the highest score." << endl;
  102. //cout << "Their scores were " << scores[highestplayer][0] << " " << scores[highestplayer][1] << " " << scores[highestplayer][2] << endl;
  103. //cout << "Their average was " << average[highestplayer] << endl;
  104.  
  105. cout << highToLow;
  106. myfile.close();
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement