Question: 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

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 wont 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 youre 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 cant 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.

Grading The grading for this assignment will be a bit different:

Each test will start by checking that you did not modify the bottom part of the provided carGears.cpp file. If you modified the file below the marked line you will get a 0. If youre having trouble with this, I recommend re-downloading the file and copying only your carGears program over to the new files for submission.

Then, your program will be compiled and run. The final line of output will be processed to ensure you did not call accelerate in chooseGears. If you did, then you will get a 0. 5

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, b(speed 2.5) 4c

Example output: (To my knowledge this is the fastest, but I literally dont know how accelerate works so it might not be optimal) After 70 accelerations. Final velocity: 7.72067

#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 < time; i++)

{

double tempVel = vel;

int gear = chooseGear(tempVel);

vel += accelerate(vel, gear, vc);

}

cout << "After " << vc << " accelerations. Final velocity: " << vel <

return 0;

}

// You are not supposed to know the formula for accelerate.

// ... gl trying to find it out

// YOU CANNOT CHANGE THIS FUNCTION IN YOUR SUMBISSION

double accelerate(double v, int g, int &c)

{

static int vc=0;

c=++vc;

if(g<1 || g>6)

{

cout << "No such gear!";

exit(1);

}

double i=v;

double n=54%3;

int x = 256;

int y = 256;

for(int i=0; i < g; i++)

{

x>>=i%true|1;

y>>=!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!true;

if(!(i^(299&1750))) {x+=x/2;}

if(!((i-1)*(i+1)-2*(i-1)+-4)) {x&=y;x<<=1;}

}

double j=true;

int s=(1<<2)+(1<<0);

int m=0x0F>>1;

int b=0x21;

double V=0;

for(int z=1; z < 7; z++)

{

double X=1;

for(int j=1; j < 7; j++)

{

if(j!=z)

{

X*=(g-j)/(z-j);

}

}

X*=(z==(199^0xC2)? -b/4.0 : z>(3^1)? !(z^(132&68))?-(s|=7+(m>>=1)):-s:s);

s^=m;

!s?V+=n+i*(4+(g>4?4-g:g-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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!