#include <iostream> #include <iomanip> using namespace std; //declaring and init
ID: 3547361 • Letter: #
Question
#include <iostream>
#include <iomanip>
using namespace std;
//declaring and initializing your constant variables//
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;
//declaring function prototypes//
float CrewMoment(int);
float FuelMoment(int);
float PassengerMoment(int);
float CargoMoment(int,int);
void PrintWarning();
void GetData(int&,int&,int&,int&,int&);
int main()
{
//declaring variables//
int crew, passsengers, closet, baggage, fuel;
float totalWt, centerOfGravity;
cout<<fixed<<showpoint<<setprecision(2);
//i think this error means i dont have the same function prototype name//
GetData(crew, passsengers,closet, baggage,fuel);
/*uses wrong type float instead of int also i think hes defining local variables*/
totalWt= EMPTY_WEIGHT+float(passsengers+crew)*PERSON_WT+float(baggage+closet)+float(fuel)*LBS_PER_GAL;
centerOfGravity= (CrewMoment(crew)+PassengerMoment(passsengers)+CargoMoment(closet, baggage)+FuelMoment(fuel)+EMPTY_MOMENT)/totalWt;
cout<<"total weight is"<<totalWt<<"pounds."<<endl;
cout<<"Center of gravity is"<<centerOfGravity<<"inches from thr front of the plane."<<endl;
PrintWarning();
return 0;
}
void GetData( int&crew, int&passengers, int&closet, int&baggage, int&fuel)
{
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 closet, Roundd to nearest whole number."<<endl;
cin>>closet;
cout<<"Enter the weight in pounds, of cargo in the baggage compartment,round to the nearest whole number."<<endl;
cin>>baggage;
cout<<"Enter the number of U.S gallons of fuel loaded, round up to the nearest whole number."<<endl;
cin>>fuel;
cout<<endl;
cout<<"Starship loading data as entered:"<<endl;
cout<<" Crew: "<<setw(6)<<crew<<endl;
cout<<" Passengers: "<<setw(6)<<passengers<<endl;
cout<<" Closet weight: "<<setw(6)<<closet<<"pounds"<<endl;
cout<<" Baggage weight: "<<setw(6)<<baggage<<"pounds"<<endl;
cout<<" Fuel: "<<setw(6)<<fuel<<"gallons"<<endl;
cout<<endl;
}
//Defining function prototype//
float CrewMoment(int crew)
{
const float CREW_DISTANCE=143.0;//distance to seats form 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;
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*ROW2_DIST);
passengers=2;
}
if (passengers>0)
{
moment=moment+float(passengers)*(PERSON_WT*ROW1_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)
{
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;
cout<<"Notice: This program assumes the passengers"<<endl;
cout<<"Fill the seat rows in order 4,3,2,1 and<< << that each passenger and crew member weights"<<PERSON_WT<<"pound"<<endl;
cout<<"It also assumes that Jet-A fuel weights<< <<"<<LBS_PER_GAL<<"pounds"<<endl;
cout<<"Per U.S gallon. The Center of gravity"<<endl;
cout<<"calculations for fuel are approximate. if"<<endl;
cout<<"the aircraft is loaded near its limits, the"<<endl;
cout<<"Pilot's operating handbook should be used"<<endl;
cout<<"to compute weight and center of gravity"<<endl;
cout<<"with more accuracy."<<endl;
}
Explanation / Answer
A few of your if statements in your functions were not closed properly. The below is running but unsure if the calculations are correct, if you have any sample data to run that would be nice to check with.
#include <iostream>
#include <iomanip>
using namespace std;
//declaring and initializing your constant variables//
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;
//declaring function prototypes//
float CrewMoment(int);
float FuelMoment(int);
float PassengerMoment(int);
float CargoMoment(int,int);
void PrintWarning();
void GetData(int&,int&,int&,int&,int&);
int main()
{
//declaring variables//
int crew, passsengers, closet, baggage, fuel;
float totalWt, centerOfGravity;
cout<<fixed<<showpoint<<setprecision(2);
//i think this error means i dont have the same function prototype name//
GetData(crew, passsengers,closet, baggage,fuel);
/*uses wrong type float instead of int also i think hes defining local variables*/
totalWt= EMPTY_WEIGHT+float(passsengers+crew)*PERSON_WT+float(baggage+closet)+float(fuel)*LBS_PER_GAL;
centerOfGravity= (CrewMoment(crew)+PassengerMoment(passsengers)+CargoMoment(closet, baggage)+FuelMoment(fuel)+EMPTY_MOMENT)/totalWt;
cout<<"total weight is "<<totalWt<<" pounds."<<endl;
cout<<"Center of gravity i s"<<centerOfGravity<<" inches from thr front of the plane."<<endl;
PrintWarning();
return 0;
}
void GetData( int&crew, int&passengers, int&closet, int&baggage, int&fuel)
{
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 closet, Roundd to nearest whole number."<<endl;
cin>>closet;
cout<<"Enter the weight in pounds, of cargo in the baggage compartment,round to the nearest whole number."<<endl;
cin>>baggage;
cout<<"Enter the number of U.S gallons of fuel loaded, round up to the nearest whole number."<<endl;
cin>>fuel;
cout<<endl;
cout<<"Starship loading data as entered:"<<endl;
cout<<" Crew: "<<setw(6)<<crew<<endl;
cout<<" Passengers: "<<setw(6)<<passengers<<endl;
cout<<" Closet weight: "<<setw(6)<<closet<<" pounds"<<endl;
cout<<" Baggage weight: "<<setw(6)<<baggage<<" pounds"<<endl;
cout<<" Fuel: "<<setw(6)<<fuel<<" gallons"<<endl;
cout<<endl;
}
//Defining function prototype//
float CrewMoment(int crew)
{
const float CREW_DISTANCE=143.0;//distance to seats form 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;
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*ROW2_DIST);
passengers=2;
}
if (passengers>0)
{
moment=moment+float(passengers)*(PERSON_WT*ROW1_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)
{
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;
cout<<"Notice: This program assumes the passengers"<<endl;
cout<<"Fill the seat rows in order 4,3,2,1 and<< << that each passenger and crew member weights"<<PERSON_WT<<"pound"<<endl;
cout<<"It also assumes that Jet-A fuel weights<< <<"<<LBS_PER_GAL<<"pounds"<<endl;
cout<<"Per U.S gallon. The Center of gravity"<<endl;
cout<<"calculations for fuel are approximate. if"<<endl;
cout<<"the aircraft is loaded near its limits, the"<<endl;
cout<<"Pilot's operating handbook should be used"<<endl;
cout<<"to compute weight and center of gravity"<<endl;
cout<<"with more accuracy."<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.