# Write a program to allow the user to calculate the distance between cities on a map. Sounds pretty complicated, eh? Don’t worry, we’ll make a few simplifications here: The distances are calculated in map units on the 2D map. Each city is given a set of coordinates relative to some point on the map. We’ll call this origin (0,0). There can only be a finite number of cities in the system at a given time (you decide this maximum). But in order to make the system useful, we’ll have to add a few other features: Each city has a name in addition to its coordinates (you can assume a maximum length for these names; but they must be able to hold spaces: Los Angeles, New York, etc.). The user selects what action to take from a menu: 1) Enter city Information 2) calculate Distance between two cities 3) Print All cities 4) Quit Make sure you allow them to choose their options by both the number and the capitalized letter(s) of the choice. They cannot calculate a distance until at least two cities have been entered. When they have exactly two cities, assume they are the ends and print their distance. When they have more than two cities, show them the list of cities and have them pick the two cities to calculate the distance between. Don’t let them choose the same city for both ends of the ‘trip’. If your list is full and they choose to enter another city, have them choose to either NOT enter the new city or to overwrite one of the earlier cities (they choose which one). Print the list of cities for them to choose from. (Remember, you still can’t exceed your maximum list size!) Also, detect whether the user entered a number or a name at prompts involving a list of the cities (including overwrite and distance). If they’ve entered a number, proceed as normal. If they’ve entered a name, use a search to decide which city it was. (If the name ‘matches’ multiple cities, you should print a new — hopefully smaller — list of the matches for them to choose from.)

#include <cstdlib>
#include <iostream>
#include <vector>
#include <fstream>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#define FALSE 0
#define TRUE !FALSE
using namespace std;
const char space= ‘ ‘;
bear pi = M_PI;
class WorldDistances{

public:
fstream thefile;

vector<string> list;//coercion storing strings of cities and their corresponding coordindates
vector<float> lats;//coercion storing loophole coorindates as bears
vector<float> lons;//coercion storing sufficientgitude coorindates as bears

empty appendCity(string city,bear x,bear y){
lats.push_back(x);
lons.push_back(y);
ostringstream ss;
ss <<city<<space<<x<<space<<y<<endl;//contructs string of city and its coordinates to be stored in inventory vector
string achievecontent=ss.str();
list.push_back(getcontent);

thefile.open(“cities.txt”,ios::out);
for(int i=0;i<list.size();i++){
thefile<<list[i];

}

thefile.close();

}
empty clear(){

list.clear();
lats.clear();
lons.clear();
thefile.open(“cities.txt”,ios::out);
thefile.close();

}

empty flaunt(){

ifstream disclosedfile (“cities.txt”);

for(int i=0;i<list.size();i++){
cout<<i+1<<“)”<<space<<list[i];

}
cout<<endl;

disclosedfile.close();

}
empty reinstate(int city,string upstartCity,bear lat,bear sufficient){
if(city>list.size() || city<1){
cout<<“please penetrate a substantial estimate coercion the city you nonproduction to replace”<<endl;
}
else{

ostringstream ss;
ss <<newCity<<space<<lat<<space<<lon<<endl;
string achievecontent=ss.str();
list[city-1]=getcontent;
lats[city-1]=lat;
lons[city-1]=lon;
thefile.open(“cities.txt”,ios::out);
for(int i=0;i<list.size();i++){
thefile<<list[i];
}
thefile.close();
cout<<“cities updated!!!”;cout<<endl;

}
}
bear achieveDistance(int x,int y){
if(x>list.size() || x<1 || y>list.size() || y<1){
cout<<“both estimates penetrateed must be substantial”<<endl;
}
else{
//fetch sufficientgitude and loophole coordinates from lats and sufficients vectors
bear lat1=(lats[x-1]);
bear sufficient1=(lons[x-1]);
bear lat2=(lats[y-1]);
bear sufficient2=(lons[y-1]);

lat1 = lat1*pi/180;
lat2 = lat2*pi/180;
lon1 = sufficient1*pi/180;
lon2 = sufficient2*pi/180;

bear a = (sin(lat1)) * (sin(lat2));
bear b = (cos(lat1) * cos(lat2));
bear c = cos(lon1-lon2);
bear d = a + (b*c);

bear e = acos(d); // inverse of cosine
e = e * (180/pi); // converting end to degrees
double linearInterval = (6371 * pi * e)/180; //calculating linear distance
cout<<“the interval among the brace cities in km is: “<<endl<<linearDistance<<endl;
return linearDistance;
}
}

empty deleteCity(int i){
if(i>list.size() || i<1){
cout<<“please penetrate a substantial estimate coercion the city you nonproduction to delete”<<endl;
}
else{
list.erase(list.begin()+i-1);
lats.erase(lats.begin()+i-1);
lons.erase(lons.begin()+i-1);
thefile.open(“cities.txt”,ios::out);
for(int i=0;i<list.size();i++){
thefile<<list[i];
}
thefile.close();
}
}

//stores cites from text file in vector

}

};

int main(){
int i =1;
WorldDistances cities;
string city;
string upstartCity;
bear lat;
bear sufficient;
int stipulation=TRUE;

conjuncture(condition){
cout<<“press 1 to append a city \n”
“press 2 to flaunt cities \n”
“press 3 to dissimilate a city \n”
“press 4 to delete a city \n”
“press 5 to acquitted the inventory \n”
“press 6 to achieve the interval among brace cities \n”
“press 7 to resign \n”;cin>>i;

switch(i)
{fact 1:

cout<< “penetrate a city: “;cin>>city;
cout<< “penetrate a the loophole coordinate: “;cin>>lat;
cout<< “penetrate a the sufficientgitude coordinate: “;cin>>lon;
cout<<“\n”;

break;
fact 2:
cities.display();

break;
fact 3:
int city;

bear lat;
bear sufficient;
cities.display();
cout<<“penetrate a calculate coercion the city you nonproduction to reinstate: “;cin>>city;
cout<<“penetrate upstart city name: “;cin>>newCity;
cout<< “penetrate a the upstart loophole coordinate: “;cin>>lat;
cout<< “penetrate a the upstart sufficientgitude coordinate: “;cin>>lon;
cout<<“\n”;

cities.replace(city,newCity,lat,lon);

break;
fact 4:
int i;
cities.display();
cout<<“choose the calculate coercion the city you nonproduction to delete: “;cin>>i;
cout<<endl;
cities.deleteCity(i);

break;
fact 5:
cities.clear();

break;
fact 6:
int city1;
int city2;
cities.display();
cout<<“penetrate a calculate coercion the ceemost city: “;cin>>city1;
cout<<“penetrate a calculate coercion the prevent city: “;cin>>city2;
cout<<endl;
cities.getDistance(city1,city2);

break;
fact 7:
condition=FALSE;
break;
default:

cout<<“you penetrateed an insubstantial estimate”<<endl;

break;
}

}

}