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; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education