Programming 3

profileShane0301
lab8_accumulators.docx

______________________________________________________________________________________________________________________________________________________________________________________________________________________

CTI 110 Page 2

______________________________________________________________________________________________________________________________________________________________________________________________________________________

Lesson 8

Lab –Using Counters and Accumulators

Objectives

· Use the while structure to keep track of:

· An accumulator

· A counter

· Output the results

Lab Task Checklist

· It is expected you have read the required reading in this Lesson before starting the lab.

· Review Course Resources/(ROE) and Standards/ROE: Programming/Flowgorithm Programs

· Review Course Resources/Flowgorithm Guidance/Menu Guidance

· Use Flowgorithm to create an algorithm meeting customer requirement

· File naming Convention “lastname-lab-accum.fprg”.

· Submit all file/s to Blackboard.

Instructions:

1. Review the customer requirements

Customer Requirements: The customer needs an application that creates a report giving the total real-estate sales for the month and the average of those sales. The customer will provide the prices of each home sold that month. Once the customer is done providing the information than they should be able to enter “ZZZ” to exit the input and create the report. The report will display the accumulated price, the average price as well as the number of properties used for the average. Additional display:

· User information (user and month and year of report)

· Report Headings ( Name of Report and breakout of Address and price)

2. Review the IPO and example pseudocode found below.

3. Open Flowgorithm and save with the required naming conventions in the “Lab Task Checklist” and remember to enter your Program Attributes.

4. Translate the below pseudocode to flowcharts using Flowgorithm.

5. What the pseudocode does:

a. Reserve Memory Locations (Declare) - Use as short and meaningful names

i. Variables - Declare variables close to where they will be used

1. Use the correct naming conventions (found in ROE)

ii. Named constants - Declare named constants at the start of the program

1. Use the correct naming conventions (found in ROE)

b. Use prompts to describe required input before asking for input

6. Document your test cases using the comment block of flowgorithm

Input, Output and Processing (IPO)

Input

Processing

Output

Variables:

Sales price

Name

Month

Year

Address

Assign Quit =“ZZZ”

Assign counter = 0

Assign accumulator = 0

Get sales price, name, month, year

Calculate accumulated prices of all properties entered and average

· Accumulated price = accumulated price + price

· Average price = accumulated price / counter

Welcome message

Report Headings

Prompts for input

Accumulated price

Average price

Number of properties

Finish and Programmer Credits

Test Data

T1: 3 entries 25500, 30000.50, 5000 accumprice= 60500.5, average = 20166.833

T2: Test Quit

Pseudocode Example (Gaddis Pseudocode):

**DISCLAIMER: This is only one of many ways that can be used to meet the customer requirements above.

** Reminder: Flowgorithm concatenation symbol is an ampersand (&) not a comma (,)

Function Main

// T1: 3 entries 25500, 30000.50, 5000 accumprice= 60500.5, average = 20166.833

// T2: Test Quit

Declare String address

Declare String name

Declare String reportMonth

Declare String reportYear

Display "Welcome to our Realestate Sales Application"

Display "Who is this report for?"

Input name

Display "What month is this report for?"

Input reportMonth

Display "What year is this report for?"

Input reportYear

Display "Requester: ", name

Display "Report date is ", reportMonth, " ", reportYear

Display "MONTH-END SALES REPORT"

Display "Address Price"

Display "Enter address of property"

Display "What is your address"

Input address

Declare Real price, accumPrice, avgPrice

Declare String QUIT

Set QUIT = "ZZZ"

Declare Integer counter

// Accumulator program. Accumulator must be initialized to 0, altered with each data set processed, and at the end outputs the accumulator

Set counter = 0

Set accumPrice = 0

While address != QUIT

Display "Enter Price of property"

Input price

Display address, " ", price

Set accumPrice = accumPrice + price

Set counter = counter + 1

Display "Enter address of next property or ZZZ to quit"

Input address

End While

Set avgPrice = accumPrice / counter

Display "The total accumulated price of realestate is: ", accumPrice, " The average realestate price for ", counter, " properties this month is: $", avgPrice

Display "Thank you for using this program. This program was created by lastname"

AY2022