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

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
//Function Prototypes
void WRITE(int, int, int,int,int, double, ofstream&);
void PRINT(ofstream&);
int READ(int);
int AREA(int, int, int);
int GIRTH(int, int);
int LARGEST(int, int, int);
double COST(int);
int DIMENSION(int, int);
int SMALLEST(int, int, int);
int MIDDLE(int, int, int, int, int);
//File I/O
ofstream out("Shipping.out");
ifstream inf("Shipping.in");
//PRINT FUNCTION prints the header atop the program output.
void PRINT(ofstream& out)
{
out << "\tShipping Box Program\n"
<< "Height x Depth\t Length \tArea Shipping Dimension\t Charges\n"
<< setprecision(2) << fixed;
}
//READ FUNCTION reads in the data from the infile.
int READ(ifstream& inf)
{
int a;
inf >> a;
return a;
}
//LARGEST FUNCTION finds the largest value of the 3 numbers.
int LARGEST(int a, int b, int c)
{
return max(max(a,b),c);
}
//SMALLEST FUNCTION returns the smallest value.
int SMALLEST(int a, int b, int c)
{
return min(min(a,b),c);
}
//MIDDLE FUNCTION returns the middle value.
int MIDDLE(int a, int b, int c, int w, int l)
{
if(a!=l && a!=w)
return a;
if(b!=l && b!=w)
return b;
if(c!=l && c!=w)
return c;
}
//AREA FUNCTION computes the area.
int AREA(int w,int h, int l)
{
return w*h*l;
}
//GIRTH FUNCTION calculates the girth of the box.
int GIRTH(int a, int b)
{
return (a + b) * 2;
}
//DIMENSION FUNCTION calculates the inches to find the cost.
int DIMENSION(int g, int l)
{
return g + l;
}
//COST FUNCTION calculates the cost for the box.
double COST(int sd)
{
return 0.87 * sd;
}
//WRITE FUNCTION prints to the file
void WRITE(int a, int b, int c, int d, int e, double f, ofstream& out)
{
out << " \t" << a << "x" << b << "\t\t " << c << " \t\t" << d
<< " \t\t" << e << " \t\t\t $" << f << endl;
}
//main FUNCTION does all the work by calling the appropriate function.
int main()
{
int D1,D2,D3,area,shipdim,total,girth,length,width,height;
PRINT(out);
while(!inf.eof())
{
D1=READ(inf);
D2=READ(inf);
D3=READ(inf);
width=SMALLEST(D1,D2,D3);
length=LARGEST(D1,D2,D3);
height=MIDDLE(D1,D2,D3,length, width);
girth=GIRTH(D1,D2);
area=AREA(D1,D2,D3);
shipdim=DIMENSION(girth,length);
total=COST(shipdim);
WRITE(width,height,length,area,shipdim,total,out);
}
out.close();
inf.close();
return 0;
}
 