I need this in c++ please
Write a Map class that is composed of a Location class. Location class has three private variable string nameOfCity, double variables, latitude and longitude. It has a constructor to initialize these and also the usual getters. It has three functions: string toString() which prints :double getFlyingTime(Location l) which returns the flying time between this and location l. It uses the formula that time = distance/speed. speed = 673 miles/hour. No need to convert to minutes. : double getDistance(Location l). This method is used by getFlyingTime. The Map class has function double getFlyingTime(string l, string r); It returns -1 if the two cities are not found in its database. Map class has a vector of 4 location objects. The driver program creates the map by providing the locations to the Map. Once the Map is created, it asks the user for two cities. If the cities are found, it returns the flying distance otherwise it says cities not found. The cities have first letter capitalized and rest small.
I need help implementing the main.cpp
//Location.h
#pragma once
#include <string>
class Location
{
std::string nameOfCity;
double latitude;
double longitude;
public:
Location() = default;
Location(double lat, double longat)
{
latitude = lat;
longitude = longat;
}
std::string getNameOfCity();
double getLatitude();
double getLongitude();
std::string toString();
double getFlyingTime(Location l);
double getDistance(Location l);
};
//Location.cpp
#include "Location.h"
#include <math.h>
using namespace std;
double DegreeToRadians(double degree)
{
return (degree* 3.14 / 180); // We can use PI from math librabry as well for precise values
}
std::string Location::getNameOfCity()
{
return nameOfCity;
}
double Location::getLatitude()
{
return latitude;
}
double Location::getLongitude()
{
return longitude;
}
std::string Location::toString()
{
return "Latitude: " + to_string(latitude) + ", Longitude: " + to_string(longitude);
}
double Location::getFlyingTime(Location l)
{
return getDistance(l) / 673;
}
double Location::getDistance(Location l)
{
double lat1r = DegreeToRadians(latitude);
double lon1r = DegreeToRadians(longitude);
double lat2r = DegreeToRadians(l.getLatitude());
double lon2r = DegreeToRadians(l.getLongitude());
double u = sin((lat2r - lat1r) / 2);
double v = sin((lon2r - lon1r) / 2);
return 2.0 * 6371.0 * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v)); // 6371.0 is Earth's radius
}
//Map.h
#pragma once
#include <vector>
#include "Location.h"
class Map
{
std::vector<Location> locations;
public:
void addLocation(Location l);
double getFlyingTime(std::string l, std::string r);
};
//Map.cpp
#include "Map.h"
using ::Map;
void Map::addLocation(Location l)
{
for (auto& c : locations)
{
if (c.getNameOfCity() == l.getNameOfCity())
return;
}
locations.emplace_back(l);
}
double Map::getFlyingTime(std::string l, std::string r)
{
bool city1Found = false;
bool city2Found = false;
Location loc1;
Location loc2;
for (auto& c : locations)
{
if (c.getNameOfCity() == l)
{
loc1 = c;
city1Found = true;
}
if (c.getNameOfCity() == r)
{
city2Found = true;
loc2 = c;
}
}
if (city1Found && city2Found)
{
return loc1.getFlyingTime(loc2);
}
return -1;
}
// Location.h
#pragma once
#include <string>
class Location
{
std::string nameOfCity;
double latitude;
double longitude;
public:
Location() = default;
// add city argument in constructor as there is no way to set the nameOfCity in the class
Location(std::string city,double lat, double longat)
{
nameOfCity = city;
latitude = lat;
longitude = longat;
}
std::string getNameOfCity();
double getLatitude();
double getLongitude();
std::string toString();
double getFlyingTime(Location l);
double getDistance(Location l);
};
//end of Location.h
// Location.cpp
#include "Location.h"
#include <math.h>
using namespace std;
double DegreeToRadians(double degree)
{
return (degree* 3.14 / 180); // We can use PI from math librabry as well for precise values
}
std::string Location::getNameOfCity()
{
return nameOfCity;
}
double Location::getLatitude()
{
return latitude;
}
double Location::getLongitude()
{
return longitude;
}
std::string Location::toString()
{
return "Latitude: " + to_string(latitude) + ", Longitude: " + to_string(longitude);
}
double Location::getFlyingTime(Location l)
{
return getDistance(l) / 673;
}
double Location::getDistance(Location l)
{
double lat1r = DegreeToRadians(latitude);
double lon1r = DegreeToRadians(longitude);
double lat2r = DegreeToRadians(l.getLatitude());
double lon2r = DegreeToRadians(l.getLongitude());
double u = sin((lat2r - lat1r) / 2);
double v = sin((lon2r - lon1r) / 2);
return 2.0 * 6371.0 * asin(sqrt(u * u + cos(lat1r) * cos(lat2r) * v * v)); // 6371.0 is Earth's radius
}
//end of Location.cpp
// Map.h
#pragma once
#include <vector>
#include "Location.h"
class Map
{
std::vector<Location> locations;
public:
void addLocation(Location l);
double getFlyingTime(std::string l, std::string r);
};
//end of Map.h
//Map.cpp
#include "Map.h"
using ::Map;
void Map::addLocation(Location l)
{
for (auto& c : locations)
{
if (c.getNameOfCity() == l.getNameOfCity())
return;
}
locations.emplace_back(l);
}
double Map::getFlyingTime(std::string l, std::string r)
{
bool city1Found = false;
bool city2Found = false;
Location loc1;
Location loc2;
for (auto& c : locations)
{
if (c.getNameOfCity() == l)
{
loc1 = c;
city1Found = true;
}
if (c.getNameOfCity() == r)
{
city2Found = true;
loc2 = c;
}
}
if (city1Found && city2Found)
{
return loc1.getFlyingTime(loc2);
}
return -1;
}
//end of Map.cpp
// main.cpp : C++ program to get the flying time between 2 cities input by the user
#include "Map.h"
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
int main()
{
Map map; // create a Map object
// add 4 locations to Map
Location l1("Las vegas",36.1699,115.1398);
Location l2("Mumbai",19.0760,72.8777);
Location l3("Dallas",32.7767,96.7970);
Location l4("New york",40.7128,74.0060);
map.addLocation(l1);
map.addLocation(l2);
map.addLocation(l3);
map.addLocation(l4);
string city1, city2;
// input the 2 cities
cout<<" Enter the name of first city (first letter capitalized and rest small ) : ";
getline(cin,city1);
cout<<" Enter the name of second city (first letter capitalized and rest small ) : ";
getline(cin,city2);
// format the city names such that first letter is capitalized and rest are small
string mod_city1="";
mod_city1 += toupper(city1.at(0));
for(size_t i=1;i<city1.length()-1;i++)
mod_city1 += tolower(city1.at(i));
string mod_city2="";
mod_city2 += toupper(city2.at(0));
for(size_t i=1;i<city2.length()-1;i++)
mod_city2 += tolower(city2.at(i));
// get the flying time
double flying_time=map.getFlyingTime(mod_city1,mod_city2);
if( flying_time == -1) // check if city(s) found in database
cout<<" City(s) not found in the database"<<endl;
else
cout<<" Flying time between "<<mod_city1<<" and "<<mod_city2<<" : "<<flying_time<<" hours"<<endl;
return 0;
}
//end of program
Output:


I need this in c++ please Write a Map class that is composed of a Location...
Language: Java For this file, it should be concrete. I don't know how to write a code with the following private field & associated getter methods: final String NAME - a constant that represents the name of a location final double LATITUDE - a constant that represents the latitude (x) of that location final double LONGITUDE - a constant double represents the longitude (y) of that location Then, create a following constructor to initialize Location(String name, double lat, double long)...
The following C++ code contains an incomplete program that should be able to calculate the distance between a series of geocoded locations. Two parts of the program need to be completed: 1. The portion of the main() function that calculates the distances between each of the hard-coded 5 locations, and stores it in a two-dimensional array declared as distances. 2. A portion of the calculateDistanceBetweenLocations(l1, l2) function; omitted code spaces are designed with a // TODO: comment. The code is properly...
C++ Programming
Hi! Sorry for all the material attached. I simply need help in
writing the Facility.cpp file and the other files are included in
case they're needed for understanding. I was able to complete the
mayday.cpp file but am stuck on Facility. The following link
contains a tar file with the files provided by the professor. Thank
you so much in advanced!
http://web.cs.ucdavis.edu/~fgygi/ecs40/homework/hw4/
Closer.h:
#ifndef CLOSER_H
#define CLOSER_H
#include <string>
#include "gcdistance.h"
struct Closer {
const double latitude, longitude;...
Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed. You do NOT need to write a...
I am stuck on this question. Write the class, GeoLocation.java. You can refer to Name.java used in the lecture to complete the below exercises. Do the following: 1. Create two instance variables, lat and lng, both of which should be doubles. 2. Write the default constructor. 3. Write the non-default constructor. 4. Write 2 accessor methods, one for each instance variable. 5. Write 2 mutator methods, one for each instance variable. 6. Write a method that will return the location...
Please Implement ParkingLot.cpp below based off the completed Automobile Class and ClaimCheck class down below. Automobile.hpp #pragma once #include <iostream> #include <string> class Automobile { friend bool operator==( const Automobile& lhs, const Automobile& rhs ); friend std::ostream & operator<<( std::ostream& stream, const Automobile& vehicle ); private: std::string color_; std::string brand_; std::string model_; std::string plateNumber_; public: Automobile( const std::string & color, const std::string & brand, const std::string & model, const std::string & plateNumber ); }; bool operator!=( const Automobile& lhs, const...
Cout_op.hpp #include <ostream> #include <string> #pragma once #ifndef STUDENT_CPP #define STUDENT_CPP #includes "Student.cpp" #endif //This allows us to << a Student object template<class CharT, class TraitsT> std::basic_ostream<CharT, TraitsT>& operator <<(std::basic_ostream<CharT, TraitsT>& os, Student& sc) { return os << sc.toString(); } class Student { private: //declaring private variables struct Student () { string name; int age; char gender; double gpa; bool onScholarship}; public: //creating two constructors prototype Student(); //empty constructor Student(string,int,char,double,bool);//parameterised constructor //declaring prototype of 6 methods int getAge(); void...
This is for my c++ class and I would really appreciate the help, Thank you! Complete the definitions of the functions for the ConcessionStand class in the ConcessionStand.cpp file. The class definition and function prototypes are in the provided ConcessionStand.h header file. A testing program is in the provided main.cpp file. You don’t need to change anything in ConcessionStand.h or main.cpp, unless you want to play with different options in the main.cpp program. ___________________ Main.cpp ____________________ #include "ConcessionStand.h" #include <iostream>...
This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...
c++. I'm working on a hangman game. It has to utilize a class. It should show the number of attempts that have been made, the length of the word represented by dots, and then the alphabet. There also needs to be input validation. If the word was horse, the very first attempt at the user guessing should display " 1 ..... choose: abcdefghijklmnopqrstuvwxyz ". As the user guesses letters, the number of attempts should go up, the letter should be...