Stock inventory
Solution
main.cpp
#include
#include
#include
#include
#include
using namespace std;
boolenter_inventory_data(ofstream& out)
{
cout<< “Please enter stock number: ” <
stringstock_number;
getline(cin, stock_number );
if (stock_number.empty())
{
return false;
}
cout<< “Please enter description: ” <
string description;
cin>> description;
double cost = 0;
do
{
cout<< “Please enter cost (between 0.00 and 10000 inclusive): ” <
cin>> cost;
if (cost == -999.00)
{
return true;
}
}
while (cost < 0 || cost > 10000);
cout<< “Please enter price: ” <
int price;
cin>> price;
cout<< “Please enter quantity in stock: ” <
int quantity;
cin>> quantity;
out<
getline(cin, stock_number);
if (out.bad())
{
cout<< “Error file writing” <
return false;
}
return true;
}
int main()
{
ofstream out;
do
{
cout<< “Please enter file name: ” <
stringfile_name;
getline(cin, file_name);
if (file_name.empty())
{
file_name = “stock.dat”;
}
if (file_name.find(‘.’) == string::npos)
{
file_name += “.dat”;
}
out.open(file_name);
if (!out.is_open())
{
cout<< “Can’t open file: ” <
}
} while (!out.is_open());
while (enter_inventory_data(out))
{}
out.close();
return 0;
}