dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Car Race Algorithm

  1. #1
    Join Date
    Nov 2008
    Posts
    1

    Question Car Race Algorithm

    I need help with following Car race Algorithm.

    I am writing a simple car race program.
    In a race, the LeaderBoard tracks the current order of the cars, who
    is in first place, etc. We have 10 Cars in the race and we want to know
    what order the cars are in. So we will periodically call UpdateLeaderBoard.

    Assume that we have a record or a structure, Car, in pseudo-code:
    Car
    Name: String;
    StartPos: Int;
    CurPos: Int;
    Speed: Int;
    end;

    You can make it into an object if you want.

    Assume for now that the track is straight, don't have to take
    laps into account. I am only concerned with distance from some
    0 point. To make it interesting, not all the cars start at the same point.

    Position, here, refers to location on the track, not ranking on
    the LeaderBoard.

    Assume that we can initialize the cars by reading data in from a
    file.
    Something like
    proc InitCars
    begin
    I = 0;
    while I < 10 do
    begin
    ReadXML(Cars[I]);
    Next(I)
    end
    end



    The routine that calculates the leaders should be called several
    times throughout the race to find the current ranking.
    Show me, in pseudo-code or language of your choice, what that
    overall program would look like. I'm especially interested in
    the details of UpdateLeaderBoard and how it is called.

    I've purposely not been very precise in my problem statement.
    Assume this is the just the beginning of the program and we
    will be adding lots of features to it, so we want it to be
    maintainable.

    Please offer your help.

    Thank you.
    Ratnayake

  2. #2
    Join Date
    Sep 2006
    Location
    Wantagh,NY
    Posts
    151

    Re: Car Race Algorithm

    Did this question come from a text? Or did your instructor make it up? If it did come from a text, I can almost bet you that the solution is on the web if you know where to look.

  3. #3
    Join Date
    Feb 2008
    Posts
    966

    Re: Car Race Algorithm

    You first.

    What are your thoughts about how to handle this problem? How would you approach creating such a system? Where would you start?

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

    Re: Car Race Algorithm

    So what kind of help do you want with the algorithm? If you ask specific questions you may get specific answers. If you don't, you definitely won't.

    I have always found that plans are useless, but planning is indispensable...
    Dwight Eisenhower
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Aug 2007
    Location
    Birmingham, UK
    Posts
    360

    Re: Car Race Algorithm

    In case you missed the message dlorde posted directly above yours I'll repeat it here as it contains important information regarding your request..
    So what kind of help do you want with the algorithm? If you ask specific questions you may get specific answers. If you don't, you definitely won't.

  6. #6
    Join Date
    Feb 2008
    Posts
    966

    Re: Car Race Algorithm

    Quote Originally Posted by sweet100 View Post
    i will like some help in starting this coding. i don't now how to begin i have some ideas but is begin putting it to paper.
    Sure:
    Code:
    public class Race {
    //put your code here
    }

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

    Re: Car Race Algorithm

    Quote Originally Posted by sweet100 View Post
    i am doing it in c++
    This is a Java forum, ask your question in the C++ forum

    Your question appears to be about basic language syntax and use. These forums do not teach the language, they expect you to know the language basics. You can learn the language from courses, books and online tutorials. No-one can learn it for you.

    The truth is, when all is said and done, one does not teach a subject, one teaches a student how to learn it. Teaching may look like administering a dose, but even a dose must be worked on by the body if it is to cure. Each individual must cure his or her own ignorance...
    J. Barzun
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  8. #8
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Car Race Algorithm

    You are not posting in the correct place. Please be more humble you will get more help.
    ahoodin
    To keep the plot moving, that's why.

  9. #9
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Car Race Algorithm

    #1 Are you both Ratnayake and sweet100?
    #2 Just because you know C++ doesn't mean you know Java.
    #3 Visa Versa.

    So go and post in the Correct Forum and quit all these excuses!
    ahoodin
    To keep the plot moving, that's why.

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

    Re: Car Race Algorithm

    Quote Originally Posted by sweet100 View Post
    i am doing an Introduction to Computer Programming course right now. so i do know the language basic.
    If you want help declaring variables and you don't know how to begin (as you said previously), then you clearly don't know the language basics.

    But as I said before, if you want Java help, ask a specific Java question.

    It is easier to write an incorrect program than understand a correct one...
    A. Perlis
    Please use &#91;CODE]...your code here...&#91;/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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)