Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview Automobile Speed/Distance Application Program This programming project involves creating a C++ program which simulates the speed of a car distance traveled over a period

image text in transcribed
image text in transcribed
Overview Automobile Speed/Distance Application Program This programming project involves creating a C++ program which simulates the speed of a car distance traveled over a period of time. This should be an interactive program which accepts keyboard input the user and produces text output on the console. Each command entered by the user should execute one interval". For example, the "a" (accelerate) command should increase the speed by 5 miles per a time interval of I second. Similarly, the "b" (brake) command should decrease the speed by 5 MPH over a interval of 1 second, and the "e" (cruise) command should keep the spee operations include calculation of how far the car travels during the I second interval, and the total traveled since the program started. A separate "d" (demo) command outputs a sequence ot shown in the sample data, simply by executing the other operations in a predetermined sequence. time hour (MPH) over d constant for 1 second. All of these distance steps, similar to that This document discusses the you understand this document before you begin coding your final solution. requirements for the program, as well as possible implementation details. Be sure General Discussion of the Project tarts out "Stopped", at some initial position. We could say that the car is at "position zero" is zero Miles-per-hour. If the driver of the car does nothing, then the car will remain at its and its current initial position. However, if the driver steps on the gas pedal, the car will some amount. Now that the car is moving, its position will change over time. speed "accelerate": its speed will increase b How much will the position change? This depends on the speed, and how much time has elapsed. It turns out at a car moving at a constant speed of 25 miles per hour (36.7 feet per second) will travel 367 feet in 10 seconds. (Multiply 36.7 feet per second times 10 seconds.) But what if the speed is not constant? In this case we need to know the average speed over the specified time interval. If the speed changes at a constant rate, perhaps 5 miles-per-hour each second, then the average the speed at the beginning of the time interval (previousSpeed), plus the speed at the end of the time inter (currentspeed), divided by 2: averageSpeed (previousSpeed + currentSpeed) / 2; averageSpeed Feet PerSecond averageSpeed 5280.0/3600.0; intervalFeetTraveled-averageSpeed FeetPerSecond timeInterval; or convenience, we can keep the timeInterval value fixed at one second. he calculations described above mention speed in "miles per hour" and distance in "feet". This is deliberate esthetic reasons: people are accustomed to thinking of the speed of a car in "miles per hour", at least in the nited States. Yet, if we were to express the distance traveled over a few seconds in miles, then the number ould be tiny fractions of a mile, and would therefore not be intuitively appropriate to the person using the T237_Projectl_20190125.docx 1/24/2019 11:23 PM page CIT237 C++ Programming from miles per hour (MPH) to feet per program. This is why the averageSpeed value is converted second (FPS). In general, the formula for converting miles per hour (MPH) to feet per second (FPS) is: 5280.0 FPSPH 3600.0 Possible Program Variables Description These variable names are a suggestion, intended to get you thinking about the problem. The implementation which you choose may be different. The contents of each variable to represent the car could be as follows: Variable Description Current speed of the car (miles per hour) current Speed of the car at the end of the "previous" time interval (miles per hour) total Feet Traveled intervalFeet Traveled timeInterval currentState Total feet traveled by the car (since the program started) Total feet traveled during the most recent time interval The amount of elapsed time for each calculation interval (fixed at I second) Current state of the car's motion. Valid values are: "Stopped", "Accelerating", "Cruising" (moving at a steady speed), or "Braking" delta The amount which the speed of the car will increase (during acceleration) or decrease (during braking). By default, this value should be 5 miles per hour. The "accelerate" "delta" is 5 MPH.) , "brake", and "cruise" operations can be calculated as shown. (In this table, the default value of Operation accelerate Calculation previousSpeed currentSpeed; currentSpeed currentSpeed + delta; brake previousSpeedcurrentSpeed; currentspeed currentSpeed delta; cruise previousSpeedcurrentSpeed; Design Note: You must write separate functions for the accelerate, brake, and cruise operations. Not only does this improve the modularity of the program, but it will also make it very easy for you to write the code for the demo operation described later in this document

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions