0% found this document useful (0 votes)
80 views8 pages

Victoria Torres Lab2 Manual

This document discusses modules in programming. It provides an example of a retail sales tax calculation program broken down into modules. The purpose of each module is described, including an inputData module to get user input, calcCounty/State modules to calculate taxes, a calcTotal module to sum the taxes, and a printData module to output the results. Pseudocode is provided to define the main module and call the other modules, passing arguments by reference as needed. Students are assigned to write pseudocode and create a flowchart for the program following these guidelines.

Uploaded by

Vick Torres
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views8 pages

Victoria Torres Lab2 Manual

This document discusses modules in programming. It provides an example of a retail sales tax calculation program broken down into modules. The purpose of each module is described, including an inputData module to get user input, calcCounty/State modules to calculate taxes, a calcTotal module to sum the taxes, and a printData module to output the results. Pseudocode is provided to define the main module and call the other modules, passing arguments by reference as needed. Students are assigned to write pseudocode and create a flowchart for the program following these guidelines.

Uploaded by

Vick Torres
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

Starting Out with Programming Logic and Design 1

Lab 2: Modules
This lab accompanies Chapter 3 of Starting Out with Programming Logic & Design.

Name: Victoria Torres.


Lab 2.2 – Pseudocode and Modules
Critical Review

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.

The format for a module definition is as follows:

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

//accepts number as a reference so the changed value


//will be retained
Module inputData(Real Ref number)
Number = 20
End Module

//number does not to be sent as a reference because


//number is not going to be modified
Module printData(number)
Display “The number is “, number
End Module

Help Video: Double click the file to view video

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.

A retail company must file a monthly sales tax report


listing the total sales for the month and the amount of
state and county sales tax collected. The state sales tax
rate is 4 percent and the county sales tax rate is 2
percent. Write a program that asks the user to enter the
total sales for the month. The application should calculate
and display the following:
 The amount of county sales tax
 The amount of state sales tax
 The total sales tax (county plus state)

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.

Variable Name Purpose


Declare Real totalSales Stores total sales the user
inputs
Declare Real countyTax Stores the calculated state
tax
Declare Real stateTax Stores the calculated state
tax
Declare Real totalTax Stores the calculated total
tax

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).

Module Name Purpose


Module inputData () Allows the user to enter required
user input
Module calcCounty () Calculates the county tax at 2% of
the monthly sales
Module calcCounty () Calculates the state tax at 4% of the
monthly sales
Module calcTotal () Calculates the total tax as state
plus county
Module printData () Prints the necessary information

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

//this module takes in the required user input


Module inputData (Real Ref totalSales)
Display “Enter the total sales for the month.”
Input totalSales
End Module

//this module calculates county tax


//totalSales can be a value parameter because it is not
//changed in the module.
//countyTax must be a reference parameter because it is
//changed in the module
Module calcCounty(Real totalSales, Real Ref countyTax)
countyTax = totalSales * .02
End Module

//this module calculates state tax


Module calcState (Real totalSales, Real Ref stateTax)
State Tax = totalSales * .04

End Module

//this module calculates total tax


Module calcTotal (Real countyTax, Real state Tax, Real Ref
totalTax)
Display “The county tax is”, countyTax
Display “The state tax is”, countyTax
Display “The total tax is”, totalTax

End Module
Starting Out with Programming Logic and Design 4

//this module prints the total, county, and state tax


Module printData (Real countyTax, Real state Tax, Real Ref
totalTax)
Display “The county tax is”, county Tax
Display “The state tax is”, state Tax
Display “The total tax is”, total Tax

End Module
Starting Out with Programming Logic and Design 5

Lab 2.3 – Flowcharts

Critical Review

The flowchart symbol used for a function call is a rectangle with vertical bars on each
side:

Main ( ) Method ( )

//Used in main to //do something


represent a
function call
Method( )
Return

End

Help Video: Double click the file to view video

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.

A retail company must file a monthly sales tax report


listing the total sales for the month and the amount of
state and county sales tax collected. The state sales tax
rate is 4 percent and the county sales tax rate is 2
percent. Write a program that asks the user to enter the
total sales for the month. The application should calculate
and display the following:
 The amount of county sales tax
 The amount of state sales tax
 The total sales tax (county plus state)

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

The county tax is $1357.0800


The state sales tax is $2714.1600
The total tax is $ 4071.2400
----Run finished----

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.

PASTE FLOWCHART HERE

Start

inputData
Declare variables

calcCounty Declare Real totalSales


Declare Real countyTax
Declare Real stateTax
Declare Real totalTax
calcState

calcTotal

printData

End

You might also like