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
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
Overview In this assignment you are required to implement binary code comparator using Xilinx that it...
Overview In this assignment you are required to implement binary code comparator using Xilinx that it is compatible with the MXK Seven Segment Displays. You will draw your digital logic circuit using Xilinx and then simulate it to verify the functionality of your design. Software Requirements ? Xilinx ISE 10.1 or higher Specifications Binary Code Comparator The binary code comparator is to be implemented and made compatible with the seven 7-segment displays of the board. Represent the first five digits...
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting...
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT