Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- // DO NOT ALTER THE FUNCTION PROTOTYPE
- void writeFile(int n, std::string lines[], std::string filename) {
- }
- // DO NOT ALTER THE FUNCTION PROTOTYPE
- double average(int n, int numbers[]) {
- return average;
- }
- int main()
- {
- std::ifstream inFile("scores.dat");
- std::ofstream outFile("averages.dat");
- // Number of Scores apparently
- int count = 0;
- // Get count
- inFile >> count;
- // Read each line until we get to the end of file (file.eof())
- while(!inFile.eof()) {
- int actual_count = 0;
- std::string name;
- double scores[30];
- double averaged_scores[30];
- // get persons name
- inFile >> name;
- // v is used for getting the score in the file up to the next space character
- double v;
- for(int i = 0; inFile >> v && i < 30; ++i) {
- scores[i] = v;
- ++actual_count;
- }
- // Do your averaging here
- // Write results to file here
- outFile << name;
- for(int i = 0; i < actual_count; ++i) {
- outFile << " " << averaged_scores[i];
- }
- outFile << "\n";
- }
- inFile.close();
- outFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement