Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write, compile, debug, and run a program that will use the specified loops to do the following This program will ask the user for items
Write, compile, debug, and run a program that will use the specified loops to do the following This program will ask the user for items to buy and their quantities, and write a shopping list to a file. The program does all of the following during one run: Open a file named "shopping.txt" for write access Use a do while loop to get the items from the user and write them to the file: o Prompt the user for an item to place on the shopping list (i.e. apples) Prompt for the quantity of that item, using the name of the item in the prompt o For example, if the user entered "apples", prompt "How many apples?" (don't worry about grammar and plurals.) Write each item and its quantity to the file, item first, quantity second .e. apples 5) with only spaces between each write, nothing else (no punctuation, no endl, no In) Ask the user if they want to keep entering items Loop until the user enters N or n to this question (loop should only end if they enter N or n.) (This is the do while loop condition.) o o o . Close the file . Open the same file for read acces:s . Use a while loop to read the file and display: Read each item and quantity from the file, individually, into separate variables Display the shopping list to the screen, with each quantity and item ona new line (after a heading line) Read individual item and quantity values from the file using the >> operator. Do not read whole lines. Do not use any other method to read from the file (i.e. don't use getline, rdbuf, or any way other than what is used in your textbook chapter 5.) o o o o The while loop should read until it reaches the end of the file. (it should not loop a certain number of times - don't count how many writes the earlier loop did and then do the same number of reads.) . Close the file Your output should look similar to this: Here is your shopping list for today: 5 apples 1 bread 2 milk
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started