Question

In: Computer Science

USING MATLAB Part 2: Insert coins For this part, you are going implement the code that...

USING MATLAB

Part 2: Insert coins

For this part, you are going implement the code that asks the user to enter coins until they have entered enough for the NAU power juice.

  1. Open the insert_coins.m file.
  1. Initialize total to 0. We do this because initially, no coins have been entered.

  1. Using a loop, ask the user to enter a coin until the total matches or exceeds 115 cents. The input should be a char or string, so make sure that you are using the ‘s’ with your input function (refer to the pre-lab). Also, be sure that you store the input in a variable named coin. After the coin has been entered, your get_coin_value function is called to get the value of the coin and add it to the total (this has been done for you).

  1. After your loop, print a message to let them know that their NAU power juice has been dispensed.

Solutions

Expert Solution

Note: I am showing the full working code below. If some part is already implemented for you, substitute that part accordingly into this code. If any confusion, please let me know in the comments.

Matlab Code:

total = 0;

%Following function to return the value as per coin name
function value = get_coin_value(c)
c = lower(c); %converting input to all lowercase
if strcmp(c,"penny") == 1
value = 1;
elseif strcmp(c,"nickel") == 1
value = 5;
elseif strcmp(c,"dime") == 1
value = 10;
elseif strcmp(c,"quarter") == 1
value = 25;
elseif strcmp(c,"half") == 1
value = 50;
elseif strcmp(c,"dollar") == 1
value = 100;
end
end
%Loop to keep asking user for coin till total is less than 115 cents
while(total<115)
coin = input("Please enter a coin: ",'s');
total = total + get_coin_value(coin);
end

disp("Your NAU power juice has been dispensed")

Sample Output Screenshot:

(*Note: Please up-vote. If any doubt, please let me know in the comments)


Related Solutions

Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you...
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you cannot give correct MATLAB
USING C# Design and implement a program (name it Coins) that determines the values of coins...
USING C# Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below. Sample run...
Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
Start with the provided code for the class linkedListType. Be sure to implement search, insert, and...
Start with the provided code for the class linkedListType. Be sure to implement search, insert, and delete in support of an unordered list (that code is also provided). Now, add a new function called insertLast that adds a new item to the END of the list, instead of to the beginning of the list. Note: the link pointer of the last element of the list is NULL. Test your new function in main. Submit a .zip of your entire project....
in C++ For this program, you are going to implement a stack using an array and...
in C++ For this program, you are going to implement a stack using an array and dynamic memory allocation. A stack is a special type of data structure that takes in values (in our case integers) one at a time and processes them in a special order. Specifically, a stack is what's called a first-in-last-out (FILO) data structure. That is to say, the first integer inserted into the stack is the last value to be processed. The last value in...
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Function Template and Exception Handling In part one, you are going to implement the selection sort...
Function Template and Exception Handling In part one, you are going to implement the selection sort function that is capable of sorting vectors of int, double or string. In part two you will be writing a try catch block to catch the out-of-range exception. You are to write three functions and manipulate main() function for this lab all of which should be written in one main.cpp file: Part one: unsigned min_index(const vector<T> &vals, unsigned index): Passes in an index of...
Submit your calculation/answer for Part 1 and MATLAB code/result/answer for Part 2 below: Servicing Customers A...
Submit your calculation/answer for Part 1 and MATLAB code/result/answer for Part 2 below: Servicing Customers A supermarket you work part-time at has one express lane open from 5 to 6 PM on weekdays (Monday through Friday). This time of the day is usually the busiest since people tend to stop on their way home from work to buy groceries. The number of items allowed in the express lane is limited to 10 so that the average time to process an...
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
You are going to set up a small shopping system, where you are going to implement...
You are going to set up a small shopping system, where you are going to implement a "shopping bag" subject to the following specifications: Each item that will be placed in the bag needs three pieces of data included: a descriptive name, an item code (2 letters followed by two numbers), and price (in US dollars). You will implement items as a separate class, where these three properties are private, and there are mutators and accessors for all three properties,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT