A small market maintains an inventory of exactly 20 items Yo

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.

Solution

//inventory.cpp Source file

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;
struct inventory
{
        string name;
        int cost;
        char tax;
};
int main()
{
        int numstate,i,total_cost;
        int c1=0,c2=0,c3=0;
        int ch;
        struct inventory iy[20];
        ifstream infile;
        ofstream outfile;
        infile.open(\"inventory.txt\");
        outfile.open(\"inventory_output.txt\");      
        for(i=0;i<20;i++)
        {
                infile>>iy[i].name;
                infile>>iy[i].cost>>iy[i].tax;
                infile.ignore(100,\'\ \');
        }      
        outfile<<\"Product Name\\t Cost\ \";
        for(i=0;i<20;i++)
        {
                cout<<i+1<<\".\\t\"<<iy[i].name<<\"\\t\"<<iy[i].cost<<\"\\t\"<<iy[i].tax<<\"\ \";
        }
        cout<<\"0 for quit\ \";
        cin>>ch;
        total_cost=0;
        do{
                outfile<<iy[ch-1].name<<\"\\t\\t\"<<iy[ch-1].cost<<\"\ \";
                total_cost += iy[ch-1].cost;

//                For tax you can multiply the value
//                if(iy[ch-1].tax==\'y\')           
//                total_cost += iy[ch-1].cost*tax_value/100; tax value is the percentage of tax that is not given

                for(i=0;i<20;i++)
                {
                        cout<<i+1<<\".\\t\"<<iy[i].name<<\"\\t\"<<iy[i].cost<<\"\\t\"<<iy[i].tax<<\"\ \";
                }
                cout<<\"0 for quit\ \";
                cin>>ch;
        }while(ch!=0);
        outfile<<\"\ \ Total cost:\\t\"<<total_cost<<\"\ \";      
        infile.close();
        return 0;
}

// inventory.txt Input file

car 155000 y
table 100 n
chair 120 y
plug 12 n
wire 120 y
scooter 110 n
box 1002 n
bed 1345 y
laptop 2302 y
fan 120 n
mobile 1580 y
bottle 450 n
mug 10 y
charger 40 y
towel 10 y
pillow 35 y
board 32 n
racket 56 y
ball 4 n
bat 18 y

// inventory_output.txt

Product Name   Cost
chair       120
box       1002
scooter       110


Total cost:   1232

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 c
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 c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site