winzip icon

NARSCAR RACE Simulation

Email
Submitted on: 1/1/2015 4:03:00 PM
By: Wilton Marranzini (from psc cd)  
Level: Advanced
User Rating: By 9 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++
Views: 1616
 
     First of All Please take a minute and Rate my Code.=) It uses Object Orinted Programming to Make a Nascar Racing simulation. The race is formed of 33 Cars if random aspects effecting it. We start with 33 cars, all of which are identical The race is 500 miles. We're going to do the simulation using clock ticks of .5 seconds. All cars start at zero velocity, and when the race starts they all gain speed at a uniform rate of 0.0020833 miles per second (about 7.5 miles per second) plus a random amount of 5% added or subtracted from the added speed until it reaches a cruising speed of .41667 miles per second (150 miles per hour). It then maintains this speed plus or minus 3%.each car has 20 gallons of fuel. The fuel consumption of the car is normally 30 miles per gallon, divided by the car's current speed divided by 10, e.g. if the car is going 150 miles per hour, its fuel consumption is 30/(150/10)=2 miles per gallon. However, if the car is less than .01 miles (52.8 feet) behind another car, its fuel economy improves by 10% because it's in the draft. However, it cannot stay in the draft more than 100 clock ticks (50 seconds) before the car starts to overheat, in which case the car pulls out of the draft and gets normal fuel mileage. It cannot draft again for 100 clock ticks because the engine has to cool down. A lap in the race is 2 miles, so each time the car has traveled a multiple of two miles we check its fuel. If it doesn't have enough to complete two more laps (4 miles) at the current rate of consumption, it must pull into the pits at the end of the next lap. In this case, when the car comes to the next multiple of two miles (end of lap), it decelerates at the same uniform rate as acceleration (only with no random amount added or subtracted) until it has zero velocity. It then sits for 20 clock ticks (10 seconds) and then accelerates back up to cruising speed.

 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :NARSCAR RACE Simulation
//**************************************
#include <math.h>
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include <time.h>
#include <vector.h>
#include <algorithm>
#include <windows.h>
#include <conio.h>
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.