Sei sulla pagina 1di 4

McCoy, Daniel

CISP 300
Optional Assignment (Chapter 8)

Statement of Problem
Construct an algorithm to show the processing steps needed to solve the
following problem. Data values to be added are provided as input, The number
of items to be added will be indicated by the first value provided as input
(not included in the sum). A count of the number of data items whose value
exceeds 30,000 is also to be accumulated. The sum of the values added and the
count of those exceeding 30,000 are to be provided as output. Headings and
page numbers are not required.

Structure Chart

O VER AL L
C O N T RO L

A 000

P R O C E SS P R O C E SS O UT PU T
I N IT IA L I Z A T I O N D AT A

B 000 B 010 B 020

Table of Variables
Variable Name Type Range Description
N Number 0-1000 Number of values to input
DATA Number 0-500000 The input data value
SUM Number 0-10000000 Sum of all data values
LARGECOUNT Number 0-1000 The number of values over 30000
Pseudocode
A000
START
Process Initialization (B000)
WRITE "How many values to input?"
READ N
IF N <= 0 THEN
WRITE "No Data"
ELSE
DOUNTIL N = 0
Process Data (B010)
N = N - 1
ENDDO
Output Data (B020)
ENDIF
STOP

B000
N = 0
SUM = 0
LARGECOUNT = 0
RETURN

B010
WRITE "Enter data value"
READ DATA
IF DATA > 30000 THEN
LARGECOUNT = LARGECOUNT + 1
(ELSE)
ENDIF
SUM = SUM + DATA
RETURN

B020
WRITE "The sum of all data values is: ", SUM
WRITE "The number of data values over 30,000 is: ", LARGECOUNT
RETURN
Qbasic Source
DECLARE SUB ProcessInitialization()
DECLARE SUB ProcessData()
DECLARE SUB OutputData()
DIM SHARED N AS LONG
DIM SHARED SUM AS LONG
DIM SHARED LARGECOUNT AS LONG

CLS
CALL ProcessInitialization
PRINT "How many values to input?"
INPUT N
IF N <= 0 THEN
PRINT "No Data"
ELSE
DO
CALL ProcessData
N = N - 1
LOOP UNTIL N = 0
CALL OutputData
END IF
END

SUB ProcessInitialization
N = 0
SUM = 0
LARGECOUNT = 0
END SUB

SUB ProcessData
PRINT "Enter data value"
INPUT DATAV
IF DATAV > 30000 THEN
LARGECOUNT = LARGECOUNT + 1
END IF
SUM = SUM + DATAV
END SUB

SUB OutputData
PRINT "The sum of all data values is: ", SUM
PRINT "The number of data values over 30,000 is: ", LARGECOUNT
END SUB
Basic Screenshot

Potrebbero piacerti anche