enter image description here
I've been trying to figure out the problem with this program for quite some time now and I've searched on google how to tackle this problem but in vain.
So this is a fairly easy program as you can see. The problem is when i'm trying to output the product from my file.
The cashier enters the barcode and when the barcode matches with the one in the stock.txt file it displays the product as in a purchase list.
Could someone help me resolve this problem?
class stock
{
protected:
int barcode;
string itemname;
int stock_qty;
int reorder_level;
double buying_price;
double selling_price;
double percent_vat;
public:
stock();
stock(int bar, string item, int sqty, int Rlevel, double bp, double sp, double vat);
int getBarcode();
void setBarcode(int bar);
string getItemname();
void setItemname(string item);
int getStock_qty();
void setStock_qty(int sqty);
int getReorder_level();
void setReorder_level(int Rlevel);
double getBuying_price();
void setBuying_price(double bp);
double getSelling_price();
void setSelling_price(double sp);
double getPercen_Vat();
void setPercen_Vat(double vat);
~stock();
};
class stockOperator:public stock
{
public:
void add_item()
{
cout<<"\nEnter The Barcode Of The Item: ";
cin>>barcode;
cout<<"\nEnter The Name of The Item: ";
cin>>itemname;
cout<<"\nEnter The Quantity of the Item Received: ";
cin>>stock_qty;
cout << "\nEnter The Selling Price of The Item: ";
cin >> selling_price;
cout << "\nEnter The Vat on the Item(%): ";
cin >> percent_vat;
}
};
//global declaration for stream object, object
stockOperator opt;
fstream file;
void write_item()
{
file.open("stock.txt", ios::out | ios::app);
opt.add_item();
file.write((char*)&opt, sizeof(stockOperator));
file.close();
cout << "\n\nThe Item Has Been added";
getch();
}
void place_order()
{
int order_arr[50], quan[50], c = 0;
float TotalExcluVat,TotalVat;
char ch = 'Y';
do
{
cout << "\n\nEnter The Barcode Of The Product : ";
cin >> order_arr[c];
cout << "\nQuantity in number : ";
cin >> quan[c];
c++;
cout << "\nDo You Want To Order Another Product ? (y/n)";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
cout << "\n\nThank You For Placing The Order";
getch();
cout << "\n\n******************************** INVOICE ************************\n";
cout << "\nItemName\t ItemQty\t ItemPriceVatExclu\t ItemPriceVatInclu\t TotalExcluVat\t TotalVat\ n ";
for (int x = 0; x <= c; x++)
{
file.open("stock.txt", ios:: in );
file.read((char*)&opt, sizeof(stockOperator));
while (!file.eof())
{
if (opt.getBarcode() == order_arr[x])
{
TotalExcluVat = opt.getBuying_price()*quan[x];
TotalVat = opt.getSelling_price()*quan[x];
cout << "\n" << opt.getItemname() << "\t" << quan[x] << "\t\t" << opt.getBuying_price() << "\t" << opt.getSelling_price() << "\t" << TotalExcluVat << "\t" << TotalVat << "\n";
}
file.read((char*)&opt, sizeof(stockOperator));
}
file.close();
}
getch();
}
int main()
{
int choice;
cout<<"Welcome to ---------- supermarket\n";
cout<<"select: ";
cout<<"1) Cashier\n";
cout<<"2) Stock Operator\n";
cin>>choice;
switch(choice)
{
case 1:
place_order();
break;
case 2:
write_item();
break;
}
}