CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Help for New programmer

    Hello, I am in first year computer science at university... i have an assignment that has one question on it that i cant get my head around and was hoping someone could help me out with it...im sure its very simple...

    Precise angle measurements (and geographical coordinates) are often
    expressed in the DMS format showing degrees, minutes and seconds (for
    example, 234˚12’17”). There are 360 degrees in a circle, there are 60
    minutes in one degree and 60 seconds in one minute. Write a program
    that inputs angle measurements for two angles (each measurement
    requires you to input 3 values) and then adds the two angles together and
    prints out the resulting angle. For example,

    234˚12’17” + 10˚10’10” = 244˚22’27” (correction in yellow)

    Notice that if the sum of the two seconds components exceeds 60 it
    “wraps around” (like a clock) but also causes a carry into the minutes of
    the result. For example,

    10˚20’40” + 10˚20’40” = 20˚41’20”

    This wrap around and carry can occur for minutes too (causing a carry into
    degrees). The wrap around can also happen for degrees but there’s no
    carry in this case. Consider this example:

    200˚30’40” + 159˚29’20” = 0˚0’0”

    HINT: The integer division and remainder operators are key here. Use
    temporary variables to capture each of the carry values. If you have programmed before, please resist the temptation to use an “if” statement -
    it’s not needed.

    Thanks.

  2. #2
    Join Date
    Oct 2009
    Posts
    6

    Re: Help for New programmer

    That (correction in yellow) shouldn't be there!

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help for New programmer

    What have you got so far, and what exactly is the problem you have with this assignment?

    Whenever there is a hard job to be done I assign it to a lazy man; he is sure to find an easy way of doing it...
    W. Chrysler
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Oct 2009
    Posts
    6

    Re: Help for New programmer

    all i have so far are the inputs of all te angles, im just completly lost with this, everything we have done has been basic multipliation division... i dont no how to go about the math

  5. #5
    Join Date
    May 2007
    Posts
    811

    Re: Help for New programmer

    Can you do the same math with pen and paper?

  6. #6
    Join Date
    Oct 2009
    Posts
    6

    Re: Help for New programmer

    I have an idea on how to do it on paper, but not 100%

  7. #7
    Join Date
    Feb 2008
    Posts
    966

    Re: Help for New programmer

    Quote Originally Posted by ryan449 View Post
    I have an idea on how to do it on paper, but not 100%
    If you can't do it on paper (meaning you don't completely understand the math) how do you expect to do it in a program? I don't say that to be rude, but you need to understand the problem before you can code up a solution. Start with understanding the problem.

  8. #8
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Help for New programmer

    Quote Originally Posted by ryan449 View Post
    I have an idea on how to do it on paper, but not 100%
    Well you need to sort out exactly how to solve the problem on paper before thinking about Java code.

    It basically looks like arithmetic in base 60 and base 360.

    Like primary school addition, start with the smallest orders and work up. Start with seconds, move to minutes, adding any carry-over, then degrees, adding any carry-over. So if the seconds or minutes exceed 59, subtract 60 and carry 1 over to the next column. If the degrees exceed 359, just subtract 360.

    In Java, you can either use the '-' (subtraction) operator to subtract 60 or 360, or the '%' (modulus) operator to find the remainder after dividing by 60 or 360. The results, in this case, will be the same.

    From a programmer's point of view, the user is a peripheral that types when you issue a read request...
    P. Williams
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured