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 182 183 184 185 186 187 188 189
|
//---------------------------------------------------------------------
//
// Name:
//
// Course: CS 1430, Section 4
//
// Purpose: Program outputs a post offices list of packages
//and displays how many packages, cost of rejected packages
//, how many rejected packages, and a table showing mass of packages
//
// Input: 1 integer for mass, 1 integer for cost
//3 integers for each side of box, integer for trans. number,
//and 2nd integer for mass of transaction table
//
// Output: outputs a table of mass and corresponding cost
//outputs table showing each individual transaction
//and their individual number, mass, or corresponding rejection.
//---------------------------------------------------------------------
const int MAX_ARRAY_SIZE = 25;
const int MAX_TRANS_SIZE = 3;
const int DIM_MASS_LIMIT = 32000;
const int DIM_LENGTH_LIMIT = 101;
const int DIM_SUM_LIMIT = 240;
const int DOUBLER = 2;
void ReadParcelPostTable(int masses[], float costs[], int & sizeOfTable);
void PrintParcelPostTable(const int masses[], const float costs[],
int sizeOfTable);
int FindIndexOfMass(const int masses[], int lookUpMass, int size);
float FindLargestDimension( const int dim[], int size);
float Girth( const int dim[], int size);
bool TestLength ( const int s1, const int s2, const int s3 );
bool TestMass ( const int mass );
void PrintTransactionTable ( int transNumber, int mass, int s1,
int s2, int s3);
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
cout << fixed << showpoint << setprecision(2);
int masses[MAX_ARRAY_SIZE];
float costs[MAX_ARRAY_SIZE];
int transNumber = 0;
int sizeOfTable, mass = 0;
int s1 = 0, s2 = 0, s3 = 0;
ReadParcelPostTable( masses, costs, sizeOfTable );
PrintParcelPostTable( masses, costs, sizeOfTable );
PrintTransactionTable ( transNumber, mass, s1, s2, s3 );
return 0;
}
//Reads the parcel post table, reading the size of the table first
//and that many masses and costs. Assume that the massess are
//ordered in ascending order by mass in (integer) grams.
//params: in, in, inout
void ReadParcelPostTable(int masses[], float costs[], int & sizeOfTable)
{
cout << "Enter how many in Parcel Post Table (Grams Dollars):\n\n";
cin >> sizeOfTable;
cout << "Enter Parcel Post Table (mass & cost) information:\n\n";
for ( int i = 0; i < sizeOfTable; i++ )
cin >> masses[i] >> costs[i];
}
//Prints the parcel post table in tabular form. Prints the heading
//that includes printing the size of the table. (See sample output)
//params: in, in, in
void PrintParcelPostTable(const int masses[], const float costs[],
int sizeOfTable)
{
cout << "Parcel Post Table in tabular form with " << sizeOfTable
<< " entries. \n";
cout << setw(10) << "Mass" << setw(12) << "Cost" << endl;
cout << setw(10) << "------" << setw(12) << "-----" << endl;
for ( int i = 0; i < sizeOfTable; i++ )
cout << setw(10) << masses[i] << setw(12) << costs[i] << endl;
cout << setw(10) << "------" << setw(15) << "-----\n\n\n";
}
//Finds and returns an index of the look-up-mass in the Masses
//array. Since the Masses array is ordered in ascending order by
//mass, this function returns the index of the first mass
//in the masses array such that lookUpMass is less than or equal
//to masses[i].
//On the off chance that no such index can be found, returns -1.
//params: in, in, in
int FindIndexOfMass(const int masses[], int lookUpMass, int size)
{
int index = -1;
for ( int i = 0; i < size; i++ )
{
if ( lookUpMass <= masses[i] )
return i;
}
return index;
}
//Returns the largest value in the dim array; size is how many items
//are in the dim array.
//params: in
float FindLargestDimension( const int dim[], int size)
{
float largest = 0;
for ( int i = 0; i < size; i++ )
{
if ( dim[i] > largest )
largest = dim[i];
}
return largest;
}
//Returns the girth of a parcel where girth is calculated as twice
//the difference of the sum of the elements in the dim array and the
//largest of the dimensions.
//params: in
float Girth( const int dim[], int size)
{
float girth;
int sum = 0;
for (int i = 0; i < size; i++ )
sum += dim[i];
girth = DOUBLER * ( sum - FindLargestDimension (dim, size ) );
return girth;
//Girth = 2 * ( s1 + s2 + s3 – length)
}
bool TestMass ( const int mass )
{
if ( mass > DIM_MASS_LIMIT )
return true;
else
return false;
}
bool TestLength ( const int s1, const int s2, const int s3 )
{
if ( s1 >= DIM_LENGTH_LIMIT || s2 >= DIM_LENGTH_LIMIT
|| s3 >= DIM_LENGTH_LIMIT )
return true;
else
return false;
}
void PrintTransactionTable ( int transNumber, int mass, int s1, int s2, int s3 )
{
int processed_Counter = 0, rejected_Counter = 0;
float cost_Of_Rejected = 0;
cout << "Transaction Number" << setw(11) << "Mass" << setw(27)
<< "Cost/Rejection Message" << endl;
cout << "------------------" << setw(11) << "-----" << setw(36)
<< "-------------------------------" << endl;
cin >> transNumber >> mass >> s1 >> s2 >> s3;
while ( !cin.eof() )
{
processed_Counter++;
cout << setw(18) << transNumber << setw(11) << mass;
if ( TestMass(mass) )
{
rejected_Counter++;
cout << setw(35) << "REJECT_01 - EXCEEDS MASS LIMIT";
}
else if ( TestLength( s1, s2, s3) )
{
rejected_Counter++;
cout << setw(40) << "REJECT_02 - EXCEEDS DIMENSION LIMIT";
}
cin >> transNumber >> mass >> s1 >> s2 >> s3;
cout << endl;
}
cout << setw(30) << "\nNumber of packages processed is "
<< processed_Counter << endl;
cout << setw(30) << "Number of packages rejected is "
<< rejected_Counter << endl;
cout << setw(30) << "Total cost of sending non-rejected packages is "
<< "$" << endl;
}
|