//
// custorderscf2.cpp
//
#include <cstdlib> // student ...... Jones, Patricia
#include <iostream> // section ...... MW row .... 4
#include <fstream> // due date ..... xx/xx/xx
#include <iomanip> // refer to ..... Gaddis Ch3
void SetPrecision(int); // procedure prototype
using namespace std; // avoid std::cin >> ...
/* declare global data elements */
int ordnum; // input variables
string partnum; //
int quantity; //
double price; //
void readinput (void); //
ifstream infile; // declare file object
int main (void) // main function header
{ // begin block
int oldordnum; // old order number
double de1extprice; // detail line ext price
double cf1extprice; // order total
double cf2extprice; // report total
/* begin procedural code */
SetPrecision(2); // set floating points
cf2extprice = 0; // clear report total
infile.open("custorders.bdl"); // open input file
/* test for successful open */
if(!infile)
{
cout << "Input file open error!";
exit(-1); // error pgm stop
}
/* print column headers */
cout << setw(10) << "ORD NUM"
<< setw(10) << "PARTNUM"
<< setw(10) << "QUANTITY"
<< setw(10) << "PRICE"
<< setw(12) << "EXT PRICE" << "\n\n";
/* begin processing loop */
readinput(); // read first record
oldordnum = ordnum; // save the control field
while(ordnum != 99999); // test for more data
{
cf1extprice = 0; // clear order total
while(ordnum == oldordnum) // same group ?
{
cout << setw(10) << ordnum // detail calc
<< setw(10) << partnum // level one calc
<< setw(10) << quantity // print detail
<< setw(10) << price;
de1extprice = quantity * price; //
cout << setw(12) << de1extprice << endl;
//
cf1extprice = cf1extprice + de1extprice; //
//
readinput(); // read next record
}
cout << endl;
cout << setw(52) << cf1extprice << "\n\n"; // order total
cf2extprice = cf2extprice + cf1extprice; // level two calc
oldordnum = ordnum; // save the control field
} //
cout << endl;
cout << setw(52) << cf2extprice; // print report total
/* close file and stop run */
cout << endl;
infile.close(); // close file
return(0); // int return to o/s
} // end main block
void readinput (void)
{
infile >> ordnum >> partnum >> quantity >> price;
if (infile.eof())
ordnum = 99999;
return;
}
void SetPrecision(int pDecPlaces) // procedure header
{
cout.setf(ios::right); // right-justified
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(pDecPlaces);
return; // return to caller
}