Write in C++. The Bite-a Vite-a vitamin store needs an \"expert\" computer progr
ID: 3773362 • Letter: W
Question
Write in C++.
The Bite-a Vite-a vitamin store needs an "expert" computer programmer to help keep track of their inventory. The store maintains all their vitamin stock information on disk. The data is organized as follows:
The first column contains the vitamin name (A, B, C, etc.)
The second column contains the unit price of a single jar of that particular vitamin.
The third column has the number of jars of that vitamin in the store.
For example:
Write a C++ program that will do the following:
1. Read data from the keyboard in the form
vitamin price quantity
2. Write and call a function that will return the total value of the store's inventory for that one vitamin product (unit_price * number_of_jars).
You will also calculate:
The average price of a vitamin
The total inventory (total number of jars)
Print the output so that it is organized as follows:
Vitamin Price Inventory Total Inventory
5. Write and call a function that will return the per unit price of a vitamin. The parameter to the function will include the vitamin name. (Hint use a vector or other container class).
--------------------------------------------------
The average price for a vitamin is: $9.98
The total store inventory is 104 jars of vitamins
A 12.95 23 K 9.99 56 Z 6.99 25Explanation / Answer
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
double input (double, int);
using namespace std;
int
main()
{
float rate;
int frame;
int sum = 0, totalJars = 0;
float totalViteRate = 0;
ofstream outfile;
char vitmins;
ifstream infile;
infile.open("Totalinventory.txt");
if(infile.fail())
{
cerr << "file failed to open";
abort();
}
outfile.open("output.txt");
outfile << "Vitamin Price Inventory Total sumory " << endl;
outfile << "====================================================" << endl;
outfile << setprecision(2) << setiosflags (ios::fixed);
while (!infile.eof())
{
infile >> vitmins >> rate >> frame;
outfile << vitmins << setw(15) << rate << setw(15)
<< frame << setw(15) << input (rate, frame)<< endl;
sum ++;
totalJars += frame;
totalViteRate += rate;
}
outfile << " The average rate for a vitamin is : " << totalViteRate / sum << endl;
outfile << " The total store inventory is " << totalJars << " jars of vitamins" << endl;
infile.close();
outfile.close();
return 0;
}
double input (double t, int j)
{
return t * j;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.