PDA

View Full Version : Write a console app to test two classes



Losh
26th February 2014, 16:09
Hi there im a rookie in programming. ive spent two weeks reading a textbook to solve this question but im more confused then anything. Im just hoping somebody can maybe help me.

ok the Question : Define and implement classes to store GPS coordinates using the following UML class diagram:
10084

Note that the GPSCoord class has a composition relationship with the Coordinate class. There is only a zero-parameter constructor for the GPSCoord class which should initialise its latitude and longitude to 0° 0' 0'' N and 0° 0' 0'' E, respectively. To change these values, the setCoord() member function must be used. If the value of its fourth parameter is 'N' or 'S', the latitude coordinate must be set, but if it is 'E' or 'W', the longitude coordinate must be set.

The Coordinate class stores three integers for the degrees, minutes and seconds of a coordinate, and a character for the cardinal direction. The number of degrees should be an integer from 0 to 179, and the number of minutes and seconds should both be integers from 0 to 59. The cardinal direction should be N or S if it is specifying latitude, or E or W for longitude. Note that the constructor need not check whether the values provided as parameters comply with these restrictions – it can assume that the user (or client program) provides valid values.

The toString() member function of the Coordinate class should return a string comprising the three integer values annotated with the necessary degree symbol and inverted commas to indicate degrees, minutes and seconds, and the cardinal direction. So the function call
Coordinate(25, 46, 3, 'S').toString()
should return the string 25° 46' 3" S.
(Hint: Use char(248) to produce the ° character.)

The toDecimal() member function of the Coordinate class should convert the geographic coordinate to a decimal (double) value. To do this, the number of minutes must be divided by 60, and the number of seconds by 360, and these fractions must be added to the number of degrees. The cardinal direction must then be used to determine whether the decimal number of degrees should be positive or negative: If the cardinal direction is N or E, the value should be positive, but if it is S or W, it should be negative. The function call
Coordinate(25, 46, 3, 'S').toDecimal()
should therefore return the floating point value -25.767.

The toString() member function of the GPSCoord class takes a single boolean value as parameter to specify whether it should be rendered as a decimal coordinate or not. If it is false, it should return the concatenated string values of its latitude and longitude in geographic coordinates (obtained by simply calling toString() on each). If it is true, it should return a string comprising the decimal forms of its latitude and longitude (obtained by calling toDecimal() on each and converting them to strings).

Note also that the definition and implementations of these two classes must be placed in their own header and source files.

Write a console app to test these classes. The program should construct an instance of GPSCoord, input values for its latitude and longitude from the keyboard, and set them accordingly. (The program need not check for valid input.) It should then display the GPS coordinate in both geographic and decimal formats.


I have attached my code as well as the UML diagram. If you can help me i would really appreciate it. Thank you

stampede
26th February 2014, 16:24
First thing I can tell you - your program doesn't have a main() function, quite hard to write a working C++ program without it :)
Anyway, the more specific your question, the more likely you will get any answer. Right now it looks like one of "do my homework" request, which typically are ignored here.

ChrisW67
27th February 2014, 01:40
Assuming you are (the assignment is) looking for a Qt solution; Qt has a testing facility specifically for this sort of thing: QTestLib Manual and the associated tutorial.

On a cursory glance at your class code I can see issues with the cardinal direction characters, the setCoords() function, and memory leaks.