Lab 2.1 - Pseudocode and Modules Critical Review A Module is a group of statemen
ID: 3886295 • Letter: L
Question
Lab 2.1 - 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 naneL 3ttement 3tatement Etc End Hodule Calling a module is normally done from the Main module such as: Call nane 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 mainL Declare Real number Call inputData (number) Call printData (number) End Hodule //accept number reference o the changed value ill be retained Module inputDatalReal Ref number) Number = 20 End Hodule //number does not to be sent reference becau e /number is not going to be modified Module BKARERARAReal number Display "The number ", number End Hodule Help Video: lab2-1.wnvExplanation / Answer
Main() //Declare local variables Declare Real totalSales Declare Real countyTax, stateTax, totalTax //Function calls Call inputData(totalSales) Call calCountyTax(totalSales, countyTax) Call calcStateTax(totalSales, countyTax) Call calcTotalTax(stateTax, countyTax, totalTax) Call displayTax(totalTax, countyTax, stateTax) End Module //This module takes in the requires user input Module inputData(Real Ref totalSales) Display “Enter totalSales for the month” Input totalSales End Module //this module calcuates county calCountyTax //totalSales can be a value parameter because it is not //changed in the module. //countyTax must be a reference parameter because it is ot //changed the module Module calcCountyTax(Real totalSales, Real Ref countyTax) Set countyTax = totalSales * .02 End Module //this module calculates state tax Module calcStateTax (Real totalSales, Real Ref stateTax) Set stateTax = totalSales * .04 End Module //this module calculates total tax Module calcTotalTax(Real stateTax, Real countyTax, Real Ref totalTax) Set totalTax = stateTax + countyTax End Module //this module prints the total, county, and state tax Module displayTax (Real totalTax, Real countyTax, Real stateTax) Display "County tax is: " + countyTax Display "The State tax is: " + stateTax Display "The Total tax is: " + totalTax End Module
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.