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
|
/* This program will read in various
dimensions of jars and boxes then decide
if the jars firt in the box with .25 clearance
and send the output to external file */
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void makeHeader ();
void Decide_and_Send(double L, double W, double Box_H, double D, double Jar_H);
int main()
{
double L, W, Box_H; // Box length, width, and height
double D, Jar_H; // Jar diameter and height
ifstream inFile;
inFile.open("P4Boxes.txt");
if (!inFile)
{
cout << "ERROR! File could not be opened." << endl;
system("PAUSE");
return 1;
}
inFile >> L;
while (!inFile.eof() )
{
inFile >> W >> Box_H >> D >> Jar_H;
Decide_and_Send(L, W, Box_H, D, Jar_H);
inFile >> L;
}
inFile.close();
return 0;
}
void Decide_and_Send(double L, double W, double Box_H, double D, double Jar_H)
{
string fits_no;
L = L - 0.25;
W = W - 0.25;
Box_H = Box_H - 0.25;
if (L > D && W > D && Box_H > Jar_H)
fits_no = "yes";
else if ( W > D && Box_H > D && L > Jar_H)
fits_no = "yes";
else
fits_no = "no";
//-----------------------------Begin writing into Output file
ofstream outFile; //Create object file and open header again
outFile.open("header.txt");
outFile << "Box: " << "Jar: " << "Jar Fits?";
outFile << "\n\nL" << setw(6) << "W" << setw(6) << "H" << setw(8)
<< "D" << setw(6) << "H" << setw(6) << " " << endl;
outFile << L << setw(6) << W << setw(6) << Box_H << setw(8)
<< D << setw(6) << Jar_H << setw(6) << fits_no << endl;
outFile.close();
}
| |