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

Analyze and add necessary comments 1 #include <iostream> #include <iomanip> usin

ID: 3536911 • Letter: A

Question

Analyze and add necessary comments

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

all part of the code is clearlyy understood..

i have added only some comments for that.

#include <iostream> // header files

#include <iomanip>

using namespace std;

const float PERSON_WT = 170.0; // constant declarations that cant be altered anywhere in program

const float LBS_PER_GAL = 6.7;

const float EMPTY_WEIGHT = 9887.0;

const float EMPTY_MOMENT = 3153953.0;

float CargoMoment( int, int ); // initial function declarations

float CrewMoment( int );

float FuelMoment( int );

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

float PassengerMoment( int );

void PrintWarning();

int main() //main function

{

int crew;

int passengers;

int closet;

int baggage;

int fuel;

float totalWt;

float centerOfGravity;

cout << fixed << showpoint << setprecision(2); // print fixed , show point and value set for precision

GetData(crew, passengers, closet, baggage, fuel); //get data - crew , passengers closet etc

totalWt =

EMPTY_WEIGHT + float(passengers + crew) * PERSON_WT +

float(baggage + closet) + float(fuel) * LBS_PER_GAL; // calculation of total weight

centerOfGravity =

(CrewMoment(crew) + PassengerMoment(passengers) +

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

EMPTY_MOMENT) / totalWt; // calculating centre of gravity

cout << "Total weight is " << totalWt << " pounds." << endl; // printing values

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) // check if passengers are greator than six

{

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;

}

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