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
|
// Inventory Report.cpp
//
// Purpose: Write a program that
// 1.
// 2.
// 3.
// 4.
//
// Author: Anonymous
// Reference: http://www.cplusplus.com
// Date: 23 July 2011
#include <iostream> // header file for console I/O
#include <iomanip> // header file for stream manipulators
#include <string> // header file used to manipulate and process strings and arrays
#include <fstream> // header file used to read data from a file
#include "Product.h" // header file for class and function declarations
using namespace std; // instructs compiler to use names in standard library
/********************************* main() *******************************/
int main()
{
// Display author name to the right, title of program, and dashes
cout << right;
cout << setw(60) << "Anonymous" << endl;
cout << "Product Inventory Report - Sort by Product" << endl;
cout << setfill ('-') << setw(42) << "-" << endl;
cout << endl << endl; // extra lines (for legability)
// Declaration Section
int arraySize=0;
char *endp;
Product inventory[10];
// Open the file for input
cout << "Products READ FROM FILE" << endl;
cout << setfill ('-') << setw(23) << "-" << endl;
cout << endl << endl; // extra lines (for legability)
ifstream inFile("inventory.csv"); // open file stream for input
if (inFile.fail())
{
cout << "ERROR opening data file." << endl;
return -1;
}
// read the contents of the file into an array of Product objects
while (!inFile.eof())
{
// input Product record data from file
getline(inFile, sku, ',');
getline(inFile, product, ',');
getline(inFile, category, ',');
getline(inFile, unitPrice, ',');
getline(inFile, onHand, ',');
getline(inFile, ReorderLevel, ',');
getline(inFile, ReorderLeadTime);
inventory[arraySize].setProductInfo(sku, product, category,strtod(unitPrice.c_str(),&endp),
atoi(onHand.c_str()), atoi(ReorderLevel.c_str()), atoi(ReorderLeadTime.c_str()));
++arraySize;
}
inFile.close(); //close the file
// Products array header
cout << left << setfill (' ');
cout << setw( 8 ) << "SKU #" << setw( 30 ) << "Product Name" << setw( 12 ) << "Category" << setw( 9 ) << "On Hand" << setw( 12 ) << "Unit Price" << setw( 10 ) << "Inv Value" << setw( 10 ) << endl;
// Display ProductInfo
for (int i=0; i < arraySize; i++)
inventory[i].displayProductInfo();
/*experiemntal > */
cout << endl << endl << endl;
//cout<< product<<endl;
/*< experimental*/
cout << endl << endl << endl; // extra lines (for legability)
// Sort the Products alphabetically based on the Product Name
cout << "Products SORTED BY Product Name" << endl;
cout << setfill ('-') << setw(31) << "-" << endl;
cout << endl << endl; // extra lines (for legability)
// Products array header
cout << left << setfill (' ');
cout << setw( 8 ) << "SKU #" << setw( 30 ) << "Product Name" << setw( 12 ) << "Category" << setw( 9 ) << "On Hand" << setw( 12 ) << "Unit Price" << setw( 10 ) << "Inv Value" << setw( 10 ) << endl;
// Display sorted products
/* Test Output Beginning */
sort(inventory, arraySize);
for (int j=0; j < arraySize; j++)
inventory[j].displayProductInfo();
/* Test Output End*/
cout << endl << endl << endl;
system("pause");
return 0;
}
|