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
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....
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...
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...
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
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
Your task is to take the below code, and insert comments (using the “%” symbol) next...
Your task is to take the below code, and insert comments (using the “%” symbol) next to each line of code to make sure that you know what every line does. clc clear close all NMax = 100; partialSum = 0; exactAnswer = pi^2; for k=1:NMax partialSum = partialSum + 6/k^2; percentDiff(k) = abs(partialSum - exactAnswer)/exactAnswer*100; end NVector = [1:NMax]; plot(NVector,percentDiff); xlabel('{{Noob}}'); ylabel('% Difference');
Your task is to take the above code, and insert comments (using the “%” symbol) next...
Your task is to take the above code, and insert comments (using the “%” symbol) next to each line of code to make sure that you know what every line does. close all; clear all; clc; thetaAB = 0; angleIncrement = 0.1; numOfLoops = 360/angleIncrement; thetaABVector = [angleIncrement:angleIncrement:360]; rAB = 5; rBC = 8; for i=1:numOfLoops bothResults = SliderCrankPosn(rAB,rBC,thetaAB); rAC(i) = bothResults(1); thetaBC(i) = bothResults(2); thetaAB = thetaAB+angleIncrement; end subplot(2,1,1) plot(thetaABVector,thetaBC,'Linewidth',3); xlabel('\theta_{AB} [degrees]'); ylabel('\theta_{BC} [degrees]'); xlim([0 360]); ylim([300 400]); grid...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT