Presentation is loading. Please wait.

Presentation is loading. Please wait.

>> y1 = input('Please enter a number'); >> y2 = input('Please enter a letter'); >> y3 = input('Please enter a letter','s'); >> y4 = input('Please enter.

Similar presentations


Presentation on theme: ">> y1 = input('Please enter a number'); >> y2 = input('Please enter a letter'); >> y3 = input('Please enter a letter','s'); >> y4 = input('Please enter."— Presentation transcript:

1

2 >> y1 = input('Please enter a number'); >> y2 = input('Please enter a letter'); >> y3 = input('Please enter a letter','s'); >> y4 = input('Please enter a number','s'); Demo: input statements Input: 9 a 9

3 >> num = input('Please enter a number: '); >> name = input('Please enter your name: ','s'); >> fprintf('The number you''ve entered is %i',num); >> fprintf('The number you''ve entered is %i\n',num); >> fprintf('The number you''ve entered is %f\n',num); >> fprintf('The number you''ve entered is %0.2f\n',num); >> fprintf('The number you''ve entered is %8.2f\n',num); >> fprintf('Your name is %i\n',name); >> fprintf('Your name is %s\n',name); Demo: fprintf statements

4 Using input statements Problem 1: Write a script that will allow the user to enter the three coefficients of a quadratic expression (y = ax 2 + bx + c) and computes the roots of the polynomial. Problem 2: A metric ton is 35,273.92 ounces. Write a script that will allow the user to enter the weight of a box of cereal (in ounces) and compute the weight of the box of cereal in tons as well as how many boxes are needed to make one metric ton of cereal.

5 Using input statements Problem 3: You are the newest employee at VISA (Vending Innovations for Snacking Acquisition), and you have been put in charge of writing the new control system for the next wave of vending machines. Currently, the top-of-the-line model of vending machines produced by VISA only gives change in pennies. Before you implement your system on an actual vending machine, you need to do some testing. Write a script that will allow the user to enter the cost of the item and the amount of money entered and returns the least number of individual pieces of currency as change. The vending machine can return dollar bills, quarters, dimes, nickels, and pennies.

6 Write a script that will allow the user to select from a set of different dimensions for standard shipping boxes and return the volume and girth of each box. Menu Statements Dimensions: 1)L: 12” W: 12”H: 5.5” 2)L: 5.375” W: 8.675”H: 1.675” 3)L: 11” W: 8.5”H: 5.5” 4)L: 11.875” W: 3.375”H: 13.675” L W H girth

7 fprintf Statements Using fprintf statements, write a script that will display the lengths, widths, heights, volumes and girths for all 4 box options in a table format. Example Results: Length (in)Width (in)Height (in)Volume (in^3)Girth (in) 12.000 12.000 5.500 792.000 17.840 5.375 8.675 1.675 78.102 10.342 11.000 8.500 5.500 514.250 14.950 11.875 3.375 13.675 548.068 18.423

8 Useful String Functions When working with strings, there are two useful functions that can allow you to switch back and forth between numbers and strings: num2str(number) – converts a number from type double to the equivalent string of numbers str2double('string') – converts a string of number characters into a double value

9 Creating Strings Figure out 2 different ways to display the following statement: My name is X and I am Y years old. where X is a name entered by the user (using an input statement) and Y is the age entered by the user (using an input statement)


Download ppt ">> y1 = input('Please enter a number'); >> y2 = input('Please enter a letter'); >> y3 = input('Please enter a letter','s'); >> y4 = input('Please enter."

Similar presentations


Ads by Google