Stock inventory

Stock inventory

Solution 

main.cpp 

#include <stdlib.h>

#include <string>

#include<iostream>

#include<iomanip>

#include<fstream>

using namespace std;

boolenter_inventory_data(ofstream& out)

{

cout<< “Please enter stock number: ” <<endl;

stringstock_number;

getline(cin, stock_number );

 

if (stock_number.empty())

{

return false;

}

cout<< “Please enter description: ” <<endl;

string description;

cin>> description;

double cost = 0;

do

{

cout<< “Please enter cost (between 0.00 and 10000 inclusive): ” <<endl;

cin>> cost;

if (cost == -999.00)

{

return true;

}

}

while (cost < 0 || cost > 10000);

cout<< “Please enter price: ” <<endl;

int price;

cin>> price;

cout<< “Please enter quantity in stock: ” <<endl;

int quantity;

cin>> quantity;

out<<stock_number<<” “<<description<<” “<<cost<<” “<<price<<” “<<quantity<<endl;

getline(cin, stock_number);

if (out.bad())

{

cout<< “Error file writing” <<endl;

return false;

}

return true;

}

int main()

{

ofstream out;

do

{

cout<< “Please enter file name: ” <<endl;

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: ” <<file_name<<endl;

}

} while (!out.is_open());

while (enter_inventory_data(out))

{}

out.close();

return 0;

}