Question
Hello I need help with my C++ code. The code should display only once to enter the GPS-style coordinates and the last part (5.11591e-12 E)
Hello I need help with my C++ code. The code should display only once to enter the GPS-style coordinates and the last part (5.11591e-12" E) needs to display as 59.99'' as it is displayed in the screenshot of the desired output. Also, the loop needs to be changed. Thanks.
NOTE: the seconds need to be in double instead of float.
Code:
Angle.h
#pragma once #include
using namespace std;
class Angle { private: int degrees, minutes; double seconds; char direct; public:
Angle() { degrees = 0; minutes = 0; seconds = 0; direct = 'N'; } //******************************************* //Lat = 0; Lon = 1; //******************************************* Angle(double gpsVal, bool longitude) { degrees = fabs(gpsVal); minutes = ((fabs(gpsVal) - degrees) * 60); seconds = (((fabs(gpsVal) - degrees) * 60) - minutes) * 60;
direct = (!longitude) ? ((fabs(gpsVal) == gpsVal) ? 'N' : 'S') : ((fabs(gpsVal) == gpsVal) ? 'E' : 'W');
}
Angle(int d, int m, float s, char di) { degrees = d; minutes = m; seconds = s; direct = di; }
void setDegrees(int); void setMinutes(int); void setSeconds(double s); void setDirection(char d);
int getDegrees(); int getMinutes(); double getSeconds(); char getDirection();
void print(); string toString();
};
testAngle.cpp
#include "Angle.h" #include
using namespace std;
void Angle::setDegrees(int d) { degrees = d; }
void Angle::setMinutes(int m) { minutes = m; }
void Angle::setSeconds(double s) { seconds = s; }
void Angle::setDirection(char d) { direct = d; }
int Angle::getDegrees() { return degrees; }
int Angle::getMinutes() { return minutes; }
double Angle::getSeconds() { return seconds; }
char Angle::getDirection() { return direct; }
void Angle::print() { cout
std::string Angle::toString() { stringstream ss; ss
int main() { double lat, lon; Angle latA, lonA; cout > lat; cout > lon;
latA = Angle(lat, 0); lonA = Angle(lon, 1);
cout
// using GPS to DMS constructor cout > lat; Angle latC(lat, 0);
cout > lon; Angle lonC(lon, 1);
cout
return 0; }
OUTPUT WITH HIGHLIGHTED ERROR:
DESIRED OUTPUT:
Enter GPS-style coordinates: Latitude: (+/- 0-90.00): 23.4 Longitude: (+/- 0-180.00): 45.6 DMS: (23 23' 60" N, 45 36' 5.11591e-12" E) Enter GPS-style coordinates: Latitude: (+/- 0-90.00): Enter GPS-style Coordinates: Lattitude (+/- 8-96.00): 23.4 Longitude (+/- 0-180.00):45.6 Converted from GPS to DMS, 23.4. 45.6 is: 23 23' 60' N, 450 35' 59.99" E Process returned @ (@x0) execution tine : 11.581 s Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started