Question
Hello, I just need a quick fix for my C++ program. The calculations are not precise as they need to be for the GPS coordinates
Hello, I just need a quick fix for my C++ program. The calculations are not precise as they need to be for the GPS coordinates converter. This error is highlighted in the output screenshot. Thanks.
Angle.h
#pragma once #include
using namespace std;
class Angle { private: int degrees, minutes; float seconds; char direct; public:
Angle() { degrees = 0; minutes = 0; seconds = 0; direct = 'N'; } //******************************************* //Lat = 0; Lon = 1; //******************************************* Angle(float 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(float 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(float 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
}
string Angle::toString()
{
stringstream ss;
ss
return ss.str();
}
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 error highlighted:
How it is supposed to be:
Enter GPS-style coordinates: Latitude: (+/- 0-90.00): 23.4 Longitude: (+/- 0-180.00): 45.6 DMS, (23 23' 59.998627" N, 45 35' 59.994507" E) Enter GPS-style coordinates: Latitude: (+/- 0-90.00): DD (decimal degrees)* Latitude 23.4 Longitude 45.6 Get Address DMS (degrees, minutes, seconds)* Latitude NOS 23 23 ' 60 Longitude E W 45 Enter GPS-style coordinates: Latitude: (+/- 0-90.00): 23.4 Longitude: (+/- 0-180.00): 45.6 DMS, (23 23' 59.998627" N, 45 35' 59.994507" E) Enter GPS-style coordinates: Latitude: (+/- 0-90.00): DD (decimal degrees)* Latitude 23.4 Longitude 45.6 Get Address DMS (degrees, minutes, seconds)* Latitude NOS 23 23 ' 60 Longitude E W 45
Step 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