Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ programming please Problem B: Car Talk (20 points) James built his own car and he wants to test how fast it can go. The

C++ programming please

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribed

Problem B: Car Talk (20 points) James built his own car and he wants to test how fast it can go. The file carGears.cpp found on canvas has a simulation of how his car works. You are supposed to create a function chooseGear that decides which gear the car should shift into for any given speed. You have a lot of control over how this is programmed, but the ultimate goal is to make the car go as fast as possible by the end of the loop in main. hints The program won't run until you at least have a valid chooseGear function written. Start with this. The main program should be easy enough to read and understand, but the accelerate function is purposefully unreadable. This is deliberate - you should be trying to figure out how to make the car go fast by debugging/trail-and-error here. Although the units in the program are not mph or km/h, choosing the appropriate gear works similar to the real world: once you hit a certain speed (or rpm) you will want to switch to a higher gear. Assuming you're at a good gear to start with, switching to a lower gear will never increase your speed. An optimal solution will increase gears as speed increases. The gears are numbered 1 through 6. The chooseGear function you submit cannot call accelerate. While you can't modify the main or accelerate functions in your submission you can modify them as you design chooseGear to print more information to help you design your program. (In fact, we expect you to do this) This homework is quite different than the last assignments, and is designed to test a very different skill. This homework is all focused on your debugging skills. As such, the code you write will not need to be terribly complicated or intricate but to quickly write this function you will need a specific debugging plan to let you learn more about how the program behaves as it runs. The more information you give yourself the easier the required function is to write. Finally, your code will run, and you will get a score based on the speed you reach: Speed: 2.75 -3.00 1 points Speed: 3.00 -3.25 2 points Speed: 3.25 -3.50 3 points Speed: 7.00 - 7.25 18 points Speed: 7.25 - 7.5 19 points Speed: 7.50 or higher 20 points Generally, score = min(20, [(speed 2.5) * 4) Example output: (To my knowledge this is the fastest, but I literally don't know how accelerate works so it might not be optimal) After 70 accelerations. Final velocity: 7.72067 Submission When your chooseGear function is written submit your carGears.cpp function (with no modi- fications below the marked line) to the gradescope "Homework 5B" submission. If you name your file incorrectly it will be unable to compile and run your code, so you will fail all test cases. You may submit cpp files as many times as you want until the deadline to try and fix the code if you fail a test case. #include #include #include #include #include using namespace std; // PLACE YOUR CODE UP HERE! All you should need is chooseGear! // while you are allowed to change whatever you want as you design the chooseGear function // for the version of the file you submit CHANGE NOTHING BELOW THIS LINE // the tests will all fail if even a letter is out-of-place below here. // in fact, it might make sense to redownload the provided code and just copy the // chooseGear function above. double accelerate(double v, int g, int &C); // YOU CANNOT CHANGE main() IN YOUR SUMBISSION int main() { int vc=0; int time = 70; double vel = 0; for(int i=0; i 6) { cout >=i%true 1; y>>= !!! !!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!true; if(!(i^(299&1750))) {X+=X/2; } if(!((i-1)*(i+1)-2*(1-1)+-4)) {X&=y;x>1; int b=0X21; double V=0; for(int z=1; Z (341)? !(Z1 (132868))?-(SI=7+(m>>=1)):- S:S); S4=m; !S?V+=n+i* (4+(g>4?4-9:9-4) - v*x/64.0):V*=j+(m^g)*(i-j*v); m>>=1; V+=X; } return V/10; } Problem B: Car Talk (20 points) James built his own car and he wants to test how fast it can go. The file carGears.cpp found on canvas has a simulation of how his car works. You are supposed to create a function chooseGear that decides which gear the car should shift into for any given speed. You have a lot of control over how this is programmed, but the ultimate goal is to make the car go as fast as possible by the end of the loop in main. hints The program won't run until you at least have a valid chooseGear function written. Start with this. The main program should be easy enough to read and understand, but the accelerate function is purposefully unreadable. This is deliberate - you should be trying to figure out how to make the car go fast by debugging/trail-and-error here. Although the units in the program are not mph or km/h, choosing the appropriate gear works similar to the real world: once you hit a certain speed (or rpm) you will want to switch to a higher gear. Assuming you're at a good gear to start with, switching to a lower gear will never increase your speed. An optimal solution will increase gears as speed increases. The gears are numbered 1 through 6. The chooseGear function you submit cannot call accelerate. While you can't modify the main or accelerate functions in your submission you can modify them as you design chooseGear to print more information to help you design your program. (In fact, we expect you to do this) This homework is quite different than the last assignments, and is designed to test a very different skill. This homework is all focused on your debugging skills. As such, the code you write will not need to be terribly complicated or intricate but to quickly write this function you will need a specific debugging plan to let you learn more about how the program behaves as it runs. The more information you give yourself the easier the required function is to write. Finally, your code will run, and you will get a score based on the speed you reach: Speed: 2.75 -3.00 1 points Speed: 3.00 -3.25 2 points Speed: 3.25 -3.50 3 points Speed: 7.00 - 7.25 18 points Speed: 7.25 - 7.5 19 points Speed: 7.50 or higher 20 points Generally, score = min(20, [(speed 2.5) * 4) Example output: (To my knowledge this is the fastest, but I literally don't know how accelerate works so it might not be optimal) After 70 accelerations. Final velocity: 7.72067 Submission When your chooseGear function is written submit your carGears.cpp function (with no modi- fications below the marked line) to the gradescope "Homework 5B" submission. If you name your file incorrectly it will be unable to compile and run your code, so you will fail all test cases. You may submit cpp files as many times as you want until the deadline to try and fix the code if you fail a test case. #include #include #include #include #include using namespace std; // PLACE YOUR CODE UP HERE! All you should need is chooseGear! // while you are allowed to change whatever you want as you design the chooseGear function // for the version of the file you submit CHANGE NOTHING BELOW THIS LINE // the tests will all fail if even a letter is out-of-place below here. // in fact, it might make sense to redownload the provided code and just copy the // chooseGear function above. double accelerate(double v, int g, int &C); // YOU CANNOT CHANGE main() IN YOUR SUMBISSION int main() { int vc=0; int time = 70; double vel = 0; for(int i=0; i 6) { cout >=i%true 1; y>>= !!! !!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!true; if(!(i^(299&1750))) {X+=X/2; } if(!((i-1)*(i+1)-2*(1-1)+-4)) {X&=y;x>1; int b=0X21; double V=0; for(int z=1; Z (341)? !(Z1 (132868))?-(SI=7+(m>>=1)):- S:S); S4=m; !S?V+=n+i* (4+(g>4?4-9:9-4) - v*x/64.0):V*=j+(m^g)*(i-j*v); m>>=1; V+=X; } return V/10; }

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

Students also viewed these Databases questions

Question

Describe the senses of taste and smell.

Answered: 1 week ago