FastestRunner.cpp
A group of students decided to run in the Columbus Marathon. Their names and times (in minutes) are below:
Name Time (minutes)
Elena |
341 |
Thomas |
273 |
Hamilton |
278 |
Suzie |
329 |
Phil |
445 |
Matt |
402 |
Alex |
388 |
Emma |
275 |
John |
243 |
James |
334 |
Jane |
412 |
Emily |
393 |
Daniel |
299 |
Neda |
343 |
Aaron |
317 |
Kate |
265 |
Find the fastest runner.
In particular, write a program as follows. Print the list of runners and times as above. Then print the name of the fastest runner and his/her time (in hours and minutes). Also, find the second fastest runner. Print the name and his/her time (in hours and minutes).
The program should have a method that takes as input an array of integers and returns the index corresponding to the person with the lowest time. The program should apply this method to the array of running times to find the fastest runner. Also include a second method to find the second-best runner. The second method should use the first method to determine the best runner, and then returns the index corresponding to the person with the second lowest time.
Print the list of runners and times nicely formatted in columns as displayed above.
Here is some program code to get started:
#include <iostream>
#include <string>
using namespace std;
int main (){
const int numRunners = 16;
string names[] ={"Elena", "Thomas", "Hamilton", "Suzie", "Phil",
"Matt", "Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel",
"Neda","Aaron", "Kate"};
int times[] ={341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412,
393, 299,343, 317, 265};
. . .
for (int i = 0; i < numRunners; i++) {
cout << names[i] << ": " << times[i];
}}
#include <iostream>
#include <string>
#include<conio.h>
using namespace std;
// function declaration
int checkFirstRunner(int N_Runners, int times[],string names[]);
int secondRunner(int times[]);
int main ()
{
// local variable declaration:
const int N_Runners = 16;
int aray[N_Runners];
for(int i=0;i<N_Runners;i++)
aray[i]=i;
string names[] ={"Elena", "Thomas", "Hamilton", "Suzie", "Phil","Matt", "Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel","Neda","Aaron", "Kate"};
int times[] ={341, 873, 278, 329, 445, 402, 388, 275, 243, 334, 412,393, 299,343, 317, 220};
for (int i = 0; i < N_Runners; i++)
{
cout <<" "<< names[i] << ": " << times[i]<<"\n";
}
// calling a function to get max value.
int ret = checkFirstRunner(N_Runners,times,names);
cout << "Fastest runner index value : " << ret << endl;
system("pause");
return 0;
}
// function returning the max between two numbers
int checkFirstRunner(int N_Runners, int times[],string names[])
{
int index=0,min=0,fastrunner=0,minIndex=0;
min=times[0];
for(int i=1;i<N_Runners;i++)
{
if(times[i]<min)
{
min=times[i];
index=i;
}
}
cout<<"fastest runner is :"<<names[index]<<"\n";
int secondWinner = secondRunner(times);
for(int i=0;i<N_Runners;i++)
{
if(times[i]==secondWinner)
{
cout<<"second winner is:"<<names[i]<<"\n";
}
}
return index; }
int secondRunner(int times[])
{
int size=16;
int i, first=0, second=0,min=0,index=0;
min=times[0];
for(int i=0;i<16;i++)
{
if(times[i]<min)
{
second=min;
min=times[i];
index=i;
}
}
return second;
}
FastestRunner.cpp A group of students decided to run in the Columbus Marathon. Their names and times...
Write a c++ program as follows. Print the list of runners and times as example below. Then print the name of the fastest runner and his/her time (in hours and minutes). Also, find the second fastest runner. Print the name and his/her time (in hours and minutes). The program should have a method that takes as input an array of integers and returns the index corresponding to the person with the lowest time. The program should apply this method to...
C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....