Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve in MATLAB Function Name: coinCounter Inputs: 1. (double) an NX 4 array containing varying amounts of pennies, nickels, dimes, and quarters in each column

solve in MATLAB image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Function Name: coinCounter Inputs: 1. (double) an NX 4 array containing varying amounts of pennies, nickels, dimes, and quarters in each column 2. (char) a 1x4 char vector detailing the type of coin in each of the columns Outputs: 1. (double) a 5 x N array containing the coin amounts from the original array as well as each employee's total earnings in tips 2. (char) a sentence indicating the highest paid employee in tips and how much they earned for that given day Topics: (array masking). (transpose) (array manipulation) (sorting) (sprint) Background: It is the end of the day after a long shift bussing tables at Rays NY Pizza in Tech Square. You and your coworkers noticed that a ton of Georgia Tech students have been tipping in coins recently, so you decide to put your heads together and calculate who earned the most in tips that night. Everyone split their own coins into different piles of the types of coins they eamed and counted how many of each type they had. To make it easier, you decide to use your MATLAB skills to calculate the amount each employee earned. Function Description: Given an N * 4 array (input 1) where each row of the array represents a different employee and each column of the array represents a certain type of coin, determine how much money in tips each of the employees made for a given shift. The values in the array represent the number of each type of coin they received. In the 1 x 4 char vector (input 2). 'p' represents pennies ($0.01). 'n' represents nickels ($0.05), 'd' represents dimes ($0.10), and 'q' represents quarters ($0.25). The order of the char vector represents the type of coin (denoted by the letters 'p', 'm', 'd', and 'q") and its corresponding column (based on its index) in the larger array. For example, the string 'pndq' would mean pennies are in the first column, nickels in the second, dimes in the third, and quarters in the fourth Calculate each employees' earnings in tips and append a column to the right of the original array containing their corresponding totals Next, sort the entire array based on each employee's total amount of tips in descending order (the highest paid employee would be the first row, lowest paid employee would be the last). Finally, flip the rows and columns of the array, such that the tip totals are now found in the last row of the array and the employees and the corresponding number of coins they each have are represented by each column, and round all values to the second decimal place. Store the new rounded array in the first output. Finally, output the following statement: Employee number original employee row> was the highest paid and made scamount> in tips today. Where the original employee row corresponds to the row in the original array (prior to sorting) where the highest-paid employee was found and amount corresponds to the amount in tips they made. Example: coinArr (5 3 6 3 4 2 coinorder= 'dqpn! 2 11 23 0 91 [tiparr, sentence] = coinCounter (coinarr, coinorder) tipArt - [4 2 11 9 5 3 8 2 1.43 6; 3; 2; 0; 1.37 ] 1.46 sentence $1.46 Employee number 3 was the highest paid and made in tips today. Note: the highlighted row/column denotes employee 13 . Notes: The coin array will contain only positive integer values . The only chars that will be found in the second input are 'p'. 'n. q. and 'd', appearing exactly as given above and occurring exactly one time each The coins can be given in any order When displaying your output sentence, ensure the dollar amount only displays two values after the decimal (ex $5.98 rather than $5.9800) Be sure to round the final array as stated above, as to not cause a floating point error (slight rounding inaccuracles with decimals can cause the entire output to be considered incorrect) Hints: Remember conditionals and iteration are banned o Think of a way you can do this problem without using conditionals. You are guaranteed to only have 4 types of coins and you know how much each coin is worth. Try using sprintf with %f Which operation would allow you to switch the rows and the columns? Function Name: timeUnscrambler Inputs: 1. (double) MxN array representing your scrambled time card Outputs: 1. (double) Mx(N+1) array representing your fixed time card Topics: (array masking). (sorting arrays). (linear indexing) Background: You've just been hired as a TA for Georgia Tech's newest computer science class, CS1731. In hopes that the CS department will give you a raise, you decide to take on some extra hours by working the overnight shift at the help desk. Each night, you log the hours you've worked on a timecard, and at the end of the week you turn it in to your boss in hopes of that prized promotion. One evening, however, you fall asleep for 5 minutes on the job and when you wake up, your pesky co-TA's have messed with your time cards to ruin your chances of Impressing your boss! Desperate, you turn to MATLAB to help you unscramble the mess. Function Description: You are given an array of doubles representing your scrambled time card. Apply the following operations to unscramble your card: 1. Replace all negative numbers in your array with their positive equivalent (.e.-5--5) 2. Flip the order of the elements in your array's major diagonal, for example: 4 3 [1 2 3 5 & 7 90 3 4 5 8 2 [ 2 5 9 3 4 4 8 2 1) 5 3. Sort the rows of your array in ascending order based on the first column (e. the numbers should get larger as you go down the rows in the first column) 4. The first column of your sorted array will represent the amount of time you have worked, in minutes. Replace this column with two separate columns in the final output, where the first column is the number of hours you have worked, and the second is the number of additional minutes. For example 1100 234 52 300 11 40 3 54 0 52 5 D 1 1 Example: scrambled = (-11 8 -80 563 -23 382 - 49 4 3 -22 123 4 -40 0 -2 63] unscrambled = timeUnscrambler (scrambled) unscrambled = [0 8 123 0 1 23 40 22 3 382 4 3 20 23 1 2 49 4 9 11 Hints: To linearly index out the values of the major diagonal, start by finding the starting index, step size, and stopping index for the diagonal first. Try writing out 5x3, 3x3, and 3x5 arrays and ask yourself the following questions: How do the indices for the major diagonal behave? o What patterns do you observe (either in step sizes or stopping index values) in relation to the array's dimensions? How can you flip or reverse the order of a vector using linear indexing

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago