1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#include <iostream>
#include <iomanip>
using namespace std;
const float PERSON_WT = 170.0; //missing ; and added it after 170.0
const float LBS_PER_GAL = 6.7; // missing ; and added itafter 6.7 // warning C4305: 'initializing' : truncation from 'double' to 'const float'
const float EMPTY_WEIGHT = 9887.0;
const float EMPTY_MOMENT = 3153953.0;
void CargoMoment (int closet, int baggage ); //changed float to void and changed (int, int) to (int closet, int baggage) //error: see declaration of 'CargoMoment'
void CrewMoment( int crew ); //changed float to void and added crew after int //error: see declaration of 'CrewMoment'
void FuelMoment( int fuel ); //changed float to void and added fual after int //error: see declaration of 'FuelMoment'
void GetData( int& crew , int& passengers, int& closet, int& baggage, int& fuel );
//change ( int&, int&, int&, int&, int& ) to ( int& crew, int& passengers, int& closet, int& baggage, int& fuel)
void PassengerMoment( int passengers); //changed float to void and added passengers after int //see declaration of 'PassengerMoment'
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 + int(passengers + crew) * PERSON_WT + //for rid of float before passengers and changed it to int
int(baggage + closet) + int(fuel) * LBS_PER_GAL; //for rid of float before (baggage + closet) and (fuel) and changed it to int
centerOfGravity =
CrewMoment(crew) + PassengerMoment(passengers) + //took out the ( in (CreMoment //error C2186: '+' : illegal operand of type 'void'
CargoMoment(closet, baggage) + FuelMoment(fuel) +
(EMPTY_MOMENT) / totalWt; //changed EMPTY_MOMENT) to (EMPTY_MOMENT)
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) //added the ( symbol after 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" << 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;
}
//******************************************************************
void CrewMoment( /* in */ int crew ) //changed float to void
{
const float CREW_DISTANCE = 143.0; // Distance to crew seats
// from front
return int(crew) * PERSON_WT * CREW_DISTANCE; //changed float(crew) to int(crew) //error C2562: 'CrewMoment' : 'void' function returning a value
}
//******************************************************************
void PassengerMoment( int passengers ) //changed float to void
{
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 +
int(passengers - 6) * PERSON_WT * ROW4_DIST; //changed float(passengers -6) to int(passengers -6)
passengers = 6;
}
if (passengers > 4)
{
moment = moment +
int(passengers - 4) * PERSON_WT * ROW3_DIST; //changed float (passengers -4) to int (passengers -4)
passengers = 4;
}
if (passengers > 2)
{
moment = moment +
int(passengers - 2) * PERSON_WT * ROW1_DIST; //float to int
passengers = 2;
}
if (passengers > 0)
moment = moment +
int(passengers) * PERSON_WT * ROW2_DIST; //float to int
return moment; //error C2562: 'PassengerMoment' : 'void' function returning a value
}
//******************************************************************
void CargoMoment( int closet, int baggage ) //changed float to void
{
const float CLOSET_DIST = 182.0;
const float BAGGAGE_DIST = 386.0;
return int(closet) * CLOSET_DIST + int(baggage) * BAGGAGE_DIST; //changed both float(closet) and float(baggage) to int(closet) and int(baggage)
}
//'CargoMoment' : 'void' function returning a value
//******************************************************************
void FuelMoment (int fuel ) //changed float to void and added the missing ( symbol
{
float fuelWt;
float fuelDistance;
fuelWt = int(fuel) * LBS_PER_GAL; //changed float to int
if (fuel < 60)
fuelDistance = int(fuel) * 314.6; //changed float to int //warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
else if (fuel < 361)
fuelDistance = 305.8 + (-0.01233 * int(fuel - 60)); //float to int //warning C4244: ""
else if (fuel < 521)
fuelDistance = 303.0 + ( 0.12500 * int(fuel - 361)); //float to int //warning C4244
else
fuelDistance = 323.0 + (-0.04444 * int(fuel - 521)); //float to int //warning C4244
return fuelDistance * fuelWt;
}
//error C2562: 'FuelMoment' : 'void' function returning a value
//******************************************************************
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;
}
|