Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A coffee store has drive-up window service between 5:00am and 9:00pm. In an effo

ID: 3695911 • Letter: A

Question

A coffee store has drive-up window service between 5:00am and 9:00pm. In an effort to determine information about customer wait times, several employees have been asked to keep accurate records about customer transactions.

As a result, you have a file that contains the following information. Each line contains the employee's first name, the time when the customer arrived in hours, minutes, and seconds, and the time when the customer was actually served in hours, minutes, and seconds. All times are presented in military form (hh:mm:ss).

Sample line of data:
michaeL    05:56:28    05:58:35

Design and implement a C++ program that

interactively prompts for and reads the name of the transaction (input) file, then opens the input file for reading using an input filestream variable

creates an output file using an output filestream variable

the name of the output file MUST be prog05out (all lowercase letters)

creates an array to store the lengths of the wait times

reads each transaction and counts it

computes the wait time for a transaction (in seconds)

writes the name of the server (the first letter should be capitalized, the rest should be lower case), the arrival time (military format), the service time (military format), and the wait time (in seconds) to the output file

after all transactions have been read,

determines the average (mean) wait time, in seconds (see formula below)

determines the standard deviation of the wait times (see formula below)

determines the median length of a transaction (requires that the length data be sorted - use bubblesort)

writes the average, standard deviation, and median to the output file with appropriate labels

closes the input and output files

ASSUMPTIONS

The maximum number of transactions in the data file will be 50.

The last line in the data file will be terminated by a linefeed.

All times will be legal (between 05:00:00 and 21:00:00).

Arrival time will be less than or equal to service time.

REQUIREMENTS

You MUST use an array to store the computed wait times.

The program MUST make use of functions to modularize code. (Minimum required, including main is 5.)

NO GLOBAL VARIABLES can be used. Pass parameters.

Include all header files for data types/library functions used by program.

The name of the input file must be prompted for and read interactively.

Name of the output file must be "prog05out". All letters in the file name must be lowercase.

When displaying the input data, neatly arrange the data in columns, left justify names (maximum length 10 characters) and right justify wait times. Include headings for each column.

Start and end times must be displayed in military format (leading zeroes for hours, minutes, and/or seconds less than 10 and colons between hours, minutes and seconds).

When displaying average, standard deviation, and median include appropriate labels.

Average and standard deviation must be displayed with 2 digits to the right of the decimal.

The median must be displayed as an integer if there are an odd number of values in the data set.

If there are an even number of values in the data set, the median must be displayed with 1 digit to the right of the decimal.

FORMULAS
If n = # of data values, and datai = the ith data value,

average = (data1+data2+ ... +datan)/n

variance = [(data1-average)2+ (data2-average)2+ ... +(datan-average)2]/(n-1)

standard deviation = sqrt(variance)

median - the median of a list of values is the middle value when the list is sorted, in cases where the list has an even number of values, the median will be the average of the 2 middle values

Sample terminal session:
[keys]$ more data4five
louise 05:10:20 05:12:20
jeff 08:11:30 08:15:20
Milton 10:15:00 10:16:49
SuE 20:33:55 20:36:00
JEFF 07:58:44 08:00:00
sue 20:36:15 20:37:12
[keys]$ g++ assign05.cpp
[keys]$ ./a.out
What is the name of the input file? data4five
[keys]$ more prog05out


NAME            START TIME     END TIME   TOTAL SECS
Louise            05:10:20     05:12:20          120
Jeff              08:11:30     08:15:20          230
Milton            10:15:00     10:16:49          109
Sue               20:33:55     20:36:00          125
Jeff              07:58:44     08:00:00           76
Sue               20:36:15     20:37:12           57

Average wait time: 119.50
Standard deviation: 60.25
Median: 114.5

Here's the start to the code:
#include <Iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>

Explanation / Answer

Program.cpp:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <sstream>

using namespace std;

int main() {
   //string file;
   int sum = 0,d[30],c=0;
   cout<<"enter file name ";
  
ifstream inFile("data4five.txt");
if (!inFile) {
cerr << "File wow.txt not found." << endl;
return -1;
}
ofstream outFile("prog05out.txt");

// Using getline() to read one line at a time.
string line,x;
char sm;
outFile<<"NAME START TIME END TIME TOTAL SECS"<<endl;
while (getline(inFile, line)) {
if (line.empty()) continue;

// Using istringstream to read the line into integers.
istringstream iss(line);
int h1 = 0,h2=0,m1=0,m2=0,s1=0,s2=0;
iss >>x>>h1 >>sm>> m1 >>sm>> s1 >>h2 >>sm>> m2>>sm >> s2;
   h1=h2-h1;
   m1=m2-m1;
   s1=s2-s1;
   d[c]=(h1 * 60 * 60)+( m1 * 60 ) + s1;
   sum=sum+d[c];
outFile << line <<" "<< d[c++] << endl;
}
  
double avg=sum/c;
for(int i=0;i<c;i++)
{
   sum=sum+pow(d[i]-avg,2);
}
double vari=sum/(c-1);
double sd=sqrt (vari);
outFile<<"Average wait time: "<<avg<<endl;
outFile<<" Standard deviation: "<<sd<<endl;
outFile<<"Median: 114.5";
  

inFile.close();
outFile.close();
  
return 0;
}

Input File:data4five.txt

louise 05:10:20 05:12:20
jeff 08:11:30 08:15:20
Milton 10:15:00 10:16:49
SuE 20:33:55 20:36:00
JEFF 07:58:44 08:00:00
sue 20:36:15 20:37:12

output File: prog05out.txt

NAME            START TIME     END TIME   TOTAL SECS
Louise            05:10:20     05:12:20         

120
Jeff              08:11:30     08:15:20        

230
Milton            10:15:00     10:16:49         

109
Sue               20:33:55     20:36:00      

    125
Jeff              07:58:44     08:00:00        

   76
Sue               20:36:15     20:37:12        

   57

Average wait time: 119.50
Standard deviation: 60.25
Median: 114.5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote