Question

In: Computer Science

MATLAB CODE Let’s say you need to write a small script that takes in the total...

MATLAB CODE

Let’s say you need to write a small script that takes in the total amount of money entered, and a cost, and returns the correct change in quarters/dimes/nickels/pennies.

  • Initialize counter variables for quarters, dimes, nickels and pennies to 0. Counter variables are used to keep track of how many of each coin are to be returned.
  • Calculate the amount of change to be given using the ‘total’ and ‘cost’ variables.
  • While there is still change to be given, find the largest coin that can be returned, increment the coin’s counter, and subtract the coin value from the amount of change to be given.
  • Display the total change, as well as how many of each coin are being returned.

PREVIOUS CODE FOR THIS

function value = get_coin_value(coin)

%Set value to be the correct number based on coin.

%For example, if coin == 'q', value = 25

if coin == 'q'

value = 25;

elseif coin == 'd'

value = 10;

elseif coin == 'n'

value = 5;

elseif coin == 'p'

value = 1;

else

value = 0;

end

function total = insert_coins

%your code here

total = 0;

%Loop to keep asking user for coin till total is less than 115 cents

while(total<115)

coin = input('Enter q for quarter, d for dime, n for nickel,p for penny:','s');

total = total + get_coin_value(coin);

end

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

end

Solutions

Expert Solution

classdef MyClass < handle properties
publicProp = 1;
end
properties(Access = private)
privateProp
end
methods
function obj = MyClass(value)
obj.privateProp = value;
end
function publicMethod(obj,value)
obj.privateMethod(value);
end
function res = calculateSomeValue(obj)
res = obj.publicProp*obj.privateProp;
end
end
methods (Access = private)
function privateMethod(obj,value)
obj.publicProp = obj.publicProp + value;
obj.privateProp = obj.privateProp + obj.doubleThisValue(value);
end
end
methods(Static)
function res = doubleThisValue(val)
res = 2 * val;
if coin == 'q'
value = 25;
elseif coin == 'd'
value = 10;
elseif coin == 'n'
value = 5;
elseif coin == 'p'
value = 1;
else
value = 0;
end
function total = insert_coins
total = 0;
while(total<115)
coin = input('Enter q for quarter, d for dime, n for nickel,p for penny:','s');
total = total + get_coin_value(coin);
end
disp("Your NAU power juice has been dispensed")
end
end
end
end

Related Solutions

MATLAB CODE Let’s say you need to write a small script that takes in the total...
MATLAB CODE Let’s say you need to write a small script that takes in the total amount of money entered, and a cost, and returns the correct change in quarters/dimes/nickels/pennies. Initialize counter variables for quarters, dimes, nickels and pennies to 0. Counter variables are used to keep track of how many of each coin are to be returned. Calculate the amount of change to be given using the ‘total’ and ‘cost’ variables. While there is still change to be given,...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
Write a java code that: 1) Takes as an argument an integer number, say N 2)...
Write a java code that: 1) Takes as an argument an integer number, say N 2) Creates an array of size N 3) Populates the array with random numbers between 0 and 10 * N. This is, the values of the elements of the array should be random numbers between 0 and 10 * N. 4) Finally, the code outputs the index of the smallest element and the index of the largest element in the array
Matlab: How would I write a script that calculates a. 654.23+345.73 b. 3984566/5.5 (need to use...
Matlab: How would I write a script that calculates a. 654.23+345.73 b. 3984566/5.5 (need to use the  format long command)
write a matlab script for double mass spring system with animation.
write a matlab script for double mass spring system with animation.
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as...
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations. Part B: In...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
3. Write a Matlab script that describes the dynamics of Pressure and Flow in the systemic...
3. Write a Matlab script that describes the dynamics of Pressure and Flow in the systemic arteries and Left Ventricle. Assume that : 1) Pressure in the Left atrium (PLA) and in the Systemic Veins (Psv) remain constant. 2) A time dependent LV compliance 3) Opening/Closing of the heart valves instantaneously with the direction of flow (i.e. valves are at an open or closed states. Use parameter values from the handout.
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT