Results 1 to 3 of 3

Thread: Write a console app to test two classes

  1. #1
    Join Date
    Feb 2014
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Write a console app to test two classes

    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:
    coord.jpg

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Write a console app to test two classes

    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.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Write a console app to test two classes

    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.

Similar Threads

  1. How to write test into PDF file
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 16th August 2013, 14:11
  2. Qt Console App modify test colour
    By Gavin Harper in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2010, 20:07
  3. Replies: 2
    Last Post: 2nd November 2010, 05:15
  4. How to build and execute only test classes
    By vels in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2010, 09:39
  5. How do you run multiple test classes?
    By jeffadams78 in forum Qt Programming
    Replies: 3
    Last Post: 2nd April 2009, 18:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.