Explore BrainMass

C++: Write a Class Coord that Includes Degrees

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

In ocean navigation, locations are measured in degrees and minutes of latitude and longitude. For example, 149 degrees 34.8 minutes west longitude, and 17 degrees 31.5 minutes south latitude, to be written as 149°34.8' W, 17°31.5' S. There are 60 minutes in a degree. Longitudes are measured from 0 to 180 degrees, east or west from Greenwich, England. Latitude is measured from 0 to 90 degrees, north or south from the equator to the poles.

Write a class Coord that includes the members: degrees (int), minutes (float), and the direction character (N, S, E, or W) to represent both latitude and longitude (altogether 6 members). The class must have a constructor accepting 6 parameters and a toString() method that returns a string representation of the coordinate as a C++ string (not C string).

The main () program must allow the user to enter the coordinates one-by-one, create the Coord object, and apply its toString() method for displaying. You can use hex character constant 'xB0' for printing the degree symbol (°).

© BrainMass Inc. brainmass.com March 21, 2019, 5:59 pm ad1c9bdddf

Solution Preview

Please see the attachment.

// Navigation.cpp

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

class Coord {
int longtitude_degree;
float longtitude_minute;
char longtitude_direction;
int latitude_degree;
float latitude_minute;
char latitude_direction;
Coord(int, float, char, int, float, char); // Constructor to accept 6 parameters
string toString(); // method for ...

Solution Summary

The solution writes a class Coord that includes degrees and minutes of latitudes and longitudes.