Question

In: Computer Science

Running laps: This is C++ Programming Coding Language Everyone likes running laps in gym class right?...

Running laps: This is C++ Programming Coding Language

Everyone likes running laps in gym class right?

There are 5 objectives and 20 points each. Please indicate in code (or comments) where each objective begins and ends. It may be prudent to place each objective in it's own function.

In this lab you will be reading in a file of student results. The students each ran 3 laps in a race and their times to complete each lap are posted in the order that they completed the lap (the students will not necessarily be in the same order each lap). You will be outputting a number of results based on the student performance. And it should go without saying that you cannot hard-code any of the values into your program as the values I’ve given as an example are not the same values I will use to test it with. There is a maximum of 20 students that may participate in the race (though the example file only has 7).

Hint: times in the files are given as minutes:seconds. But many times, you need to add or do calculations with them together. So you will need to convert them to total seconds to do these calculations. Then for displaying you will need a function for converting them back.

Objective 1: Output the final times of all the students. I also want to know who placed 1st, 2nd and 3rd overall. (Though if you have them all in order that will be sufficient). You can order values simply by setting aside 3 variables and when you calculate a new score you see if it is the best, if so move the old best into 2nd place and move the 2nd place into 3rd place. If it isn’t the best, then move down to 2nd and try that one and so on.

I should also note that you may read a file as many times as you want. Though it is not necessarily the most efficient solution you may read the file over again for each student that participated.

Objective 2: I want the averages for each lap by all the students. Then output which students are above the average and which are below:

Lap 1 average: 2:05
Below: Akano, Wes, Kye, Edward (note that Edward is right on the border and could be put in either)
Above: Jess, Ally, Wilt

Objective 3: Naturally, the students slowed down from lap to lap as they were running. I want the lap times and the difference between them posted for each student:

Lap      1    2    3
Akano 1:48 2:28 2:25
            +40 -3     (note that she is one of the few that needs a negative)

Objective 4: Consistency in races is important. I want to know the total range of each students fastest and slowest lap. In the end I want to know the top 3 most consistent runners:

               Slowest     fastest     difference
Akano:      2:28           1:48        40 sec

Objective 5: Now you are going to use both the example files together. The second results file contains the same students (though my test data will be 2 files with different number and names than the files you are given). I want a comparison of the student’s overall times from each results file:

                      1         2    difference
Akano:    6:41   5:49          -52 sec

Lap 1:
Akano 1:48
Edward 1:50
Wes 1:55
Kye 1:59
Ally 2:04
Jess 2:18
Wilt 2:44

RESULTS TXT 1
Lap 2:
Edward 1:56
Kye 2:21
Jess 2:21
Akano 2:28
Ally 2:33
Wes 2:43
Wilt 3:14

Lab 3:
Kye 2:11
Akano 2:25
Wilt 3:01
Ally 3:10
Jess 3:11
Wes 3:18
Edward 3:34
Lap 1:
Akano 1:43
Wes 1:45
Kye 1:52
Edward 2:05
Jess 2:14
Ally 2:26
Wilt 2:30


RESULTS TXT 2
Lap 2:
Edward 1:50
Akano 2:00
Wes 2:03
Kye 2:15
Jess 2:16
Ally 2:23
Wilt 2:54

Lab 3:
Kye 2:01
Akano 2:06
Ally 2:54
Wes 3:03
Wilt 3:11
Jess 3:15
Edward 3:21

Solutions

Expert Solution

#include <iostream>
#include<fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
   ifstream file;
   string a;
   string players1[7];
   string players2[7];
   string players3[7];

   int total[7];
   int total2[7];
   int total3[7];

   int sum[7];
   int sum2[7];

   int diff[7];
   file.open("file1.txt");
   getline(file, a);
   getline(file, a);

   istringstream iss(a);
   string word;
   iss >> word;
   int num = 0;
   players1[num] = word;

   while (a != "Lap 2:")
   {
       //cout << players1[num] << " ";
       int count = 0;
       for (int i = size(a) - 4; i < size(a); i++)
       {
           if (count == 0)
           {
               total[num] = (a[i] - 48) * 60;
           }
           if (count == 2)
           {
               total[num] = total[num] + (a[i] - 48) * 10;
           }
           if (count == 3)
           {
               total[num] = total[num] + (a[i] - 48);
           }
           // cout << a[i] ;
           count++;
       }
       // cout<< " " << total[num] << endl;

       getline(file, a);
       istringstream iss(a);
       iss >> word;
       if (num == 6)
           break;

       num++;
       players1[num] = word;
   }


   getline(file, a);


   istringstream is(a);
   is >> word;
   num = 0;
   players2[num] = word;


   while (a != "Lap 3:")
   {
       //cout << players2[num] << " ";
       int count = 0;
       for (int i = size(a) - 4; i < size(a); i++)
       {
           if (count == 0)
           {
               total2[num] = (a[i] - 48) * 60;
           }
           if (count == 2)
           {
               total2[num] = total2[num] + (a[i] - 48) * 10;
           }
           if (count == 3)
           {
               total2[num] = total2[num] + (a[i] - 48);
           }
           // cout << a[i];
           count++;
       }
       // cout << " " << total2[num]<<endl;
       getline(file, a);

       istringstream iss(a);
       iss >> word;
       if (num == 6)
           break;

       num++;
       players2[num] = word;
   }
   getline(file, a);
   istringstream it(a);
   it >> word;
   num = 0;
   players3[num] = word;

   while (num < 7)
   {
       //cout << players3[num] << " ";
       int count = 0;
       for (int i = size(a) - 4; i < size(a); i++)
       {
           if (count == 0)
           {
               total3[num] = (a[i] - 48) * 60;
           }
           if (count == 2)
           {
               total3[num] = total3[num] + (a[i] - 48) * 10;
           }
           if (count == 3)
           {
               total3[num] = total3[num] + (a[i] - 48);
           }
           // cout << a[i];
           count++;
       }
       //cout << " " << total3[num]<< endl;
       getline(file, a);


       istringstream iss(a);
       iss >> word;
       if (num == 6)
           break;

       num++;
       players3[num] = word;
   }
   //cout << " sum 1 in s" << endl;
   for (int n = 0; n < 7; n++)
   {
       for (int i = 0; i < 7; i++)
       {
           for (int j = 0; j < 7; j++)
           {
               if ((players1[n] == players2[i]) && (players1[0] == players3[j]))
               {
                   sum[n] = total[n] + total2[i] + total3[j];
                   //cout << players1[n] << " " << sum[n] << endl;
               }
           }
       }
   }
   file.close();
   cout << endl;

   ifstream fil;
   string b;
   string players21[7];
   string players22[7];
   string players23[7];

   int total21[7];
   int total22[7];
   int total23[7];


   fil.open("file2.txt");
   //cout << "Lap 1" << endl;
   getline(fil, a);
   getline(fil, a);
   istringstream iss2(a);
   iss2 >> word;
   num = 0;
   players21[num] = word;
   while (a != "Lap 2:")
   {
       //cout << players21[num] << " " << endl;
       int count = 0;
       for (int i = size(a) - 4; i < size(a); i++)
       {
           if (count == 0)
           {
               total21[num] = (a[i] - 48) * 60;
           }
           if (count == 2)
           {
               total21[num] = total21[num] + (a[i] - 48) * 10;
           }
           if (count == 3)
           {
               total21[num] = total21[num] + (a[i] - 48);
           }
           // cout << a[i] ;
           count++;
       }
       // cout<< " " << total[num] << endl;

       getline(fil, a);
       istringstream iss(a);
       iss >> word;
       if (num == 6)
           break;
       num++;
       players21[num] = word;
   }


   getline(fil, a);


   istringstream it2(a);
   it2 >> word;
   num = 0;
   players22[num] = word;


   while (a != "Lap 3:")
   {
       //cout << players22[num] << " " << endl;
       int count = 0;
       for (int i = size(a) - 4; i < size(a); i++)
       {
           if (count == 0)
           {
               total22[num] = (a[i] - 48) * 60;
           }
           if (count == 2)
           {
               total22[num] = total22[num] + (a[i] - 48) * 10;
           }
           if (count == 3)
           {
               total22[num] = total22[num] + (a[i] - 48);
           }
           // cout << a[i];
           count++;
       }
       // cout << " " << total2[num]<<endl;
       getline(fil, a);

       istringstream iss(a);
       iss >> word;
       if (num == 6)
           break;

       num++;
       players22[num] = word;
   }

   getline(fil, a);
   istringstream it22(a);
   it22 >> word;
   num = 0;
   players23[num] = word;

   while (num < 7)
   {
       //cout << players3[num] << " ";
       int count = 0;
       for (int i = size(a) - 4; i < size(a); i++)
       {
           if (count == 0)
           {
               total23[num] = (a[i] - 48) * 60;
           }
           if (count == 2)
           {
               total23[num] = total23[num] + (a[i] - 48) * 10;
           }
           if (count == 3)
           {
               total23[num] = total23[num] + (a[i] - 48);
           }
           // cout << a[i];
           count++;
       }
       //cout << " " << total3[num]<< endl;
       getline(fil, a);


       istringstream iss(a);
       iss >> word;
       if (num == 6)
           break;

       num++;
       players23[num] = word;
   }

   //cout << " sum 2 in seconds " << endl;
   for (int n = 0; n < 7; n++)
   {
       for (int i = 0; i < 7; i++)
       {
           for (int j = 0; j < 7; j++)
           {
               if ((players21[n] == players22[i]) && (players21[0] == players23[j]))
               {
                   sum2[n] = total21[n] + total22[i] + total23[j];
                   //cout << players21[n] << " " << sum2[n] << endl;
               }
           }
       }
   }
   num = 0;
   cout << "name file1 file2 diff" << endl;
   for (int i = 0; i < 7; i++)
   {
       for (int j = 0; j < 7; j++)
       {
           if (players1[i] == players21[j])
           {
               int a, b, c, d;
               diff[num] = sum[i] - sum2[j];
               a = sum[i] / 60;
               c = sum[i] - a * 60;
               b = sum2[j] / 60;
               d = sum2[j] - b * 60;
               cout <<players1[i] << " " << std::right << a<<":"<<c << " " << b<<":"<<d<< " " << diff[num] << endl;
               num++;
           }
       }
   }

   system("pause");
}

Comment Down For Any Queries
Please Give A Thumbs Up If You Are Satisfied With The Answer


Related Solutions

Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
Class object in C++ programming language description about lesson inheritance example.
please answer with coding from The second edition C programming language textbook /* Changes all occurrences...
please answer with coding from The second edition C programming language textbook /* Changes all occurrences of t in s to u, result stored in v * * Example: * * char v[100]; * replace("hello", "el", "abc", v) => v becomes "habclo" * replace("", "el", "abc", v) => v becomes "" (no change) * replace("hello", "abc", "def", v) => v becomes "hello" (no change) * replace("utilities", "ti", "def", v) => v becomes "udeflidefes" * */ void replace(char *s, char *t,...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private»...
Programming Language: C# Person Class Fields - password : string Properties + «C# property, setter private» IsAuthenticated : bool + «C# property, setter absent» SIN : string + «C# property, setter absent» Name : string Methods + «Constructor» Person(name : string, sin : string) + Login(password : string) : void + Logout() : void + ToString() : string Transaction Class Properties + «C# property, setter absent » AccountNumber : string + «C# property, setter absent» Amount : double + «C#...
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson copy constructor example.
Class object in C++ programming language description about lesson static variable example.
Class object in C++ programming language description about lesson static variable example.
In the C# programming language... Write a program to perform student record manage for class IST311....
In the C# programming language... Write a program to perform student record manage for class IST311. Create student record class (Student.cs) and it should get the student information from the user and set up student record class. The program will perform recording student’s grade information and compute final grade, and then print out the student’s class information. Student class definitions: It should contain attributes as following: first name, last name, 5 labs grade, 3 grade, final grade. Its member functions...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT