Answer the given question with a proper explanation and step-by-step solution. CSCI 251 Section 1 Shopping Cart Problem Statement Design a simple shopping program using while loop and switch statement. Your program should list 3 items (book, bag and phone) and their prices (this part is implemented in the template). Ask the user to choose one item from the list by entering its name and then prompt for the quantity to purchase. If the item is not in the list, output an error message: “XXX is out of stock!”. The item name entered by user should not be case sensitive, i.e., your program should be able to recognize ‘bag, ‘Bag or ‘BAG’, to convert a string to lower case, use lower() function. For each iteration, output a message with newly added item and the total price. For example: 1 x phone added to the cart. Total price:$700 The program keeps running until the user enter ‘check’ when promote for the item name. Output the total price before the program terminates. Input Item name Quantity Output For each iteration, output the changes of the shopping cart and the total price. The total price after entered ‘check’. An error message if the item is not in the list. Hint You can use the function lower() to convert item name to lower cases. The lower() function takes a character array and converts every character to lower case. e.g., lower('Shoes') => 'shoes', lower('SHOES') =>'shoes'. Think about the logic of your program, otherwise it might behave unexpectedly. The output of your program should look exactly like the sample outputs when the same test case is applied. A template is attached at the end of this description, please implement your program on top of this template. clc;clear; name_book='book'; name_bag='bag'; name_phone='phone';   price_book=10; price_bag=50; price_phone=700;   fprintf('%s $%d, %s $%d, %s $%d \n',... name_book,price_book,name_bag,price_bag,name_phone,price_phone);   checkout=false; %Do not change the value of this variable total_price=0;   while ________ % while true   qt=0; % Quantity of item   %1. Prompt the user for an item name, store it as a character array    ____________________________________________________   %2. Convert the item name to lower case with lower() function   ____________________________________________________      if _______________________________%if user enter 'check', fprintf('Check out\n');    %Change the value of flag variable, terminates the while loop ____________________________________    else    switch __________ %item's name entered by user, converted to lower case.   case ________ %item’s name defined in this program: name_*   qt=_______________________ %prompt for quantity    total_price=______________%current total price + quantity * price of %selected item    % you need two more cases for all items    otherwise fprintf('%s is out of stock!\n',________);%item's name end %end of switch fprintf('%d x %s added to the cart. Total price:$%d\n',____,____,____) end %end of if end %end of while   fprintf('Total Price:$%d\n',__________);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

Answer the given question with a proper explanation and step-by-step solution.

CSCI 251 Section 1 Shopping Cart Problem Statement Design a simple shopping program using while loop and switch statement. Your program should list 3 items (book, bag and phone) and their prices (this part is implemented in the template). Ask the user to choose one item from the list by entering its name and then prompt for the quantity to purchase. If the item is not in the list, output an error message: “XXX is out of stock!”. The item name entered by user should not be case sensitive, i.e., your program should be able to recognize ‘bag, ‘Bag or ‘BAG’, to convert a string to lower case, use lower() function. For each iteration, output a message with newly added item and the total price. For example: 1 x phone added to the cart. Total price:$700 The program keeps running until the user enter ‘check’ when promote for the item name. Output the total price before the program terminates. Input Item name Quantity Output For each iteration, output the changes of the shopping cart and the total price. The total price after entered ‘check’. An error message if the item is not in the list. Hint You can use the function lower() to convert item name to lower cases. The lower() function takes a character array and converts every character to lower case. e.g., lower('Shoes') => 'shoes', lower('SHOES') =>'shoes'. Think about the logic of your program, otherwise it might behave unexpectedly. The output of your program should look exactly like the sample outputs when the same test case is applied. A template is attached at the end of this description, please implement your program on top of this template.

clc;clear;

name_book='book';

name_bag='bag';

name_phone='phone';

 

price_book=10;

price_bag=50;

price_phone=700;

 

fprintf('%s $%d, %s $%d, %s $%d \n',...

name_book,price_book,name_bag,price_bag,name_phone,price_phone);

 

checkout=false; %Do not change the value of this variable

total_price=0;

 

while ________ % while true

 

qt=0; % Quantity of item

 

%1. Prompt the user for an item name, store it as a character array

  

____________________________________________________

 

%2. Convert the item name to lower case with lower() function

 

____________________________________________________

 

  

if _______________________________%if user enter 'check',

fprintf('Check out\n');

  

%Change the value of flag variable, terminates the while loop

____________________________________

  

else

  

switch __________ %item's name entered by user, converted to lower case.

 

case ________ %item’s name defined in this program: name_*

 

qt=_______________________ %prompt for quantity

  

total_price=______________%current total price + quantity * price of

%selected item

  

% you need two more cases for all items

  

otherwise

fprintf('%s is out of stock!\n',________);%item's name

end %end of switch

fprintf('%d x %s added to the cart. Total price:$%d\n',____,____,____)

end %end of if

end %end of while

 

fprintf('Total Price:$%d\n',__________);

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operators
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education