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

analyze, add necessary comments, problem statements 1 #include <iostream> #inclu

ID: 3536868 • Letter: A

Question

analyze, add necessary comments, problem statements

1

#include <iostream>

#include <iomanip>

using namespace std;

const float PERSON_WT = 170.0

const float LBS_PER_GAL = 6.7

const float EMPTY_WEIGHT = 9887.0;

const float EMPTY_MOMENT = 3153953.0;

float CargoMoment( int, int );

float CrewMoment( int );

float FuelMoment( int );

void GetData( int&, int&, int&, int&, int& );

float PassengerMoment( int );

void PrintWarning();

int main()

{

int crew;

int passengers;

int closet;

int baggage;

int fuel;

float totalWt;

float centerOfGravity;

cout << fixed << showpoint << setprecision(2);

GetData(crew, passengers, closet, baggage, fuel);

totalWt =

EMPTY_WEIGHT + float(passengers + crew) * PERSON_WT +

float(baggage + closet) + float(fuel) * LBS_PER_GAL;

centerOfGravity =

(CrewMoment(crew) + PassengerMoment(passengers) +

CargoMoment(closet, baggage) + FuelMoment(fuel) +

EMPTY_MOMENT) / totalWt;

cout << "Total weight is " << totalWt << " pounds." << endl;

cout << "Center of gravity is " << centerOfGravity

<< " inches from the front of the plane." << endl;

PrintWarning();

return 0;

}

//******************************************************************

void GetData( int& crew, int& passengers, int& closet, int& baggage, int& fuel

{ 2

cout << "Enter the number of crew members." << endl;

cin >> crew;

cout << "Enter the number of passengers." << endl;

cin >> passengers;

cout << "Enter the weight, in pounds, of cargo in the" << endl

<< " closet, rounded up to the nearest whole number."

<< endl;

cin >> closet;

cout << "Enter the weight, in pounds, of cargo in the" << endl

<< " aft baggage compartment, rounded up to the" << endl

<< " nearest whole number." << endl;

cin >> baggage;

cout << "Enter the number of U.S. gallons of fuel" << endl

<< " loaded, rounded up to the nearest whole number."

<< endl;

cin >> fuel;

cout << endl;

cout << "Starship loading data as entered:" << endl

<< " Crew: " << setw(6) << crew << endl

<< " Passengers: " << setw(6) << passengers << endl

<< " Closet weight: " << setw(6) << closet << " pounds"

<< endl

<< " Baggage weight:" << setw(6) << baggage << " pounds"

<< endl

<< " Fuel: " << setw(6) << fuel << " gallons"

<< endl << endl;

}

//******************************************************************

float CrewMoment( /* in */ int crew )

{

const float CREW_DISTANCE = 143.0; // Distance to crew seats

// from front

return float(crew) * PERSON_WT * CREW_DISTANCE;

}

//******************************************************************

float PassengerMoment( int passengers )

{

const float ROW1_DIST = 219.0;

const float ROW2_DIST = 265.0;

const float ROW3_DIST = 295.0;

const float ROW4_DIST = 341.0;

float moment = 0.0; 3

if (passengers > 6)

{

moment = moment +

float(passengers - 6) * PERSON_WT * ROW4_DIST;

passengers = 6;

}

if (passengers > 4)

{

moment = moment +

float(passengers - 4) * PERSON_WT * ROW3_DIST;

passengers = 4;

}

if (passengers > 2)

{

moment = moment +

float(passengers - 2) * PERSON_WT * ROW1_DIST;

passengers = 2;

}

if (passengers > 0)

moment = moment +

float(passengers) * PERSON_WT * ROW2_DIST;

return moment;

}

//******************************************************************

float CargoMoment( int closet, int baggage )

{

const float CLOSET_DIST = 182.0;

const float BAGGAGE_DIST = 386.0;

return float(closet) * CLOSET_DIST +float(baggage) * BAGGAGE_DIST;

}

//******************************************************************

float FuelMoment int fuel )

{

float fuelWt;

float fuelDistance;

fuelWt = float(fuel) * LBS_PER_GAL;

if (fuel < 60)

fuelDistance = float(fuel) * 314.6;

else if (fuel < 361) 4

fuelDistance = 305.8 + (-0.01233 * float(fuel - 60));

else if (fuel < 521)

fuelDistance = 303.0 + ( 0.12500 * float(fuel - 361));

else

fuelDistance = 323.0 + (-0.04444 * float(fuel - 521));

return fuelDistance * fuelWt;

}

//******************************************************************

void PrintWarning()

{

cout << endl

<< "Notice: This program assumes that passengers" << endl

<< " fill the seat rows in order 2, 1, 3, 4, and" << endl

<< " that each passenger and crew member weighs "

<< PERSON_WT << " pounds." << endl

<< " It also assumes that Jet-A fuel weighs "

<< LBS_PER_GAL << " pounds" << endl

<< " per U.S. gallon. The center of gravity" << endl

<< " calculations for fuel are approximate. If" << endl

<< " the aircraft is loaded near its limits, the" << endl

<< " pilot's operating handbook should be used" << endl

<< " to compute weight and center of gravity" << endl

<< " with more accuracy." << endl;

}

Explanation / Answer

#include #include // For setw() and setprecision() const float PERSON_WT = 170.0; // Average person weighs // 170 lbs. const float LBS_PER_GAL = 6.7; // Jet-A weighs 6.7 lbs. // per gal. const float EMPTY_WEIGHT = 9887.0; // Standard empty weight const float EMPTY_MOMENT = 3153953.0; // Standard empty moment float CargoMoment( int, int ); float CrewMoment( int ); float FuelMoment( int ); void GetData( int&, int&, int&, int&, int& ); float PassengerMoment( int ); void PrintWarning(); int main() { int crew; // Number of crew on board (1 or 2) int passengers; // Number of passengers (0 through 8) int closet; // Weight in closet (160 lbs. maximum) int baggage; // Weight of baggage (525 lbs. max.) int fuel; // Gallons of fuel (10 through 565 gals.) float totalWt; // Total weight of the loaded Starship float centerOfGravity; // Center of gravity of loaded Starship cout.setf(ios::fixed, ios::floatfield); // Set up floating pt. cout.setf(ios::showpoint); // output format cout