This lab is to to add another option for the user to print warnings of any inventory running low. More specifically: - Add another option to the menu, called W for Warning - Look at all items, in all locations. If an item has less than 10 left, print out on one line the item name, location, and quantity.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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, and I need to add in a warning option that will alert that in any of the places the amount of product is below 10.

Lab = This lab is to to add another option for the user to print warnings of any inventory running low. More specifically:
- Add another option to the menu, called W for Warning
- Look at all items, in all locations. If an item has less than 10 left, print out on one line the item name,
location, and quantity.

Pictures included are:

1. How the program currently runs 

2. How the program needs to run, with included warning option (My program needs to match this photo)

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);

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 (E)xit: ";
cin >> choice;
switch(choice) {
case 'P':
case 'p':
placement(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;

}
}

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;
}

ris:-]$ ./labll
Read Red delicious apples
Read Assorted bouquets
Read Camembert cheese
Read END
You have 3
(P) lacement (E)xit: p
Which? shelf
Item
shelf
Red delicious apples
Assorted bouquets
8
10
Camembert cheese
12
(P) lacement (E)xit: p
Which? counter
Item
Red delicious apples
Assorted bouquets
counter
6
10
Camembert cheese
10
(P) lacement (E) xit: p
Which? warehouse
Item
Red delicious apples
Assorted bouquets
warehouse
10
Camembert cheese
4
(P) lacement (E) xit: e
Transcribed Image Text:ris:-]$ ./labll Read Red delicious apples Read Assorted bouquets Read Camembert cheese Read END You have 3 (P) lacement (E)xit: p Which? shelf Item shelf Red delicious apples Assorted bouquets 8 10 Camembert cheese 12 (P) lacement (E)xit: p Which? counter Item Red delicious apples Assorted bouquets counter 6 10 Camembert cheese 10 (P) lacement (E) xit: p Which? warehouse Item Red delicious apples Assorted bouquets warehouse 10 Camembert cheese 4 (P) lacement (E) xit: e
Read Red delicious apples
Read Assorted bouquets
Read Camembert cheese
Read END
You have 3
(P)lacement (W) arning e (X) it: 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 (X)it:
Transcribed Image Text:Read Red delicious apples Read Assorted bouquets Read Camembert cheese Read END You have 3 (P)lacement (W) arning e (X) it: 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 (X)it:
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY