1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#pragma hdrstop
#pragma argsused
#include <iostream.h>
#include <math.h>
#include <string.h>
#include <fstream>
using namespace std;
ios::out;
ios::app;
double Distance(double, double, double, double);
class Place{
public:
char name[20], name1[20];
float Latitude;
float Longitude;
};
int i1 = 0, j1 = 0, k1 = 0, i = 0, j = 0, k = 0, m = 0, n = 0, v = 0, h = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
int main()
{
ofstream name("C:\Documents and Settings\05072295\My Documents\Borland Studio Projects\out.dat");
//ifstream name1("C:\Documents and Settings\05072295\My Documents\Borland Studio Projects\in.dat");
float C,F, Lat[2], Lon[2], TDistance;
char option, place1[20], place2[20];
Lat[0] = 0, Lat[1] = 0, Lon[0] = 0, Lon[1] = 0;
cout << "------**** Welcome to the World Distance Calculator ****------"<<endl<<endl;
cout << "This program enables you to calculate the distance between any"<<endl;
cout << "two cities in the world. Use the prompts below to navigate." << endl<<endl;
do{
cout << "If you would like to add a new entry >>>>>>>>>>>>>>>>>>>>>>>>>>>>> press 1"<<endl;
cout << "If you would like to find the distance between two places >>>>>>>> press 2"<<endl;
cout << "If you would like to display all the places in database >>>>>>>>>> press 3"<<endl;
cout << "If you wish to exit this program >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> press 4"<<endl<<endl;
cout << "Please enter an option number: ";
cin >> option;
cout << "" << endl;
switch (option)
{
case '1':
Place P1[10];
cout << "" << endl;
cout << "Enter Place Name: ";
cin >> P1[i++].name;
cout << "Enter Latitude Co-ordinate (in decimal degrees): ";
cin >> P1[j++].Latitude;
cout << "Enter Longitude Co-ordinate (in decimal degrees): ";
cin >> P1[k++].Longitude;
cout << "" << endl;
name << P1[i1++].name << P1[j1++].Latitude << P1[k1++].Longitude << endl;
// copy the out file into the in file
//strcpy(char P1.name, char*P1.name1);
break;
case '2':
cout << "" << endl;
cout << "Enter the The Name of the first place: ";
cin >> place1;
while ((e != 10)&&((place1[0] != P1[a].name[0])||(place1[1] != P1[b].name[1]))){
a++,b++,e++;
}
if (e > 9)
cout << "Place Not in Data Base!" << endl;
else
Lat[0] = P1[a].Latitude, Lon[0] = P1[b].Longitude ;
cout << " " << endl;
cout << "Enter the the name of the second place: ";
cin >> place2;
while ((f != 10)&&((place2[0] != P1[c].name[0])||(place2[1] != P1[d].name[1]))){
c++,d++,f++;
}
if (f > 9)
cout << "Place Not in Data Base!" << endl;
else
Lat[1] = P1[c].Latitude, Lon[1] = P1[d].Longitude;
cout << " " << endl;
TDistance = Distance(Lat[0],Lat[1],Lon[0],Lon[1]);
if (f > 9)
cout << "Distance could not be calculated";
else if (e > 9)
cout << "Distance could not be calculated";
else
cout << "Distance Between Place 1 And Place 2 is: " << TDistance << "Km";
cout << "" << endl;
cout << "" << endl;
while(e != 0 || a != 0 || b != 0){e--,a--,b--;}
while(f != 0 || c != 0 || d != 0){f--,c--,d--;}
break;
case '3':
cout << "Name Latitude Longitude";
cout << "" << endl;
if (i>0)
while (m < i){
cout << "" << endl;
//name >> P1[n++].name >>" " >> P1[v++].Latitude >> " " >> P1[h++].Longitude;
n--;
cout << P1[n++].name << endl ;
m++;}
else cout << "No Places Stored!";
while (m > 0){
m--,n--,v--,h--;}
cout << "" << endl;
cout << "" << endl;
break;
default:
cout << "" << endl;
cout << "Invalid option" << endl;
cout << "" << endl;
break;
}
}while (option !='4');
name.close();
}
double Distance(double L1, double L2, double Lon1, double Lon2)
{
double Lat1 = L1*(M_PI/180);
double Lat2 = L2*(M_PI/180);
double Long1 = Lon1*(M_PI/180);
double Long2 = Lon2*(M_PI/180);
return acos(sin(Lat1)*sin(Lat2)+cos(Lat1)*cos(Lat2)*cos(Long2-Long1))*6371;
} |