-
November 5th, 2008, 02:33 PM
#1
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
-
November 5th, 2008, 03:42 PM
#2
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.
-
November 5th, 2008, 04:37 PM
#3
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?
-
November 5th, 2008, 06:54 PM
#4
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 [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.
-
November 26th, 2008, 06:56 AM
#5
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.
-
November 26th, 2008, 01:19 PM
#6
Re: Car Race Algorithm
Originally Posted by sweet100
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
}
-
November 26th, 2008, 02:14 PM
#7
Re: Car Race Algorithm
Originally Posted by sweet100
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 [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.
-
November 26th, 2008, 02:15 PM
#8
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.
-
November 26th, 2008, 09:37 PM
#9
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.
-
November 27th, 2008, 05:43 AM
#10
Re: Car Race Algorithm
Originally Posted by sweet100
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 [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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|