#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;
struct Inventory
{
string description;
int quantity;
float wholesale;
float retail;
float balance;
string date;
};
void Menu(void);
void Enter(int index, Inventory *c);
void Change(void);
void Display(int x, int index, Inventory *c);
void Remainder(int index);
void Write(int x, int index, int most, Inventory *c, ofstream &report);
void Clear(void);
void Flush(void);
int main(void)
{
ofstream report;
Inventory item[20];
int index = 0, choice, x = 0, most;
report.open("Report.txt");
cout << " Menu for record #: " << (index+1);
Menu();
cout << "\n \tYour choice: ";
cin >> choice;
while ((choice != 5) && (index <= 20))
{
Clear();
if (choice==1)
{
Enter(index, &item[index]);
Clear();
}
else if (choice==2)
{
most = index;
Change();
cin >> index;
index-=1;
}
else if (choice ==3)
{
Display(x,index,&item[x]);
}
else if (choice ==4)
{
Remainder(index);
index++;
most++;
}
cout << "\n\n\n Menu for record #" << (index+1);
Menu();
cout << "\n \tYour choice: ";
cin >> choice;
}
Write(x,index,most,&item[x], report);
report.close();
cout << "\n\n Thank you for using the program!" << endl;
cout << " Please review Report.txt file for all inventory review" << endl;
Flush();
cout << "\n\n Press any key to end "<< endl;
getchar();
return 0;
}
void Menu(void)
{
cout << "\n Please choose:\n\n"
" \t1) Enter New Record\n"
" \t2) Change Record\n"
" \t3) Display Record\n"
" \t4) Input Next Record\n"
" \t5) Quit\n";
}
void Enter(int index, Inventory *c)
{
Flush();
cout << "\n\nItem Description: ";
getline(cin, c->description);
while (c->description.empty())
{
cout << "Invalid data, try again\n";
cout << "Item Description: ";
cin >> c->description;
}
Flush();
cout << "Quantity on hand: ";
cin >> c->quantity;
while (c->quantity < 0)
{
cout << "Invalid data. Try again\n";
cout << "Quantity on hand: ";
cin >> c->quantity;
}
Flush();
cout << "Wholesale cost: ";
cin >> c->wholesale;
while (c->wholesale < 0)
{
cout << "Invalid data. Try again\n";
cout << "Wholesale cost: ";
cin >> c->wholesale;
}
Flush();
cout << "Retail cost: ";
cin >> c->retail;
while (c->retail < 0)
{
cout << "Invalid data.T try again\n";
cout << "Retail cost: ";
cin >> c->retail;
}
Flush();
cout << "Date added: ";
getline(cin, c->date);
while (c->date.empty())
{
cout << "Invalid. Try again\n";
cout << "Date added: ";
cin >> c->date;
}
cout << "\n\n";
}
void Change(void)
{
cout << "Enter the record number and press 1 to fill out the information\n" << endl;
cout << "Record number: ";
}
void Display(int x, int index, Inventory *c)
{
cout << "Which record would you like to see?" << endl;
cout << "Current record number is: " << (index+1) << "\n\n";
cin >> x;
cout << "\nHere is the data for record #" << x;
x-=1;
cout << "\n\nItem Description: " << c[x].description << endl;
cout << "Quantity on hand: " << c[x].quantity << endl;
cout << "Wholesale cost: " << c[x].wholesale << endl;
cout << "Retail cost: " << c[x].retail << endl;
cout << "Date added to inventory: " << c[x].date << "\n\n" << endl;
}
void Write(int x, int index,int most, Inventory *c, ofstream &report)
{
index = most;
x = index;
report << "\n\n FULL INVENTORY REPORT\n\n" ;
for (index=0; index <= x; index++)
{
report << "\nRecord Number: " << (index+1) << endl;
report << "Item Description: " << c[index].description << endl;
report << "Quantity on hand: " << c[index].quantity << endl;
report << "Wholesale cost: " << c[index].wholesale << endl;
report << "Retail cost: " << c[index].retail << endl;
report << "Date added to inventory: " << c[index].date << endl;
}
}
void Remainder(int index)
{
cout << "Your data is in record #" << (index+1);
}
void Clear(void)
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
void Flush(void)
{
int ch;
do
{
ch = getchar();
}
while (ch != EOF && ch != '\n');
clearerr(stdin);
}