Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Update with FIXME: #include <iostream> #include <iomanip> #include <cmath> #incl

ID: 3852586 • Letter: U

Question

Update with FIXME:

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const double pi = 3.14159265;
const double grav = 9.8; // Earth gravity (m/s^2)

// Given time, angle, velocity, and gravity
// Update x and y values
void Trajectory(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;
}

// convert degree value to radians
double DegToRad(double deg) {
return ((deg * pi) / 180.0);
}

// print time, x, and y values
void PrintUpdate(double t, double x, double y) {
cout << "Time " << fixed << setprecision(0)
<< setw(3) << t << " x = " << setw(3)
<< x << " y = " << setw(3) << y << endl;
return;
}

int main() {
double t = 1.0; // time (s)
double fowlY = 0.0; // object's height above ground (m)
double fowlAngle = 0.0; // angle of launch of fowl (rad)
double fowlVel = 0.0; // velocity of fowl (m/s)
double fowlX = 0.0; // object's horiz. dist. from start (m)
double fowlLandingX = 0.0; // fowl’s horiz. dist. from start (m)
double swineX = 0.0; // distance to swine (m)
double beforeSwineX = 0.0; // distance before swine that is acceptable as a hit (m)
bool didHitSwine = false; // did hit the swine?
  
srand(time(0));
swineX = (rand() % 201) + 50;
  
// FIXME Make into a function called PrintIntro
cout << "Welcome to Upset Fowl! ";
cout << "The objective is to hit the Mean Swine by launching an Upset Fowl. ";

// FIXME Make into a function called GetUsrInpt
cout << " The Mean Swine is " << swineX << " meters away. ";
cout << "Enter fowl launch angle (deg): ";
cin >> fowlAngle;
fowlAngle = DegToRad(fowlAngle); // convert to radians
cout << "Enter fowl launch velocity (m/s): ";
cin >> fowlVel;
  
// FIXME Make into a function called LaunchFowl
do {
PrintUpdate(t, fowlX, fowlY);
Trajectory(t, fowlAngle, fowlVel, fowlX, fowlY);
t=t+1.0;
} while ( fowlY > 0.0 ); // while above ground
PrintUpdate(t, fowlX, fowlY);


fowlLandingX = fowlX;

  
// FIXME Make into a function called DtrmnIfHit
beforeSwineX = swineX - 30;
if ((fowlLandingX <= swineX) && (fowlLandingX >= beforeSwineX)) {
cout << "Hit'em!!!" << endl;
didHitSwine = true;
} else {
cout << "Missed'em..." << endl;
didHitSwine = false;
}

return 0;
}

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 Printlntro Development suggestion: Verify the program has the same behavior before continuing 2. Correct the second FIXME. Notice that the function GetUsrlnpt 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) double fow!Angle = 0.0; // angle of launch of fowl (rad) double fowlVe! = 0.0; // velocity of fowl (m/s) double swineX 0.0; // distance to swine (m) double fow! Landingx = 0.0; // fowl's horiz" dist. from start (m) bool didHitSwine false; // did hit the swine ? srand (time (0)) swineX (rand () % 201 ) + 50; PrintIntro GetUsrInpt (swineX, fowlAngle, fowlVel); towl Land ingX LaunchFowl (fowlAngle, fowlVel); didHitSwine Otrmnlfhit (fowl Landingx, swineX);

Explanation / Answer

Code for all parts till part 4 is given below :

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const double pi = 3.14159265;
const double grav = 9.8; // Earth gravity (m/s^2)

// Given time, angle, velocity, and gravity
// Update x and y values
void Trajectory(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;
}

// convert degree value to radians
double DegToRad(double deg)
{
    return ((deg * pi) / 180.0);
}

// print time, x, and y values
void PrintUpdate(double t, double x, double y)
{
    cout << "Time " << fixed << setprecision(0)
         << setw(3) << t << "   x = " << setw(3)
         << x << "   y = " << setw(3) << y << endl;
    return;
}

// Print the introduction for the game
void PrintIntro()
{
    cout << "Welcome to Upset Fowl! ";
    cout << "The objective is to hit the Mean Swine by launching an Upset Fowl. ";
}

// Function to take input from user
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 = DegToRad(fowlAngle); // convert to radians
    cout << "Enter fowl launch velocity (m/s): ";
    cin >> fowlVel;
}

// Calculate the landing distance fowlLandingX
double LaunchFowl(double fowlAngle, double fowlVel)
{
   double t = 1.0; // time (s)
    double fowlY = 0.0; // object's height above ground (m)
   double fowlX = 0.0; // object's horiz. dist. from start (m)
   do
   {
        PrintUpdate(t, fowlX, fowlY);
        Trajectory(t, fowlAngle, fowlVel, fowlX, fowlY);
        t=t+1.0;
    } while ( fowlY > 0.0 ); // while above ground
    PrintUpdate(t, fowlX, fowlY);
      
   return fowlX;
}

// Function to determine if the swine is hit
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; // angle of launch of fowl (rad)
    double fowlVel = 0.0; // velocity of fowl (m/s)
    double fowlLandingX = 0.0; // fowl’s horiz. dist. from start (m)
    double swineX = 0.0; // distance to swine (m)
    bool didHitSwine = false; // did hit the swine?
  
    srand(time(0));
    swineX = (rand() % 201) + 50;
  
    PrintIntro();
   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; // angle of launch of fowl (rad)
    double fowlVel = 0.0; // velocity of fowl (m/s)
    double fowlLandingX = 0.0; // fowl’s horiz. dist. from start (m)
    double swineX = 0.0; // distance to swine (m)
    bool didHitSwine = false; // did hit the swine?
  
    srand(time(0));
    swineX = (rand() % 201) + 50;
  
    PrintIntro();
  
    while (didHitSwine == false)
    {
       GetUsrInpt(swineX, fowlAngle, fowlVel);
        fowlLandingX = LaunchFowl(fowlAngle, fowlVel);
        didHitSwine = DtrmnIfHit(fowlLandingX, swineX);
    }
  
    return 0;
}

And for part 6:

int main()
{
    double fowlAngle = 0.0; // angle of launch of fowl (rad)
    double fowlVel = 0.0; // velocity of fowl (m/s)
    double fowlLandingX = 0.0; // fowl’s horiz. dist. from start (m)
    double swineX = 0.0; // distance to swine (m)
    bool didHitSwine = false; // did hit the swine?
  
    srand(time(0));
    swineX = (rand() % 201) + 50;
  
    PrintIntro();
  
    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;
}

The code for all parts should be self-explanatory. If any doubt still persists, feel free to comment below and it will be cleared at the earliest.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote