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
|
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
const int invSize = 2;
void getInventory(ifstream& infile, vector<string>& itemID,
vector<string>& itemName, vector<int>& pOrdered,
vector<int>& pInStore, vector<int>& pSold,
vector<double>& manufPrice, vector<double>& sellingPrice);
void printInventory(vector<string>& itemID, vector<string>& itemName,
vector<int>& pOrdered, vector<int>& pInStore,
vector<int>& pSold, vector<double>& manufPrice,
vector<double>& sellingPrice);
int main()
{
vector<int> itemQuantity(invSize);
vector<string> itemID(invSize);
vector<string> itemName(invSize);
vector<int> pOrdered(invSize);
vector<int> pInStore(invSize);
vector<int> pSold(invSize);
vector<double> manufPrice(invSize);
vector<double> sellingPrice(invSize);
ifstream infile("inventory.txt");
if (!infile)
{
perror("File error: ");
system("pause");
return 1;
}
getInventory(infile, itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
printInventory(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
system("pause");
return 0;
}
// itemId, pOrdered, pInStore, pSold, manufPrice, sellingPrice, itemName.
void getInventory(ifstream& infile, vector<string>& itemID,
vector<string>& itemName, vector<int>& pOrdered,
vector<int>& pInStore, vector<int>& pSold,
vector<double>& manufPrice,
vector<double>& sellingPrice)
{
unsigned int i = 0;
string line;
for (i = 0; i < invSize; i++)
{
infile >> itemID[i]
>> pOrdered[i]
>> pInStore[i]
>> pSold[i]
>> manufPrice[i]
>> sellingPrice[i];
getline(infile, itemName[i]);
}
}
void printInventory(vector<string>& itemID, vector<string>& itemName, vector<int>& pOrdered,
vector<int>& pInStore, vector<int>& pSold, vector<double>& manufPrice,
vector<double>& sellingPrice)
{
cout << "Friendly Hardware Store inventory" << endl << endl;
for (int i = 0; i < invSize; i++)
{
cout << "\nItem ID: " << itemID.at(i);
cout << "\nItem name:" << itemName.at(i);
cout << "\nOrdered: " << pOrdered.at(i);
cout << "\nIn store: " << pInStore.at(i);
cout << "\nSold: " << pSold.at(i);
cout << "\nManufactoring price: " << manufPrice.at(i);
cout << "\nSelling price: " << sellingPrice.at(i);
cout << "\n" << string(60, '=') << '\n';
}
}
|