I have the basis of a program that works as an inventory, it reads the contents of a file and displays them and their quantity in three places, listed below are the things that I need to add to the program below. I've included a photo of how the program currently runs.   1) Convert your structure into a class. For this exercise, you can leave the data as public (otherwise you would have to change the input and output functions). 2) Write a member function show_all that prints all the information for one record - name, cost, markup, and the three inventory numbers. 3) Add a user option S that lets the user see all the information for all the items in the inventory, using the show_all member function. Print a header so the user knows what each column means, and format the output to appear in columns.   Hint: do a setwidth() before *each* cout. Pick widths that make sense for name, cost, markup, and the three inventory numbers. Contents of the file: Contents of Inventory.txt Red delicious apples 1.00 25 6 8 10 Assorted bouquets 4.00 50 10 10 0 Camembert cheese 2.00 25 10 12 4 END The Program: //inventory menu gives placement, warning, and exit option #include #include #include using namespace std; struct Record { string name; double cost; int markup; int count[3]; }; const string places[3] = {"counter", "shelf", "warehouse"}; bool read_file(vector &v); void placement (vector &v); void warning(vector &v); int main() {  vector invent;  char choice;  if (read_file(invent) == false) {   return 1;  }  cout << "You have " << invent.size() << endl;  while (true)  {   cout << "(P)lacement (W)Warning (E)xit: ";   cin >> choice;   switch(choice) {    case 'P':    case 'p':     placement(invent);     break;    case 'W':    case 'w':     warning(invent);     break;    case 'E':    case 'e':     return(0);     break;    default:    cout << choice << " is not a choice\n";   }  }  return 0; } void placement (vector &v) { int which = -1; string input; cout << "Which? "; cin >> input; for (int i = 0; i < 3; i++) { if (input.substr(0,3) == places[i].substr(0,3)) which = i; } if (which == -1) { cout << "No match\n"; return; } cout.setf(ios::left); cout.unsetf (ios::right); cout.width(30); cout << "Item"; cout.setf(ios::right); cout.width(6); cout << places[which] << "\n"; int j; for (j = 0; j < v.size(); j++) { cout.setf(ios::left); cout.unsetf (ios::right); cout.width(30); cout << v[j].name; cout.setf(ios::right); cout.width(6); cout << v[j].count[which] << endl; } } void warning(vector &v){  for(int i=0;i &v) { Record r; ifstream infile; infile.open("inventory.txt"); if (infile.fail()) { cout << "can't open file\n"; return (false); } while (true) { getline (infile, r.name); cout << "Read " << r.name << endl; if (r.name == "END") { infile.close(); return true; } else { infile >> r.cost >> r.markup; for (int i = 0; i < 3; i++) infile >> r.count[i]; infile.get(); v.push_back(r); } } return true; }

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter19: Probabilistic Dynamic Programming
Section19.4: Further Examples Of Probabilistic Dynamic Programming Formulations
Problem 7P
icon
Related questions
Question
100%
I have the basis of a program that works as an inventory, it reads the contents of a file and displays them and their quantity in three places, listed below are the things that I need to add to the program below. I've included a photo of how the program currently runs.
 
1) Convert your structure into a class. For this exercise, you can leave the data as public (otherwise you would have to change the input and output functions).
2) Write a member function show_all that prints all the information for one record - name, cost, markup, and the three inventory numbers.
3) Add a user option S that lets the user see all the information for all the items in the inventory, using the show_all member function.
Print a header so the user knows what each column means, and format the output to appear in columns.
 
Hint: do a setwidth() before *each* cout. Pick widths that make sense for name, cost, markup, and the three inventory numbers.

Contents of the file:

Contents of Inventory.txt

Red delicious apples
1.00 25 6 8 10
Assorted bouquets
4.00 50 10 10 0
Camembert cheese
2.00 25 10 12 4
END

The Program:

//inventory menu gives placement, warning, and exit option
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

struct Record {
string name;
double cost;
int markup;
int count[3];
};

const string places[3] = {"counter", "shelf", "warehouse"};

bool read_file(vector <Record> &v);
void placement (vector <Record> &v);
void warning(vector <Record> &v);

int main()
{
 vector <Record> invent;
 char choice;

 if (read_file(invent) == false) {
  return 1;
 }
 cout << "You have " << invent.size() << endl;
 while (true)
 {
  cout << "(P)lacement (W)Warning (E)xit: ";
  cin >> choice;
  switch(choice) {
   case 'P':
   case 'p':
    placement(invent);
    break;
   case 'W':
   case 'w':
    warning(invent);
    break;
   case 'E':
   case 'e':
    return(0);
    break;

   default:
   cout << choice << " is not a choice\n";
  }
 }

 return 0;
}

void placement (vector <Record> &v)
{
int which = -1;
string input;

cout << "Which? ";
cin >> input;

for (int i = 0; i < 3; i++) {
if (input.substr(0,3) == places[i].substr(0,3)) which = i;
}
if (which == -1) {
cout << "No match\n";


return;
}

cout.setf(ios::left);
cout.unsetf (ios::right);
cout.width(30);
cout << "Item";
cout.setf(ios::right);
cout.width(6);
cout << places[which] << "\n";

int j;
for (j = 0; j < v.size(); j++) {

cout.setf(ios::left);
cout.unsetf (ios::right);
cout.width(30);
cout << v[j].name;
cout.setf(ios::right);
cout.width(6);
cout << v[j].count[which] << endl;

}
}

void warning(vector <Record> &v){
 for(int i=0;i<v.size();i++){
  for(int j=0;j<3;j++){
   if(v[i].count[j]<10){
    cout<<"Warning:  "<<v[i].name<<" "<<places[j]<<" "<<v[i].count[j]<<endl;
   }
  }
 }
}

bool read_file(vector <Record> &v)
{
Record r;
ifstream infile;

infile.open("inventory.txt");
if (infile.fail()) {
cout << "can't open file\n";
return (false);
}
while (true) {
getline (infile, r.name);
cout << "Read " << r.name << endl;
if (r.name == "END") {
infile.close();
return true;
}

else {
infile >> r.cost >> r.markup;
for (int i = 0; i < 3; i++) infile >> r.count[i];
infile.get();

v.push_back(r);
}
}
return true;
}

1S ./labll
Read Red delicious apples
Read Assorted bouguets
Read Camembert cheese
Read END
You have 3
(P) lacement (W) arning (E)xit: p
Which? counter
Item
counter
Red delicious apples
6
Assorted bouquets
10
Camembert cheese
10
(P) lacement (W) arning (E) xit: p
Which? shelf
Item
shelf
Red delicious apples
Assorted bouquets
8
10
Camembert cheese
12
(P) lacement (W) arning (E) xit: p
Which? warehouse
Item
warehouse
Red delicious apples
10
Assorted bouquets
Camembert cheese
4
(P) lacement (W) arning (E) xit: w
Warning:
Red delicious apples counter 6
Warning:
Red delicious apples shelf 8
Warning:
Assorted bouquets warehouse 0
Warning:
Camembert cheese warehouse 4
(P) lacement (W) arning (E)xit: e
Transcribed Image Text:1S ./labll Read Red delicious apples Read Assorted bouguets Read Camembert cheese Read END You have 3 (P) lacement (W) arning (E)xit: p Which? counter Item counter Red delicious apples 6 Assorted bouquets 10 Camembert cheese 10 (P) lacement (W) arning (E) xit: p Which? shelf Item shelf Red delicious apples Assorted bouquets 8 10 Camembert cheese 12 (P) lacement (W) arning (E) xit: p Which? warehouse Item warehouse Red delicious apples 10 Assorted bouquets Camembert cheese 4 (P) lacement (W) arning (E) xit: w Warning: Red delicious apples counter 6 Warning: Red delicious apples shelf 8 Warning: Assorted bouquets warehouse 0 Warning: Camembert cheese warehouse 4 (P) lacement (W) arning (E)xit: e
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole