Question

In: Computer Science

Latitude and Longitude are the two components used to exactly identify a specific spot on the...

Latitude and Longitude are the two components used to exactly identify a specific spot on the Earth. Latitude provides the North/South direction and runs from 90 degrees north at the north poll to -90 degrees south at the south poll. The equator has a Latitude of zero.

Longitude provides the East/West direction and runs from the Prime Meridian that runs through Greenwich, England and has a Longitude of zero. Longitudes then run negatively to the west and positively to the east with the maximum Longitude being 180 degrees (or -180 degrees. They are the same Longitude.)

Usually Latitude and Longitude are usually depicted in degrees, minutes and second, but they can also be represented with just real numbers, which is how your class will need to be written. (FYI Lake Worth has a 26.61353 latitude and -80.057458)

Your assignment is to create a class called locCoordinates with the following properties and methods:

class locCoordinates

{

private:

            double latitude;

            double longitude;

            string location;

public:

            locCoordinates();

            bool set(double, double, string)

            bool setLatitude(double);

            bool setLongitude(double);

            void setLocation(string);

            double getLatitude();

            double getLongitude();

            string getLocation();

            void moveUpDown (double, string);

            void moveLeftRight (double, string);

            void move (double, double, string);

            void print();

}

And here are the specifics for this class.

The constructor should set the latitude and longitude to zero, and the location to "Prime Meridian at Equator). It should not accept any parameters (and should not call the set function).

The set function will take the two numbers entered (latitude then longitude) and ensure they are correct. If either of the numbers are not within the correct range, then the location should be set to "Error", the value of the invalid entry should be set to zero and the function return a false. If everything is good it returns a true.

setLatitude will change the current value of Latitude. It also needs to check to make sure that it is a good latitude. If not correct the function should set the Latitude to zero and return false otherwise return true. In either case, the Location should be changed to "Unknown".

setLongitude does what setLatitude does, only to the Longitude.

setLocation just updates the location string in the class.

The gets return the values in the properties.

moveUpDown will pass in a double that may be either negative or positive. This value needs to be adjusted for the number of total degrees in the latitude, and then the latitude adjusted by that amount. The location would then also be updated.

moveEastWest does just like moveUpDown, but does it for Longitude.

move takes both a change in Latitude and Longitude and applies them along with setting the new location. (If I were coding this, I would probably just call moveUpDown and moveEastWest to do the work!!)

print will print out:

            Latitude: 99.99999, Longitude: 999.99999 is at location: XXXXXX

You can implement this any way you want either by creating separate class header and implementation files, or by just putting everything in one big ole file with a main routine after the class definition. In the main routine, please set up a location with a bad input and show that a false is returned, then set one up with good input. Then use the move command to adjust the coordinates by an amount above 90 (or below -90) for latitude and above 180 (or below -180) for longitude. Then use the print function to print out the results.

I need help it C++

Solutions

Expert Solution

Code:

#include <iostream>

using namespace std;


class locCoordinates // Given class
{
private:
double latitude;
double longitude;
string location;

public:
locCoordinates();
bool set(double, double, string);
bool setLatitude(double);
bool setLongitude(double);
void setLocation(string);
double getLatitude();
double getLongitude();
string getLocation();
void moveUpDown (double, string);
void moveLeftRight (double, string);
void move (double, double, string);
void print();
};

locCoordinates::locCoordinates() // setting the default constructor
{
latitude =0;
longitude =0;
location = "Prime Meridian at Equator";
}

bool locCoordinates::set(double lat, double longi, string loc) // function to set the latitude, longitude and location
{
location = loc;
if(lat >=-90 && lat <=90) // checking if the latitude lies in the range
{
latitude =lat;
}
else
{
location = "Error";
latitude = 0;
if(longi >=-180 && longi <=180) // checking if the longitude lies in the range
{
longitude =longi;
}
else
{
longitude =0;
}

return false;
}
if(longi >=-180 && longi <=180) // checking if the longitude lies in the range
{
longitude =longi;
}
else
{
location = "Error";
longitude = 0;
if(lat >=-90 && lat <=90) // checking if the latitude lies in the range
{
latitude =lat;
}
else
{
latitude =0;
}

return false;
}

return true;
}

bool locCoordinates::setLatitude(double lat) // function to set the latitude
{
if(lat >=-90 && lat <=90) // checking if the latitude lies in the range
{
latitude =lat;
location = "Unknown";
return true;
}
else
{
latitude =0;
location = "Unknown";
return false;
}

}

bool locCoordinates::setLongitude(double longi) // function to set the longitude
{
if(longi >=-180 && longi <=180) // checking if the longitude lies in the range
{
longitude =longi;
location = "Unknown";
return true;
}
else
{
longitude =0;
location = "Unknown";
return false;
}
}

void locCoordinates::setLocation(string loc) // function to set the location
{
location = loc;
}

double locCoordinates::getLatitude() // function to return latitude
{
return latitude;
}
double locCoordinates::getLongitude() // function to return longitude
{
return longitude;
}
string locCoordinates::getLocation() // function to return location
{
return location;
}
void locCoordinates::moveUpDown (double lat, string loc) // function to move latitude
{
latitude += lat;
location = loc;
}
void locCoordinates::moveLeftRight (double longi, string loc) // function to move longitude
{
longitude += longi;
location = loc;
}
void locCoordinates::move (double lat, double longi, string loc) // function to move latitude and longitude
{
moveUpDown(lat,loc);
moveLeftRight(longi,loc);
}
void locCoordinates::print() // function to print the details of the location
{
cout<<"Latitude : "<<latitude<<", Longitude: "<<longitude<<" is at location: "<<location<<endl;
}

int main()
{
locCoordinates location1;

cout<<"Details for location 1 : "<<endl;
location1.print();
cout<<"Value returned when the latitude is set to 91 : "<<location1.setLatitude(91)<<endl;
location1.print();

locCoordinates location2;

cout<<"Details for location 2 : "<<endl;
location2.print();
location2.setLatitude(26.61353);
location2.setLongitude(-80.057458);
location2.setLocation("Lake Worth");
location2.print();
location2.move(63.38647,80.057458,"North Pole");
location2.print();

return 0;
}

Output:


Related Solutions

6- Find the latitude and longitude of the location on Earth precisely opposite the geographic center...
6- Find the latitude and longitude of the location on Earth precisely opposite the geographic center of the contiguous United States (Lebanon, Kansas at 39° 50′ N, 98° 35′ W).
You are at 76° west longitude, 37° north latitude, and observe the sun to rise at...
You are at 76° west longitude, 37° north latitude, and observe the sun to rise at 05:10:20 hours local clock time. Your friend is at 87° west longitude and 49° north latitude. What will be your clock time when she sees the sun rise?
Two points A and B on the surface of the Earth are at the same longitude and θ = 55.0° apart in latitude as shown in the figure below.
Two points A and B on the surface of the Earth are at the same longitude and θ = 55.0° apart in latitude as shown in the figure below. Suppose an earthquake at point A creates a P wave that reaches point B by traveling straight through the body of the Earth at a constant speed of 7.20 km/s. The earthquake also radiates a Rayleigh wave that travels at 3.05 km/s. In addition to P and S waves, Rayleigh waves...
1. An organization-specific list of tasks and their descriptions used as a basis to identify components...
1. An organization-specific list of tasks and their descriptions used as a basis to identify components of a job is known as Select one: a. task inventory analysis. b. competency-based analysis.( Incorrect) c. functional job analysis. d. the critical incident method 2. Before committing to creating a team, the organization should do a __________ analysis to evaluate the work and see if a team is appropriate. Select one: a. task (Incorrect) b. process c. skill d. job 3. A compressed...
Problem 1: For a city at 42 deg N latitude, 93 deg W longitude, determine the...
Problem 1: For a city at 42 deg N latitude, 93 deg W longitude, determine the Local Civil Time (CT) for the sunset on May 21 for central standard time.
when it is 2 pm. Mountain standard time on februvary 3 in north platte (longitude=101,latitude=41) what...
when it is 2 pm. Mountain standard time on februvary 3 in north platte (longitude=101,latitude=41) what is solar time
Mongolia, latitude and longitude I need to know everything about it.  Physical Characteristics Human Characteristics, Human/Environmental Interactions,...
Mongolia, latitude and longitude I need to know everything about it.  Physical Characteristics Human Characteristics, Human/Environmental Interactions, Movement with how much ease and ability do ideas, goods, and people flow in and out of the region or subregion you have selected? What drives this movement?
Evaluation and Management Key Components Understanding the three key components that are used to properly identify...
Evaluation and Management Key Components Understanding the three key components that are used to properly identify the correct E/M level of service is essential for you to know as a medical coder. Reimbursement and compliance are closely tied to our accurate knowledge and expertise and these are the main elements of the job! For this discussion, consider your three key components: history, examination, medical decision making as you respond to each prompt. Apply your knowledge by including key component decision...
Suppose, for simplicity, that there are two kinds of used cars in the market. Exactly 50%...
Suppose, for simplicity, that there are two kinds of used cars in the market. Exactly 50% of the cars are good cars worth $10,000, and 50% are bad cars (lemons) worth only $5,000. Also suppose that only the car owner truly knows the type of car that it is. A.If both kinds of cars are sold, what is your expected value from buying a used car? B.Now suppose that current owners of good cars (i.e., the sellers) have a reservation...
A definitive test is one that is used to identify a specific bacterial genus or distinguish...
A definitive test is one that is used to identify a specific bacterial genus or distinguish two closely related organisms. Discuss the results of the definitive tests that allows you to identify proteus vulgaris. (Down below are the tests, however I want to know which of these are definitive test that identifies proteus vulgaris and why) Glucose Fermentation Lactose Fermentation Mannitol Fermentation OF Glucose Methyl Red Voges Proskauer Citrate Utilization Indole Production Phenylalanine Deamination Urea Hydrolysis H2S Production Oxidase Nitrate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT