Victoria Torres Lab2 Manual
Victoria Torres Lab2 Manual
Lab 2: Modules
This lab accompanies Chapter 3 of Starting Out with Programming Logic & Design.
A Module is a group of statements that exists within a program for the purpose of performing a
specific task.
Modules are commonly called procedures, subroutines, subprograms, methods, and functions.
The code for a module is known as a module definition. To execute the module, you write a
statement that calls it.
Module name( )
Statement
Statement
Etc.
End Module
Calling a module is normally done from the Main ( ) module such as:
Call name( )
Generally, local variables should be used and arguments should be passed by reference when the
value of the variable is changed in the module and needs to be retained. For example:
Module main( )
Real Integer number
Call inputData(number)
Call printData(number)
End Module
lab2-2.wmv
Starting Out with Programming Logic and Design 2
This lab requires you to think about the steps that take place in a program by writing
pseudocode. Read the following program prior to completing the lab.
Step 1: This program is most easily solved using just four variables. Declare the
variables that you will need in the program, using the proper data type and documenting
the purpose.
Step 2: Given the major task involved in this program, what modules might you consider
including? Describe the purpose of each module. (Reference: Defining and Calling a
Module, page 78).
Step 3: Complete the pseudocode by writing the missing lines. (Reference: Defining
and Calling a Module, page 78-81). Also, when writing your modules and making calls,
Starting Out with Programming Logic and Design 3
be sure to pass necessary variables as arguments and accept them as reference parameters
if they need to be modified in the module. (Reference: Passing Arguments by Value and
by Reference, page 97 – 103).
Module main ()
//Declare local variables
Declare Real totalSales
Declare Real countyTax
Declare Real stateTax
Declare Real totalTax
//Function calls
Call inputData(totalSales)
Call calcCounty(totalSales, countyTax)
Call calcState(totalSales, countyTax, stateTax)
Call calcTotal(countyTax, stateTax, totalTax)
Call printData(countyTax, stateTax, totalTax)
End Module
End Module
End Module
Starting Out with Programming Logic and Design 4
End Module
Starting Out with Programming Logic and Design 5
Critical Review
The flowchart symbol used for a function call is a rectangle with vertical bars on each
side:
Main ( ) Method ( )
End
lab2-3.wmv
This lab requires you to think about the steps that take place in a program by designing a
flowchart. Use an application such as Raptor or Visio. Read the following program prior
to completing the lab.
Step 1: Start Raptor and save your document as Lab 2-3. The .rap file extension will be
added automatically. Start by adding a Comment box that declares your variables. Here
is a start to how your Comment box should look.
Starting Out with Programming Logic and Design 6
Step 2: The next step in your flowchart should be to call your methods. Click the Call
Symbol on the Left and Drag and Drop to the flow lines between Start and Stop. Double
click on the Call Symbol and type the name of your first method. For example, type
inputData in the Enter Call box. Do not put the ( ) when using Raptor. Click the Done
button. A new box will pop up that will ask you to create a new tab. Click Yes. A new
tab will be created for your new method. Notice the new Tab called inputData.
Step 3: Continue this process to add your additional methods, which are calcCounty()
calcState(), calcTotal() and printData().
Step 4: Click on the inputData tab and add the necessary code as identified in your
pseudocode in Lab 2.2. In Raptor, there is no need to pass variables as References as in
pseudocode. Your inputData method might look like the following:
Step 5: Continue to code the remaining methods, which are calcCounty() calcState(),
calcTotal() and printData(). If you happened to execute your program without
completing your program, an error will occur such as:
Starting Out with Programming Logic and Design 7
Your calculations methods input box might look like the following:
Your output data methods box might look like the following:
Step 6: After your program is complete, click Run, then Execute to Finish. For your
input, enter 67854 as your total monthly sales. If your program is coded correctly, the
output should be as follows:
Starting Out with Programming Logic and Design 8
Step 7: The final step is to insert your finished flowchart in the space below. Inside
Raptor, select File and the Print to Clipboard from the menu. Inside Word in the space
below, select Edit and Paste. You will have to do this for each module you created.
Start
inputData
Declare variables
calcTotal
printData
End