Please help me find where I need to add count++ in order to make my calculation (avgDistanceToStart) correct. C++ #include #include #include #include #include #include using namespace std; int main( ) { ifstream input; ofstream output; string filename; string line1; string line2; string COMMAND; double startx = 0.0,starty = 0.0,stopx = 0.0,stopy = 0.0; double x1, y1, backx = 0.0, backy = 0.0; double distance = 0.0; double total = 0.0; double avgDistanceToStart = 0.0; bool START = false; bool STOP = false; int count = 0; do{ cout << "Please Enter The Name Of The Data File: "; cin >> filename; cout << filename; cout << endl; input.open(filename.c_str()); if (!input.is_open()){ cout << "Error: File failed to open." << endl; } } while(input.fail()); getline(input, line1); getline(input, line2); while(!START && input >> COMMAND >> x1 >> y1) { if(COMMAND == "START") { START = true; startx = x1; starty = y1; backx = x1; backy = y1; } } while(!STOP && input >> COMMAND >> x1 >> y1) { total += sqrt((pow(backx - x1, 2)) + pow(backy - y1, 2)); backx = x1; backy = y1; if(COMMAND == "STOP") { STOP = true; stopx = x1; stopy = y1; } } distance += sqrt(pow(startx - stopx, 2) + pow(starty-stopy, 2)); //need to add current x and current y to diffrentiate the two distances avgDistanceToStart = distance/count; output.open("GPS.report"); cout << setprecision(1) << fixed; output << setprecision(1) << fixed; cout << "Final Location: (" << stopx << ", " << stopy << ")" << endl; output << "Final Location: (" << stopx << ", " << stopy << ")" << endl; cout << "Total distance traveled " << total << endl; output << "Total distance traveled " << total << endl; cout << "Distance to starting point " << distance << endl; output << "Distance to starting point " << distance << endl; cout << "Average distance to start point " << avgDistanceToStart << endl; output << "Average distance to start point " << avgDistanceToStart << endl; output.close(); input.close(); return 0; }
Please help me find where I need to add count++ in order to make my calculation (avgDistanceToStart) correct. C++
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
int main( )
{
ifstream input;
ofstream output;
string filename;
string line1;
string line2;
string COMMAND;
double startx = 0.0,starty = 0.0,stopx = 0.0,stopy = 0.0;
double x1, y1, backx = 0.0, backy = 0.0;
double distance = 0.0;
double total = 0.0;
double avgDistanceToStart = 0.0;
bool START = false;
bool STOP = false;
int count = 0;
do{
cout << "Please Enter The Name Of The Data File: ";
cin >> filename;
cout << filename;
cout << endl;
input.open(filename.c_str());
if (!input.is_open()){
cout << "Error: File failed to open." << endl;
}
}
while(input.fail());
getline(input, line1);
getline(input, line2);
while(!START && input >> COMMAND >> x1 >> y1)
{
if(COMMAND == "START")
{
START = true;
startx = x1;
starty = y1;
backx = x1;
backy = y1;
}
}
while(!STOP && input >> COMMAND >> x1 >> y1)
{
total += sqrt((pow(backx - x1, 2)) + pow(backy - y1, 2));
backx = x1;
backy = y1;
if(COMMAND == "STOP")
{
STOP = true;
stopx = x1;
stopy = y1;
}
}
distance += sqrt(pow(startx - stopx, 2) + pow(starty-stopy, 2));
//need to add current x and current y to diffrentiate the two distances
avgDistanceToStart = distance/count;
output.open("GPS.report");
cout << setprecision(1) << fixed;
output << setprecision(1) << fixed;
cout << "Final Location: (" << stopx << ", " << stopy
<< ")" << endl;
output << "Final Location: (" << stopx << ", " << stopy
<< ")" << endl;
cout << "Total distance traveled " << total << endl;
output << "Total distance traveled " << total << endl;
cout << "Distance to starting point " << distance << endl;
output << "Distance to starting point " << distance << endl;
cout << "Average distance to start point " << avgDistanceToStart << endl;
output << "Average distance to start point " << avgDistanceToStart << endl;
output.close();
input.close();
return 0;
}
![GPS
Write a C++ program that will process a stream of GPS data. Each line of data starts with a command, followed by the data for that command. There will be one command per line.
Your program should.
1. Ask the user to enter the GPS data file name.
■"Please Enter The Name Of The Data File: "
■ Echo print the file name.
If the file does not open
1.
print an error message
■ return to step 1
2. Skip the first 2 lines of the data file
3. Process each command in the data file
4. Report the following to the screen (cout):
■ Final Location
Total distance traveled (rounded to one decimal place)
■ The Final distance to start point (rounded to one decimal place)
■ Average distance from the start point
■ Commands:
■START - indicates the starting location of the trip
■ STOP - indicates the ending location of the trip
■ DATA-indicates a turning point.
Assume [edit]
1. All coordinates are in a two dimension cartesian coordinate plane.
2. All numerical output should be rounded to 1 decimal places.
Sample Input File "Data.txt" [edit]
START 0 0
DATA 24 24
DATA 4 24
DATA 4 124
DATA -25 12
DATA 0 0
STOP 195 215
Sample Output [edit]
Please Enter The Name Of The Data File: Data.txt
Final Location: (195.0, 215.0)
Total distance traveled 587.6
Distance to starting point 290.3
Average distance to start point = 83.4](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ffbb4f64a-abda-416b-9af6-fa6be3ae4141%2Fc309368e-f6f7-4810-b96b-7784fc2bd170%2Fvhrn2ms_processed.png&w=3840&q=75)

Step by step
Solved in 4 steps









