Question
An online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the
An online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the name and the price per unit for two different parts. Then, the customer is allowed to order as many units of each of the two parts as they would like. Lastly, an invoice (report) is generated (displayed to the screen) under the following rules:
All units up to and including the 20th are sold at full price.
All unit in excess of 20 are sold at a 10% discount.
For each part there must be a separate line indicating:
The parts name
The parts full unit price
How many units are being sold at full unit price
The resulting subtotal
And if applicable, another line indicating:
The parts name
The parts discounted unit price
How many units are being sold at discounted unit price
The resulting subtotal
There must be a line indicating the total of the order.
There must be a line indicating the sales tax on the total of the order (based on a 5% sales tax)
There must be a line indicating the grand total of the order.
Finish the following MATLAB function and write a MATLAB Script that (uses that function) to satisfy the above description.
function [ fpUnits, fpSubtotal, disUnits, disSubtotal ] = processPart( unitsSold, unitPrice, discountThr, discount )
%{proccessPart Compute values for each part
%
% INPUT:
% -----
% unitsSold - Total number of units being sold
% unitPrice - Full price of each unit
% discountThr - The number of units that must be exceeded
% before applying discount
% discount - The discount rate to be applied eg (15% -> 0.15)
%
% OUTPUT:
% ------
% fpUnits - How many units being sold at full price
% disUnits - How many units being sold at discounted price
% fpSubtotal - Total cost of full priced units
% disSubtotal - Total cost of discounted priced units
%
%}
% your formulas and logic here
%
end
Outline:
Create a MATLAB Function .m file named processPart.m
Copy the skeleton function given
Finish the function by assigning all of the output variables correctly
Create a MATLAB Script .m file named Program04.m
Write the necessary MATLAB commands to prompt for and read into variables all of the Retailer's and Customer's input data
Call your processPart function to compute the results for the first part
Format and display to the screen, the output report for this part
Call your processPart function to compute the results for the second part
Format and display to the screen, the output report for this part
Format and display to the screen, the total order cost, total order tax and grand-total
Notes(s):
You will need to use (in your script) the
= input(, 's');
version of input to read in and assign the non-evaluated string part names that the user types.
You will need to use (in your script) the
= input();
version of input to read in and assign the Numeric quantities that the user types.
Your function must not display anything to the screen, nor get any user input.
Sample Run(s):
Welcome to the CS240 Online Store
---------------------------------
Retailer ...................
Please enter the name of first Part: Wing Nut
Please enter the price (per unit) of Wing Nuts $1
Please enter the name of second Part: 1/4 Bolt
Please enter the price (per unit) of 1/4 Bolts $2
Consumer .....................
Enter number of units of Wing Nuts to purchase: 20
Enter number of units of 1/4 Bolts to purchase: 30
Order Summary ...
Part Units Price/Unit Cost
----------------------------------------------
Wing Nuts 20 $1.00 $20.00
1/4 Bolts 20 $2.00 $40.00
1/4 Bolts 10 $1.80 $18.00
----------------------------------------------
Total order cost $78.00
Total order tax $3.90
Order Grand-total $81.90
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