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
|
const int MAX_CITIES = 10;
const int MAXLEN = 20;
const int MAXCOMMANDLEN = 9;
const int NOT_FOUND = -1;
enum CommandType
{
ADD, DELETE, UPDATE, OUTPUT, CLEAR, SUMMARIZE,
TOTAL, SORT, QUIT, UNKNOWN
};
typedef char CityNameType[MAXLEN + 1];
CommandType GetCommand();
class Destination
{
private:
CityNameType city;
int package_count;
float total_weight;
public:
Destination()
{
strcpy( city, "PLATTEVILLE" );
package_count = 0;
total_weight = 0;
}
Destination( const CityNameType name )
{
strcpy( city, name );
package_count = 0;
total_weight = 0;
}
bool DestinationHasName( const CityNameType name ) const
{
if ( strcmp ( city, name ) )
return true;
else
return false;
}
void ToUpper() const
{
CityNameType city;
for ( int L = 0; L < strlen( city ); L++ )
{
if ( city[L] == '_' )
city[L] = ' ';
else
city[L] = toupper ( city[L] );
}
}
void PrintDest() const
{
PrintCityName(true);
cout << setw(4) << package_count << " packages weighing";
cout << setw(11) << fixed << setprecision(2)
<< total_weight << " pounds" << endl;
}
void PrintCityName ( bool rightjustify ) const
{
CityNameType ucity;
strcpy( ucity, city );
ToUpper();
if ( rightjustify == true )
cout << setw(19) << ucity;
else
cout << ucity;
}
void RecordShipment( int numPackages, float packageWeight )
{
package_count += numPackages;
total_weight += packageWeight;
SumInTotals ( package_count, total_weight );
}
void ClearShipment()
{
package_count = 0;
total_weight = 0;
}
float AverageWeight() const
{
float ave = 0.0;
if ( package_count == 0 )
ave = 0.0;
else
ave = total_weight / package_count;
return ave;
}
void SumInTotals ( int& packageCountSum,
float& packageWeightSum ) const
{
packageCountSum += package_count;
packageWeightSum += total_weight;
}
int CompareToWeight( const Destination & destB )
{
if ( destB.total_weight < total_weight )
return 1;
else if ( destB.total_weight > total_weight )
return -1;
else
return 0;
}
bool LessThanByName ( const Destination& destB ) const
{
if ( strcmp ( destB.city, city ) > 0 )
return true;
else
return false;
}
int GetPackageCount() const
{
return package_count;
}
float GetWeightTotal() const
{
return total_weight;
}
};
|