help in C++
i will include the whole question and the sample output run wanted and also i will include my solution to help me finding the mstakes i did.
You have been asked to write simple Global Positioning System (GPS) program. Your application should read and process a sequence of waypoints stored in a GPS file. Each waypoint is stored in a single line and consists of the waypoints coordinates (latitude, longitude), as well as altitude (elevation wrt to the sea level), and name.
Example:
latitude longitude altitude waypoints name
23.076 57.499 745.622 CarParking
Your program should calculate the following:
1. Total distance of the route i.e; sum of all distances between waypoints.
2. The highest altitude.
3. The altitude profile.
How to calculate the distance between two waypoints?
If the latitude and longitude of two waypoints p1 and p2, are (a1, b1) and (a2, b2) respectively, then the distance D between waypoints p1, and p2 is given by the following formula:
D = Arccos[Cos[a1] Cos[b1] Cos[a2] Cos[b2] + Cos[a1] Sin[b1] Cos[a2] Sin[b2] + Sin[a1] Sin[a2]]/360 * 2*PI * r
Where,
r is the radius of the earth (6378136 m)
PI= 3.14159
Altitude profile
To have a visual altitude profile, use the character star (*). The highest altitude should be represented with 20 stars (See the sample run).
Input file:
Each waypoint record is stored in a single line in a file named gps.dat
=======================================================
LATITUDE LONGITUDE ALTITUDE NAME
23.076058114 57.499308921 745.622 CARPARKING
23.088451345 57.502853293 1522.843 VIEWPOINT
23.094749339 57.510688277 1639.642 CLIFFS_VILLAGE
23.098353054 57.513631247 1666.559 ROCKTABLE
23.101017829 57.527312189 1722.315 GREY_RAMP
23.098258339 57.541948417 1926.593 ABAND_VILLAGE
23.098221123 57.552689323 1899.917 JARIR
23.089191634 57.551676035 1865.550 MIBINT
23.084712345 57.540917695 1607.438 CAVE_VILLAGE
23.076595981 57.536980044 1638.681 MAAQUL
23.081151880 57.525282009 1529.091 BALCONY
23.084797254 57.515532514 1065.739 DESCENT
23.083009645 57.509667529 773.981 AL_FARA
OUTPUT sample run:
GPS PROGRAM
DATA
LATITUDE LONGITUDE ALTITUDE NAME
23.076 57.499 745.622 CARPARKING
23.088 57.503 1522.843 VIEWPOINT
23.095 57.511 1639.642 CLIFFS_VILLAGE
23.098 57.514 1666.559 ROCKTABLE
23.101 57.527 1722.315 GREY_RAMP
23.098 57.542 1926.593 ABAND_VILLAGE
23.098 57.553 1899.917 JARIR
23.089 57.552 1865.550 MIBINT
23.085 57.541 1607.438 CAVE_VILLAGE
23.077 57.537 1638.681 MAAQUL
23.081 57.525 1529.091 BALCONY
23.085 57.516 1065.739 DESCENT
23.083 57.510 773.981 AL_FARA
ALTITUDE PROFILE
745.622********
1522.840****************
1639.640******************
1666.560******************
1722.320******************
1926.590********************
1899.920********************
1865.550********************
1607.440*****************
1638.680******************
1529.090****************
1065.740************
773.981*********
HIGHEST ALTITUDE
1926.593 METER.
TOTAL DISTANCE
9155.413 METER.
BYE!
PRESS ANY KEY TO CONTINUE
=====================================================
my program is:
====================================================
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;
double arccos (double);
int main()
{
double lat, longt, alt,h_alt(0), t_dist(0), D(0);
double a1(0), b1(0), a2(0), b2(0);
string name;
int n(0);
const double PI=3.14159;
const double r=6378136;
ifstream infile;
ifstream ins;
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout.precision(3);
infile.open("gps.dat");
ins.open("gps.dat");
if(!infile || !ins)
{
cout<<"files opening error"<<endl;
return 1;
}
cout<<"GPS PROGRAM"<<endl<<endl;
cout<<"DATA"<<endl;
cout<<setw(10)<<"LATITUDE"<<setw(15)<<"LONGITUDE"<<setw(10)<<"ALTITUDE"<<setw(15)<<"NAME"<<endl;
infile>>lat>>longt>>alt>>name;
while(!infile.eof())
{
a1=lat;
b1=longt;
cout<<setw(8)<<lat<<setw(17)<<longt<<setw(12)<<alt<<setw(17)<<name<<endl;
infile>>lat>>longt>>alt>>name;
a2=lat;
b2=longt;
D = arccos((cos(a1)*cos(b1)*cos(a2)*cos(b2))+(cos(a1)*sin(b1)*cos(a2)*sin(b2))) +(sin(a1)*sin(a2)/(360*2*r))+D;
t_dist = t_dist+D;
if(alt>=h_alt)
h_alt = alt;
}
cout<<"ALTITUDE PROFILE"<<endl;
infile>>lat>>longt>>alt>>name;
while (!ins.eof())
{
n=(int)alt/100;
for (int i=0;i<=n;i++)
{
cout<<"*";
}
infile>>lat>>longt>>alt>>name;
}
cout<<"HIGHEST ALTITUDE"<<endl;
cout<<h_alt<<" METER."<<endl<<endl;
cout<<"TOTAL DISTANCE"<<endl;
cout<<t_dist<<" METER."<<endl<<endl;
cout<<"BYE!"<<endl<<endl;
infile.close();
ins.close();
return 0;
}
double arccos (double x)
{
double result(0);
result=1/cos(x);
return result ;
}
=====================================================
i need just to know how to print those stars and also how to calculate the total distance. :confused:

