Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A retail store has five bins, numbered 1 to 5, each containing a different commo

ID: 3553091 • Letter: A

Question

A retail store has five bins, numbered 1 to 5, each containing a different commodity. At the beginning of a particular day, each bin contains 50 items. The table below shows the cost per item for each of the bins, and the quantity sold during that day.

Write a program to

(a) -read sales data from a file (cis14l6.txt)

(b) -Place the cost per item and the quantity sold for each bin into an array of structures;

(c) -Display a table giving the inventory at the end of the day and the amount of revenue obtained from each bin;

(d) -Compute the total revenue for the day;

(e) -List the number of each bin that contains fewer than 25 items at the end of the day.

(f) -Sort the list from least sold to most sold, and output that result.

Format of cis14l6.txt:

1                             13.00                                    20

2                             2.25                                       35

3                             7.45                                       19

4                             17.49                                    42

5                             34.95                                    17

Column 1 is the bin number, column two is the price, and column 3 is number sold for the day.



I mainly need help with Part (A) and Part (F)... Thank you

Explanation / Answer

Input: file cis1416.txt


1                             13.00                                    20
2                             2.25                                       35
3                             7.45                                       19
4                             17.49                                    42
5                             34.95                                    17


_____________________________________________________________________________________________


Code:


#include<iostream>
#include<fstream>
#include<conio.h>
#include<iomanip>
#include<cmath>
#include<algorithm>

// Associating program identifiers with external file names
#define in_file "cis1416.txt"//input file name
#define out_file "output.txt"//output file name

using namespace std;
void inventory();
void lessthan();
void sorted_list();

ifstream ins;// associates ins as an input stream
ofstream outs;// associates outs as an output stream
const int size=5;
int bin[size]={0};
float cost[size]={0.0};
int items_sold[size]={0};
float revenue[size]={0.0};
int remaining[size];

void inventory()
{
    ins.open(in_file);
    int temp;
    float total=0.0;
    outs<<"Inventory Details"<<endl;
    outs<<"bin_NUMBER cost_per_item items_sold Revenue"<<endl;
    int i=0;
    while(true)
    {
        ins>>bin[i]>>cost[i]>>items_sold[i];
        if( ins.eof() ) break;
        revenue[i]=cost[i]*items_sold[i];
        total+=revenue[i];
        outs<<fixed<<showpoint;
        outs<<setprecision(2);
        if((bin[i]>0)&&(bin[i]<21) && items_sold[i]>=0)
        {
            outs<<setw(2)<<bin[i]<<" "<<setw(2)<<cost[i]<<" "<<setw(7)<<items_sold[i]<<" "<<setw(7)<<revenue[i]<<endl;
        }
        i++;
    }
    outs<<endl;
    outs<<"Total revenue for the day is: "<<total<<endl;
    outs<<endl;
    ins.clear();
    ins.close();
}

void lessthan()
{
    ins.open(in_file);
    int temp;
    outs<<"bins having less than 25 items at the end of day"<<endl;
    outs<<"bin remaining"<<endl;
    int i=0;
    while(true)
    {
        ins>>bin[i]>>cost[i]>>items_sold[i];
        if( ins.eof() ) break;
        remaining[i]=50-items_sold[i];
        outs<<fixed<<showpoint;
        outs<<setprecision(2);
        if(remaining[i]<25)
        {
            outs<<setw(2)<<bin[i]<<" "<<remaining[i]<<endl;
        }
        i++;
    }
    outs<<endl;
    ins.clear();
    ins.close();
}

void sorted_list()
{
    ins.open(in_file);
    int temp;
    outs<<"Inventory Details sorted from least to most items sold"<<endl;
    outs<<"bin_NUMBER cost_per_item items_sold Revenue"<<endl;
    int i=0;
    int sort_list[size]={0};
    while(true)
    {
        ins>>bin[i]>>cost[i]>>items_sold[i];
        if( ins.eof() ) break;
        revenue[i]=cost[i]*items_sold[i];
        i++;
    }
    for(int i=0;i<5;i++){
        sort_list[i]=items_sold[i];
    }
    sort(sort_list,sort_list+5);
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            outs<<fixed<<showpoint;
            outs<<setprecision(2);
            if(sort_list[i]==items_sold[j]){
                outs<<setw(2)<<bin[j]<<" "<<setw(2)<<cost[j]<<" "<<setw(7)<<items_sold[j]<<" "<<setw(7)<<revenue[j]<<endl;
                break;
            }
        }
    }
    outs<<endl;
    ins.clear();
    ins.close();
}

int main()
{
    outs.open(out_file);
    inventory();
    lessthan();
    sorted_list();
    //ins.clear();
    //ins.close();
    outs.close();
    return 0;
}


__________________________________________________________________________________________


Output: file output.txt


Inventory Details
bin_NUMBER cost_per_item items_sold Revenue
1 13.00      20 260.00
2 2.25      35   78.75
3 7.45      19 141.55
4 17.49      42 734.58
5 34.95      17 594.15

Total revenue for the day is: 1809.03

bins having less than 25 items at the end of day
bin remaining
2 15
4 8

Inventory Details sorted from least to most items sold
bin_NUMBER cost_per_item items_sold Revenue
5 34.95      17 594.15
3 7.45      19 141.55
1 13.00      20 260.00
2 2.25      35   78.75
4 17.49      42 734.58


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote