Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5.  
  6. // DO NOT ALTER THE FUNCTION PROTOTYPE
  7. void writeFile(int n, std::string lines[], std::string filename) {
  8.  
  9.  
  10.    
  11. }
  12.  
  13. // DO NOT ALTER THE FUNCTION PROTOTYPE
  14. double average(int n, int numbers[]) {
  15.  
  16. return average;
  17. }
  18.  
  19. int main()
  20. {
  21.     std::ifstream inFile("scores.dat");
  22. std::ofstream outFile("averages.dat");
  23.  
  24. // Number of Scores apparently
  25. int count = 0;
  26.  
  27. // Get count
  28. inFile >> count;
  29.  
  30. // Read each line until we get to the end of file (file.eof())
  31. while(!inFile.eof()) {
  32.     int actual_count = 0;
  33.     std::string name;
  34.     double scores[30];
  35.     double averaged_scores[30];
  36.    
  37.     // get persons name
  38.     inFile >> name;
  39.  
  40.     // v is used for getting the score in the file up to the next space character
  41.     double v;
  42.     for(int i = 0; inFile >> v && i < 30; ++i) {
  43.         scores[i] = v;
  44.         ++actual_count;
  45.     }
  46.    
  47.     // Do your averaging here
  48.    
  49.     // Write results to file here
  50.     outFile << name;
  51.     for(int i = 0; i < actual_count; ++i) {
  52.         outFile << " " << averaged_scores[i];
  53.     }
  54.     outFile << "\n";
  55. }
  56.  
  57. inFile.close();
  58. outFile.close();
  59.  
  60.  
  61.   return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement