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',__________);
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
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
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',__________);

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









