(3) Write another function named ReadGroceryList that reads the information from grocery.txt and displays the information on the screen like Item Cost Apple $4.5 Banana $1.20

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
USE THIS WRITTEN CODE AND ANSWER THE QUESTION USING DEV C++
obals)
main.cpp
sinclude ciostream
sinclude <string
sinclude cfstream>
using namespace std;
/create the function ReadGrocerylist to read the file
/pass the name of the fiLe
void ReadGroceryList (string fileiame)
//create the ifstrear object
ifstrean myfile("fileNane");
//create string Line
string line;
//create string itemvane and itemvalue
string itemval;
cout "Item"e«"Cost"<<end];
11
12
13
14
15
16
17
18
**E* end)
cout c
«endl;
19
******* end];
Cout c "EEEII
while (getline (myfile, line)
//set the pointer at the doLlar symbol in the Line
size_t dollar = line.find ("$");
/The value before dollar is item nae
line. substr (e);
/The volue after the dollar is item value
itemval = line .substr (e,line. length ());
/Print the accordiny
cout <«"itemName"<«
20
21
22
23
24
25
26
27
28
"itemvalk«""cendl;
29
30
31
myfile.close ();
32
33
int mair () {
ofstream objs
int choice;
float price;
string itemtiame;
//set the iso base to append. Now rire will alays odd at the end of List without delering the previsus tist
obj.oper ("grocery.txt, iso_base:: app");
34
35
36
37
38
39
40
41
cout « "1. Enter Groceries \n2.Show Groceries\n3. Exit\n"ccendl;
cout <«"Enter your choice:"ccendl;
cir>choice ;
while (choice«a)
42
43
44
45
46
47
cout e"Enter grocery Item Name:"<<end);
cir>»itemliame;
cout « "Enter Grocery" ccitenliame ce"Cost:"ccendl;
cir>»price;
objuitemliame c"$"c«price ccend];
48
49
50
51
52
if (choice =2)
53
54 -
//coll the function grocery List to dispLay on screen
ReadGroceryList ("grocery.txt");
55
56
57
cout "1. Enter Groceries In2.show Groceries\n3. Exit\n
cout "Enter your choice:";
cir»choice ;
58
59
60
61
62
obj.close ();
63
64
return es
65
66
Transcribed Image Text:obals) main.cpp sinclude ciostream sinclude <string sinclude cfstream> using namespace std; /create the function ReadGrocerylist to read the file /pass the name of the fiLe void ReadGroceryList (string fileiame) //create the ifstrear object ifstrean myfile("fileNane"); //create string Line string line; //create string itemvane and itemvalue string itemval; cout "Item"e«"Cost"<<end]; 11 12 13 14 15 16 17 18 **E* end) cout c «endl; 19 ******* end]; Cout c "EEEII while (getline (myfile, line) //set the pointer at the doLlar symbol in the Line size_t dollar = line.find ("$"); /The value before dollar is item nae line. substr (e); /The volue after the dollar is item value itemval = line .substr (e,line. length ()); /Print the accordiny cout <«"itemName"<« 20 21 22 23 24 25 26 27 28 "itemvalk«""cendl; 29 30 31 myfile.close (); 32 33 int mair () { ofstream objs int choice; float price; string itemtiame; //set the iso base to append. Now rire will alays odd at the end of List without delering the previsus tist obj.oper ("grocery.txt, iso_base:: app"); 34 35 36 37 38 39 40 41 cout « "1. Enter Groceries \n2.Show Groceries\n3. Exit\n"ccendl; cout <«"Enter your choice:"ccendl; cir>choice ; while (choice«a) 42 43 44 45 46 47 cout e"Enter grocery Item Name:"<<end); cir>»itemliame; cout « "Enter Grocery" ccitenliame ce"Cost:"ccendl; cir>»price; objuitemliame c"$"c«price ccend]; 48 49 50 51 52 if (choice =2) 53 54 - //coll the function grocery List to dispLay on screen ReadGroceryList ("grocery.txt"); 55 56 57 cout "1. Enter Groceries In2.show Groceries\n3. Exit\n cout "Enter your choice:"; cir»choice ; 58 59 60 61 62 obj.close (); 63 64 return es 65 66
(3) Write another function named ReadGroceryList that
reads the information from grocery.txt and displays the
information on the screen like
Item
Cost
Apple $4.5
Banana $1.20
(4) Your program must include your information and
algorithm as specified in class
Transcribed Image Text:(3) Write another function named ReadGroceryList that reads the information from grocery.txt and displays the information on the screen like Item Cost Apple $4.5 Banana $1.20 (4) Your program must include your information and algorithm as specified in class
Expert Solution
steps

Step by step

Solved in 2 steps with 1 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