Below is the starter code. Below is the grading rubric. I do not want the same a
ID: 3722417 • Letter: B
Question
Below is the starter code.Below is the grading rubric.
I do not want the same answer that was used for another question on here. Will give thumbs up for correct answer. Functions - Upset Fowls In this assignment, you'll make a knock-off version of the Angry Birds game. The starter program is a working first draft of the game. 1. Correct the first FIXME by moving the intro text to a function named Printintro. Development suggestion: Verity the program has the same behavior before continuing. 2. Correct the second FIXME. Notice that the function GetUsrinpt will need to return two values: fowlAngle and fowlVel. 3. Correct the third FIXME. Notice that the function LaunchFowl only needs to return the value fowlLandingX, but needs the parameters fowlAngle and fowlVel. 4. Correct the fourth FIXME. Notice that the function DtrmnlfHit only needs to return the value didHitSwine, but needs the parameters fowlLandingX and swineX The main should now look like the following code and the program should behave the same as the first draft int main(O double fowlAngie e.e; // angle of launch of fowl (rad) double fowlvel e.0; // velocity of fowl (m/s) double swinex - 0.e; // distance to swine (m) double fowlLandingx = .0; // fowl's horiz. dist, from start (n) bool didHitswine - false; // did hit the swine? srand (time()); swinex = (rand() % 201) + 50; PrintIntro); GetusrInpt (swineX, fowlAngle, fowlVel); fowl Landingx = LaunchFowl(fo!Angle, fowVel); didHitSwine DtrmnIfHit(fowlLandingx, swinex);
Explanation / Answer
CODE
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <ctime>
using namespace std;
const double grav = 9.8;
const double pi = 3.14159265;
void Traject(double t, double a, double v, double& x, double& y)
{
x = v * t * cos(a);
y = v * t * sin(a) - 0.5 * grav * t * t;
return;
}
double DegTRad(double deg)
{
return ((deg * pi) / 180.0);
}
void PrntUpdat(double t, double x, double y)
{
cout << "Time " << fixed << setprecision(0)
<< setw(3) << t << " x = " << setw(3)
<< x << " y = " << setw(3) << y << endl;
return;
}
void PrntIntr()
{
cout << "Welcome to Upset Fowl! ";
cout << "The objective is to hit the Mean Swine by launching an Upset Fowl. ";
}
void GetUsrInpt( double swineX, double &fowlAngle, double &fowlVel)
{
cout << " The Mean Swine is " << swineX << " meters away. ";
cout << "Enter fowl launch angle (deg): ";
cin >> fowlAngle;
fowlAngle = DegTRad(fowlAngle);
cout << "Enter fowl launch velocity (m/s): ";
cin >> fowlVel;
}
double LaunchFowl(double fowlAngle, double fowlVel)
{
double t = 1.0;
double fowlY = 0.0;
double fowlX = 0.0;
do
{
PrntUpdat(t, fowlX, fowlY);
Traject(t, fowlAngle, fowlVel, fowlX, fowlY);
t=t+1.0;
} while ( fowlY > 0.0 );
PrntUpdat(t, fowlX, fowlY);
return fowlX;
}
bool DtrmnIfHit(double fowlLandingX, double swineX)
{
double beforeSwineX = swineX - 30;
if ((fowlLandingX <= swineX) && (fowlLandingX >= beforeSwineX))
{
cout << "Hit'em!!!" << endl;
return true;
}
else
{
cout << "Missed'em..." << endl;
return false;
}
}
int main()
{
double fowlAngle = 0.0;
double fowlVel = 0.0;
double fowlLandingX = 0.0;
double swineX = 0.0;
bool didHitSwine = false;
srand(time(0));
swineX = (rand() % 201) + 50;
PrntIntr();
GetUsrInpt(swineX, fowlAngle, fowlVel);
fowlLandingX = LaunchFowl(fowlAngle, fowlVel);
didHitSwine = DtrmnIfHit(fowlLandingX, swineX);
return 0;
}
//For part 5, change the main function to:
int main()
{
double fowlAngle = 0.0;
double fowlVel = 0.0;
double fowlLandingX = 0.0;
double swineX = 0.0;
bool didHitSwine = false;
srand(time(0));
swineX = (rand() % 201) + 50;
PrntIntr();
while (didHitSwine == false)
{
GetUsrInpt(swineX, fowlAngle, fowlVel);
fowlLandingX = LaunchFowl(fowlAngle, fowlVel);
didHitSwine = DtrmnIfHit(fowlLandingX, swineX);
}
return 0;
}
//For part 6, change the main function to:
int main()
{
double fowlAngle = 0.0;
double fowlVel = 0.0;
double fowlLandingX = 0.0;
double swineX = 0.0;
bool didHitSwine = false;
srand(time(0));
swineX = (rand() % 201) + 50;
PrntIntr();
for(int i=1; i<=4; i++)
{
if(didHitSwine == true)
break;
GetUsrInpt(swineX, fowlAngle, fowlVel);
fowlLandingX = LaunchFowl(fowlAngle, fowlVel);
didHitSwine = DtrmnIfHit(fowlLandingX, swineX);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.