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

**TEE - TIME** Write using C++ , please check answer before summiting Four data

ID: 3857487 • Letter: #

Question

**TEE - TIME**

Write using C++ , please check answer before summiting

Four data files (CAR1.DAT, CAR2.DAT, CAR3.DAT, and CAR4.DAT) are available on the instructor's web page. Each file contains track results for a test vehicle. The results are in the following format The test vehicle number (line 1) The test date (line 2) » The test driver (line 3) Time, t, in seconds and distance, x, in feet (one pair of (t,x) values per line for all other lines) As an example, the contents of CAR1.DAT are shown below: Test vehicle: Car #1 Test date: October 26, 2007 Driver: D. Myers 0.0 0.0 0.2 5.5 0.4 15.9 0.6 30.9 0.8 49.7 1.0 71.8 1.2 97.1 14 125.4 1.6 156.6 1.8190.4 2.0 226.6 2.2 265.3 2.4 306.1 2.6 348.9 2.8 393.5 3.0 439.9 3.2 488.0 3.4 537.7 3.6 588.8 3.8 641.2 4.0 694.6 4.2749.2 4.4 804.7 4.6 861.2 4.8 918.4 5.0 976.2

Explanation / Answer

# include<iostream>

# include<conio.h>

# include<stdio.h>

#include <fstream>

#include <stdlib.h>

using namespace std;

void VelocityInfs(double distance[], double time[], double velocity[], int size)// Compute velocity in f/s

{

velocity[0] = 0.0;

for (int i = 1; i < size; i++)

{

velocity[i] = (distance[i] - distance[i - 1]) / (time[i] - time[i - 1]);

}

}

void VelocityInmph(double distance[], double time[], double velocity[], int size)// Compute velocity in mph

{

velocity[0] = 0.0;

for (int i = 1; i < size; i++)

{

velocity[i] = (distance[i] - distance[i - 1]) / (time[i] - time[i - 1]);

velocity[i] *= 0.682;

}

}

void acceleration(double time[], double velocity[], double acceleration[], int size)// Compute acceleration

{

acceleration[0] = 0.0;

for (int i = 1; i < size; i++)

{

acceleration[i] = (velocity[i] - velocity[i - 1]) / (time[i] - time[i - 1]);

}

}

double ArrayMean(double array[], int size)// Compute Mean of values

{

double sum=0.0;

for (int i = 0; i < size; i++)

{

sum += array[i];

}

return sum / size;

}

double ArrayMax(double array[], int size)// Find Max of all the values

{

double max=0.0;

for (int i = 0; i < size; i++)

{

if (array[i] > max)

max = array[i];

}

return max;

}

int main()

{

string fileName;

cout << "Enter file name: ";

cin >> fileName; // Give file name

std::ifstream f(fileName.c_str());// File stream

int lineCount;

string vehicleNumber;

string date;

string driverName;

double distance[30];

double time[30];

time[0] = 0.0;

distance[0] = 0.0;

string line;

int ind = 0;

cout << "filename " << fileName << " " << f.good() << """ ";// Print file name given by the user

while(getline(f, line))// read line by line

{

// cout << line << " ";

lineCount++;

if (lineCount == 1)// Read Vehicle number

{

vehicleNumber = line.substr(line.find(" "), line.length());

}

else if (lineCount == 2)// Read date;

{

date = line.substr(line.find(" "), line.length());//Store date name

}

else if (lineCount == 3)

{

driverName = line.substr(line.find(" "), line.length());// Store driver name

}

else

{

int pos = line.find(" ");// Split line by space

string t = line.substr(0, pos);// time

string d = line.substr(pos, line.length());// distance

time[ind]= atof(t.c_str());// Store time in array

distance[ind++] = atof(d.c_str()); // Strore distance in array

}

}

double velocityInfs[30];// Array for valocity in f/s

double velocityInmph[30]; // Array for velocity in mph

double accel[30];// Array for acceleration

VelocityInfs(distance, time, velocityInfs, ind);// Fill velocityInfs array

VelocityInmph(distance, time, velocityInmph, ind);//Fill velocityInmph array

acceleration(time, velocityInfs, accel, ind);//Fill acceleration array

// Output file

ofstream outFile;

outFile.open ("output.txt");// open file

outFile << "Test vehicle: " << vehicleNumber << " ";// Write vehicle number to file

outFile << "Test date: " << date << " "; //Write date to file

outFile << "Driver: " << driverName << " ";//Write driver name to file

outFile << "Average velocity = " << ArrayMean(velocityInmph, ind) << " mph ";

outFile << "Average acceleration = " << ArrayMean(accel, ind) << " ft/s/s ";

outFile << "Maximum velocity = " << ArrayMax(velocityInmph, ind) << " mph ";

outFile << "Maximum acceleration = " << ArrayMax(accel, ind) << " ft/s/s ";

//Write 5 fields to output file mentioned in problem

for(int i = 0; i < ind; i++)

{

outFile << time[i] << "," << distance[i] << "," << velocityInfs[i] << "," <<

velocityInmph[i] << "," << accel[i] << " ";

}

outFile.close();

return 0;

}