You are on page 1of 3

IS122 Information Systems II Supplementary Lab More on programming with Variables

In this lab, you will practice more on how to declare variables to store information in the computers memory and do basic calculations using these variables. This lab will not be assessed.

Objectives
By the end of this lab activity you should be able to: Design forms. Use appropriate variables and constants for storage in your programs. Use the Convert class methods to convert data to an appropriate type To give you the opportunity to do math in VB.NET Write mathematical expressions and assignment statements in VB.NET

Before coming to practical 1. Design the form for Exercise 1. You should draw a sketch of the user interface and all the controls on the form. Think of the variables and their type that you are going to use. Decide on the scope you need to give to the variables (procedure level/module level). 2. Design the form for Exercise 2. Exercise 1 Making a Change Calculator Program Yummy Pizza & Bakery Shop has asked you to help them build a change maker program. Their business is very simple this year: They only sell medium sized pizzas at a fixed price of $10.50, regardless of the flavour. What they want the program to do is: 1. To allow their cashier to enter the quantity for pizza ordered 2. Calculate and display the total purchase cost 3. Then allow the cashier to input the amount paid. [AmountPaid must be > PurchasePx] 4. Calculate and display the change. 5. Then calculate and display the in the various denominations. [Since they a very small company they only have and accept the following denominations: $10, $5. $2, 50c, 20c, 10c, 5c, 2c, 1c] User Interface The applications user interface is to be made up of the following: A Textbox to allow their cashier to enter the quantity for pizza ordered A Button to calculate and display the total purchase cost A Label to display the total purchase cost. A Textbox to allow the cashier to input the amount paid. A Button to calculate and display the total change and also the breakdown of this change. Labels to display the change and its breakdown. A Button to clear the input and out fields. A Button to exit program.
IS122 Information Systems II Page 1 of 3

Supplementary Lab

Implementation The following hints may be used for you code: Declare the following variables to have module level scope: 1. The price of pizza is fixed, declare a constant to hold that value. 2. A variable to store the total purchase cost of pizza. In the click event of the calculate total purchase cost button: A. Convert the quantity ordered to an appropriate numeric datatype of your choice. B. Calculate the purchase cost by multiplying quantity with price of pizza (constant declared in step 1 above) and storing the result in variable declared in step 2 above. C. Format total purchase cost and display in a label. In the click event of the calculate change button I. Declare appropriate variables to store the values for amount tendered and change to be calculated. II. Convert the amount tendered input value to an appropriate numeric datatype of your choice and store in variable declared in step I. III. Calculate change, store the results in the change variable declared in step I. IV. Format change and display in label. V. Break down which notes and coins to be given as change and display. To break down which notes and coins to be given as change use the following hint. Example if change is $2.50 and x is declared as an integer variable then: x = change/10; Display x $10 bill(s) change = change (x * 10) //gives the amount of $10 notes you need //which should display 0 $10 bill(s) in a label // update new value of change

To find out if $5 bills are needed: x = change/5; //gives the amount of $5 notes you need Display x $5 bill(s) //which should display 0 $5 bill(s) in a label change = change (x * 5) // update new value of change Similarly do the rest for the other denominations. Turn on Option Strict. You will then need to use the appropriate functions from the Convert class for the above calculation. [Note: It is recommended not to write a number (literal constant) in the middle of an expression. Hence in this case the various denominations (10, 5, 2 e.t.c.) used in the calculation above have to be declared as constants and then used in the division.] Once program is done, show it to your tutor.

Supplementary Lab

IS122 Information Systems II

Page 2 of 3

Specific Example: Assuming the following data and that pizza is sold at $10.50 Input Data: Quantity of Pizza Ordered: Amount tendered: Output results: Total Purchase cost: Change: Change Breakdown:

9 100

$94.50 $5.50 0 $10 bill(s) 1 $5 bill(s) 0 $2 bill(s) 1 50 cent(s) 0 10 cent(s) 0 5 cent(s) 0 2 cent(s) 0 1 cent(s)

Interface Design Planning Sketch (Exercise 1)

Form Name:_______________

Supplementary Lab

IS122 Information Systems II

Page 3 of 3