Variable and Meal Price

Only available on StudyMode
  • Download(s) : 59
  • Published : May 8, 2014
Open Document


Text Preview
PT1420 - Unit 4 Homework and Lab Assignment

Unit 4 Assignment 1: Homework (from Chapter 3)

True and False (bold your answer)
1.) Modules make it easier for programmers to work in teams True
2.) Calling a module and defining a module mean the same thing. True
3.) A statement on one module can access a local variable in another module.
False
4.) Programming languages typically require that arguments be of the same data type as the parameters that they are passed to.

True
5.) When an argument is passed by reference, the module can modify the argument in the calling part of the program.

True
6.) Passing an argument by value is a means of establishing two-way communication between modules.

false
8.) What will this program code display?
Module main()
Dim x as integer = 1
Dim y as double = 3.4
Console.Writeline(x & “ “ $ y)
changeUs(x, y)
Console.Writeline(x & “ “ $ y)
End module
Sub changeUs(ByVal x as integer, ByVal y as double)
a = 0
b = 0
Console.Writeline(x & “ “ $ y)
End Sub

1 and 3.4
0 and 0

9.) What will this program code display?
Module main()
Dim x as integer = 1
Dim y as double = 3.4
Console.Writeline(x & “ “ $ y)
changeUs(x, y)
Console.Writeline(x & “ “ $ y)
End module
Sub changeUs(ByRef x as integer, ByRef y as double)
a = 0
b = 0
Console.Writeline(x & “ “ $ y)
End Sub

This would be 1 and 3.4

10.) Design a subroutine called timesTen. The subroutine should accept an integer argument. When the subroutine is called, it should display the product of its argument multiplied by 10.

Module Module1

Sub Main()
Dim number As Integer

Console.WriteLine("Please type a number")
number = Console.ReadLine()

TenTimes(number)

End Sub

Sub TenTimes(ByVal number As Integer)
Number = number * 10
Console.writeline("The product of number is: " & number) End Sub

End Module

*****************************************************************

Unit 4 Labs

1.) Lab 4.1: Meal Price. Complete this lab below using Only Functions in your program.

Write a program that will calculate a 20% tip and a 6% tax on a meal price. The user will enter the meal price and the program will calculate tip, tax, and the total. The total price is the meal price, plus the tip, plus the tax.

You will need to do this program using functions, modules (subroutines), and variables. The functions and modules needed in your program are:

Main() – prints welcome message and calls the other Modules and functions (main is already created for you)

inputMeal() – gets meal price (store answer in a variable (returns meal price))

calcTip() – calculates tip for meal (needs to be passed meal price, store results in a variable (returns tip))

calcTax() – calculate tax for meal (needs to be passed meal price, store results in a variable (returns tax))

calcTotal() – calculate total meal cost (needs to be passed meal price, tax, and tip, store results in a variable (returns total))

printInfo() – prints meal price, tip, tax, total cost. Make sure outputs are labeled (needs to be passed meal price, tax, tip, and total, returns nothing – just displays results)

Add comments in your program code. Each module or function should have a comment about what it does.

When running your program, enter 24.50 as the meal price. Your output should look as follows:

Welcome to the tip and tax calculator program

Enter the meal price 24.50

The meal price is 24.50
The tip is 4.90
The tax is 1.47
The total meal price is $30.87

Outputs for meal price, tip, and tax should be formatted with 2 decimal places, and the total output should be formatted as currency.

Module Module1

Sub Main()
' Vaiables.
Dim price As Double
Const taxer As Double = 0.06
Dim Tax2 As Double
Const...
tracking img