Topics: User Defined Functions and MATLAB Conditionals
A 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 candies. Then, the customer is allowed to order as many units of each of the two candies 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 candy there must be a separate line indicating:
The candy's name
The candy's full unit price
How many units are being sold at full unit price
The resulting subtotal
And if applicable, another line indicating:
The candy's name
The candy's 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 ] = proccessCandy( unitsSold, unitPrice, discountThr, discount )
%proccessCandy Compute values for each candy
%{
INPUT:
-----
unitsSold - Total number of candy 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:
1.) Create a MATLAB Function .m file – named processCandy.m
2.) Copy the skeleton function given
3.) Finish the function by assigning all of the output variables correctly
4.) Create a MATLAB Script .m file – named Program04.m
5.) Write the necessary MATLAB commands to prompt for and read into variables all of the Retailer's and Customer's input data
6.) Call your processCandy function to compute the results for the first candy
7.) Format and display to the screen, the output report for this candy
8.) Call your processCandy function to compute the results for the second candy
9.) Format and display to the screen, the output report for this candy
10.) 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 Candy 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 Candy: Snickers
Please enter the price (per unit) of Snickers $1
Please enter the name of second Candy: Mike-N-Ikes
Please enter the price (per unit) of Mike-N-Ikes $2
Consumer .....................
Enter number of units of Snickers to purchase: 30
Enter number of units of Mike-N-Ikes to purchase: 20
Order Summary ...
Candy Units Price/Unit Cost
----------------------------------------------
Snickers 20 $1.00 $20.00
Mike-N-Ikes 20 $2.00 $40.00
Mike-N-Ikes 10 $1.80 $18.00
----------------------------------------------
Total order cost $78.00
Total order tax $3.90
Order Grand-total $81.90
***For only two candies, but the program can work for multiple candies***
% Function to caculate subtotal, for each candy
function [fpUnits, fpSubtotal, disUnits, disSubtotal] = proccessCandy(unitsSold, unitPrice, discountThr, discount)
disUnits = 0;
fbSubtotal = 0.0;
disSubtotal = 0.0;
fpUnits = unitsSold;
if (unitsSold > discountThr)
disUnits = unitsSold -
discountThr;
fpUnits =
discountThr;
end
fpSubtotal = (fpUnits * unitPrice);
discountedPrice = unitPrice - (unitPrice *
discount);
disSubtotal = (disUnits *
discountedPrice);
end
% Candie one information
candieOneName = input('Please enter the name of first Candy: ',
's');
fprintf('Please enter the price (per unit) of %s : ',
candieOneName);
candieOneCost = input('');
% Candie two information
candieTwoName = input('Please enter the name of second Candy: ',
's');
fprintf('Please enter the price (per unit) of %s : ',
candieTwoName);
candieTwoCost = input('');
% discountThr = input('Enter discount threshold units :
','d');
% discount = input('Enter discount % (eg., 10% -> 0.10 ):
','d');
% Customer sales
fprintf('Enter number of units of %s to purchase : ',
candieOneName);
candieOneUnits = input('');
fprintf('Enter number of units of %s to purchase : ',
candieTwoName);
candieTwoUnits = input('');
% Computing required total values
[fpUnits1, fpSubtotal1, disUnits1, disSubtotal1] =
proccessCandy(candieOneUnits, candieOneCost, 20, 0.10);
[fpUnits2, fpSubtotal2, disUnits2, disSubtotal2] =
proccessCandy(candieTwoUnits, candieTwoCost, 20, 0.10);
subTotal = (fpSubtotal1 + disSubtotal1) + (fpSubtotal2 +
disSubtotal2);
taxes = subTotal * 0.05;
grandTotal = subTotal + taxes;
fprintf('\n----------------------------------------------------------------\n');
fprintf('%-15s %-10s %-12s %-10s\n', 'Candy', 'Units',
'Price/Unit', 'Cost');
fprintf('%-15s %-10d %-12d %-10d\n', candieOneName, candieOneUnits,
candieOneCost, fpSubtotal1 + disSubtotal1);
fprintf('%-15s %-10d %-12d %-10d\n', candieTwoName, candieTwoUnits,
candieTwoCost, fpSubtotal2 + disSubtotal2);
fprintf('----------------------------------------------------------------\n');
fprintf('%-15s=\t%d\n%-15s=\t%d\n%-15s=\t%d\n', 'subTotal',
subTotal, 'Taxes', taxes, 'Grand Total',grandTotal);
Topics: User Defined Functions and MATLAB Conditionals A online retailer has hired you to write a...
Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows: Product 1 1...
can someone solve these quick please and thank you! sql chapter 4 Query #1: List the company name, contact name, contact title and the phone number for customers who HAVE NOT put in an order. Use an outer join. Query #2: Create a listing displaying the employee first name, last name and the full name (First name space Last Name) of the person they report to (Supervisor). This is a self-join. If an employee does not report to anyone then...
**This is for the C Language. Trigonometric Calculator Specification You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification. 1. When the program is run, it is to display a short welcome message. TRIG: the trigonometric calculator 2. The program shall display a message prompting the user to enter input from the keyboard. Please input request (h-help,...
SOLVE USING C!!! Project objective: Conditional statements, loops, reading from file, user defined functions. **Submit source code (LargeProg1.c) through Canvas One source code file(unformatted text) will be submitted Here is INCOMPLETE code to get started: LargeProg1.c The file name must match the assignment The code should be tested and run on a Microsoft compiler before it is uploaded onto Canvas The code must be submitted on time in order to receive credit (11:59PM on the due date) Late submissions will...
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...
Journal Entry Instructions Within this worksheet you will find a list of transactions for the month of June. Use these to write the corresponding journal entries. You are to write all the journal entries in general journal format (double entry accounting) uST DEBITS BEFORE CREDITS. SKIP 1 LINE AFTER EACH ENTRY. MAKE SURE TO INPUT THE CORRECT 2 TRANSACTIONS ON EACH GENERAL JOURNAL PAGE THERE WILL BE EXTRA ROWS ON EACH PAGE!!! fore starting work, review the entire project: all...
13) The cost the Almy type of market 7) The market is an example of A) mattress: a monopoly B) com a perfectly competitive C) car insurance an oligopoly D) cell phone; a perfectly competitive 5) airplane manufacturing a monopolistically competitive 8) What is the difference between perfect competition and monopolistic competition? A) Perfect competition has a large number of small firms while monopolistic competition does not in monopolistic competition, firms produce identical goods, while in perfect competition, firms produce...
IN c++ i post this question 5 times. hope this time somebody answer.. 16.5 Homework 5 OVERVIEW This homework builds on Hw4(given in bottom) We will modify the classes to do a few new things We will add copy constructors to the Antique and Merchant classes. We will overload the == operator for Antique and Merchant classes. We will overload the + operator for the antique class. We will add a new class the "MerchantGuild." Please use the provided templates...