minimart c++ programming A small market maintains an inventory of exactly 20 ite
ID: 3776152 • Letter: M
Question
minimart
c++ programming
A small market maintains an inventory of exactly 20 items. You will read these items from a file. Each item named will have an associated cost and a character code to indicate whether or not it is taxable. You will place your online order. A file will contain your "printed" receipt with the total amount of your order. Project Specifications Input for this project has two sources. The inventory of exactly 20 items (with cost and tax code for each) is read from an input file. The user must enter: the names of the input and output files, and the items to purchase (by the number code associated with each item.) Output also has two sources. The command line shows the names of the inventory items, the echo of the chosen item with its price and "taxable" if appropriate. The amount of the tax and the total amount due will appear on the command line screen when the user is finished. The tax rate is 7% (use .07 in your code.) The "printed" receipt will be on the output file. All the non-taxable items should be listed first followed by the taxable items, then the total amount of the tax, and last the total amount due.
Explanation / Answer
#include <iostream>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <vector>
#include "product.h"
using namespace std;
Product inv[20];
int c = 20;
int menu(void)
{
int option;
cout << "Enter 1 to begin checkout or 0 to exit" << endl;
cin >> option;
return option;
};
void updateFile()
{
ofstream newInvFile("newinventory.txt");
for (int p = 0; p < c; p++)
{
newInvFile << inv[p].getPLU() << " " << inv[p].getProductName() << " " << inv[p].getType() << " " << inv[p].getPrice() << " " << inv[p].getInventory() << endl;
}
}
void checkout(void)
{
double total = 0;
double quantity;
int input;
int PLU = 0;
do
{
PLU = 0;
cout << "Enter PLU code or (0) to exit" << endl;
cin >> input;
if (input == 0)
break;
for (int p = 0; p < c; p++)
{
if (inv[p].getPLU() == input)
{
PLU = p;
break;
}
}
if (inv[PLU].getType() == 1)
{
cout << "Weight: ";
}
else
{
cout << "Quantity: ";
}
cin >> quantity;
total += quantity * inv[PLU].getPrice();
inv[PLU].updateInventory(quantity);
}
while (input != 0);
cout << "Total: $" << total << endl;
if (total > 20)
{
total = total * 0.7;
cout << "Your purchase of over $20 qualifies you for a 7% discount. Total: $" << total << endl;
}
}
int main()
{
int plu;
string productName;
int type;
double price;
double inventory;
c = 0;
ifstream original ("inventory.txt");
if (original.is_open())
{
while (!original.eof())
{
original >> plu >> productName >> type >> price >> inventory;
Product temp = Product(plu, productName, type, price, inventory);
inv[c] = temp;
c++;
}
original.close();
}
int option;
do
{
cout << "WELCOME!" << endl;
option = menu();
if (option == 1)
checkout();
else
updateFile();
}
while(option != 0);
system ("pause");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.