Assignment: Pseudo Code Solutions for Critical Thinking Problems 2017

Verified

Added on  2020/03/23

|9
|895
|315
Homework Assignment
AI Summary
This document presents pseudo code solutions for three distinct programming problems. The first solution calculates the average of eleven user-inputted numbers and counts the occurrences of the number six. The second solution calculates the average of even numbers between 1 and a positive integer input by the user. The third solution processes user-inputted data until a dummy value (999) is entered, then calculates and displays the number of families with zero children, the number of families with more than four children, and the largest number of children in a family. Each solution includes main, initialization, calculation, and output modules, demonstrating modular programming principles. The document also includes a hierarchy chart and a defining diagram to illustrate the structure and flow of the programs, along with references to critical thinking resources.
Document Page
[Critical Thinking and Problem Solving]
2017
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
QUESTION 2
A pseudo code that reads eleven numbers from the user and prints the average of these
eleven numbers. Also counts the occurrence of number 6 in the program.
//MAIN MODULE
CREATE AVERAGE_OF_NUMBERS
//an object created to give a call to other modules
CREATE object for AVERAGE_OF_NUMBERS
COMPUTE_INITIALIZE_VARIABLES
COMPUTE_CALCULATE_AVERAGE
COMPUTE_DISPLAY_AVERAGE
END
//INITIALIZATION MODULE
CREATE INITIALIZE_VARIABLES
//create array
DECLARE and INITIALIZE MEMORY TO ARRAY ELEVEN_NUMBERS[ ]
INITIALIZE an integer CLOCK to value 0
INITIALIZE an integer SUM to value 0
DECLARE a decimal variable AVERAGE
INITIALIZE an integer i to value 1
END
//CALCULATION MODULE
CREATE CALCULATE_AVERAGE
REPEAT
READ ELEVEN_NUMBERS[i] //populate array
IF ELEVEN_NUMBERS[i] equals 6 //check for the occurrence of number 6
INCREMENT CLOCK by 1
//counter incremented in case number 6 found
END IF
UNTIL i equals 11 //Auto increments value of i and checks the condition SET i
= 1
REPEAT
Document Page
Set SUM = SUM + ELEVEN_NUMBERS[i]
UNTIL i = 11
SET AVERAGE = SUM / 11
END
//OUTPUT MODULE
CREATE DISPLAY_AVERAGE
PRINT AVERAGE //display average of eleven numbers
PRINT CLOCK //display multiple occurrence of number 6
END
QUESTION 3
A Pseudo Code that reads a positive integer from user and finds the average of all even
numbers between 1 and user’s input.
//MAIN MODULE
CREATE AVERAGE_OF_EVEN_NUMBERS
CREATE object for AVERAGE_OF_EVEN_NUMBERS
COMPUTE_INITIALIZE_VARIABLES
COMPUTE_READ_MAX_LIMIT
COMPUTE_CALCULATE_EVEN_AVERAGE
COMPUTE_DISPLAY_EVEN_AVERAGE
END
//INITIALIZATION MODULE
CREATE INITIALIZE_VARIABLES
DECLARE a decimal variable AVERAGE
INITIALIZE an integer P to value 0
INITIALIZE an integer CLOCK to value 0
INITIALIZE an integer I to value 1
INITIALIZE an integer SUM to value 0
END
//INPUT MODULE
CREATE READ_MAX_LIMIT
PRINT “INPUT A POSITIVE INTEGER”
WHILE P<0 //Ensures validation
Document Page
READ P
IF P<=0 //Validation Check
PRINT “INVALID INPUT: PLEASE RE-TRY”
//Error message printed if validation fails
END IF
END WHILE
END
// CALCULATION MODULE
CREATE CALCULATE_EVEN_AVERAGE
REPEAT
IF I MOD 2 EQUAL 0
SET SUM = SUM + I
SET CLOCK = CLOCK + 1
END IF
UNTIL I>=P //Auto increments value of i and checks the condition
SET AVERAGE = SUM/CLOCK
END
//OUTPUT MODULE
CREATE DISPLAY_EVEN_AVERAGE
PRINT AVERAGE
END
QUESTION 4
A pseudo code that reads the data from user until dummy value 999 encountered and print
some results based on this data.
//MAIN MODULE
CREATE CHILDREN_RECORD
CREATE object for CHILDREN_RECORD
COMPUTE_ INITIALIZE_VARIABLES
COMPUTE_INPUT_CHILDREN_DATA
COMPUTE_FAMILY_WITH_ZERO_CHILDREN
COMPUTE_ FAMILY_WITH_MORE_THAN_FOUR_CHILDREN
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
COMPUTE_ FAMILY_WITH_LARGEST_CHILDREN
COMPUTE_DISPLAY_ALL_RECORDS
END
//INITIALIZATION MODULE
CREATE INITIALIZE_VARIABLES
DECLARE and INITIALIZE MEMORY TO ARRAY CHILDREN_DATA [ ]
INITIALIZE an integer I to value 1
INITIALIZE an integer J to value 1
INITIALIZE an integer CLOCK to value 0
INITIALIZE an integer ZERO_CHILDREN to value 0
INITIALIZE an integer MORE_THAN_FOUR_CHILDREN to value 0
INITIALIZE CHILDREN_DATA [I] to value 0
END
//INPUT MODULE
CREATE INPUT_CHILDREN_DATA
WHILE CHILDREN_DATA [I] is not equal to 0 //Ensures validation
READ CHILDREN_DATA [I]
SET CLOCK = CLOCK + 1
//Validation Check
IF (CHILDREN_DATA [I]<0) OR (CHILDREN_DATA [I] is not INTEGER)
PRINT “INCORRECT INPUT: ENTER POSITIVE INTEGER”
//Error message printed if validation fails
END IF
SET I = I + 1
END WHILE
END
//CALCULATION MODULES
CREATE FAMILY_WITH_ZERO_CHILDREN
CALL INPUT_CHILDREN_DATA
REPEAT
IF (CHILDREN_DATA [I] is equal to 0)
SET ZERO_CHILDREN = ZERO_CHILDREN = 1
END IF
Document Page
UNTIL I is equal to P //Auto increments value of Iand checks the condition
END
CREATE FAMILY_WITH_MORE_THAN_FOUR_CHILDREN
CALL INPUT_CHILDREN_DATA
REPEAT
IF (CHILDREN_DATA [I] > 4)
MORE_THAN_FOUR_CHILDREN =
MORE_THAN_FOUR_CHILDREN + 1
END IF
UNTIL I is equal to P //Auto increments value of I and checks the condition
END
CREATE FAMILY_WITH_LARGEST_CHILDREN
CALL INPUT_CHILDREN_DATA
INITIALIZE an integer MAX to value CHILDREN_DATA [1]
REPEAT
IF (CHILDREN_DATA [I] > MAX)
Set MAX = CHILDREN_DATA [I]
END IF
UNTIL I is equal to P //Auto increments value of I and checks the condition
END
//OUTPUT MODULE
CALL FAMILY_WITH_ZERO_CHILDREN
CALL FAMILY_WITH_MORE_THAN_FOUR_CHILDREN
CALL FAMILY_WITH_LARGEST_CHILDREN
CREATE DISPLAY_ALL_RECORD
PRINT ZERO_CHILDREN
PRINT MORE_THAN_FOUR_CHILDREN
PRINT MAX
END
Document Page
HIERARCHY CHART
MAIN MODULE
INPUT MODULE CALCULATION
MODULE
OUTPUT MODULE
.
.
CALL
CALCULATION
MODULES
INITIALIZATION
MODULE
FAMILY_WITH_ZER
O_CHILDREN
.
.
CALL INPUT
MODULE
FAMILY_WITH_LAR
GEST_CHILDREN
.
.
CALL INPUT
MODULE
FAMILY_WITH_MOR
E_THAN_FOUR_CHI
LDREN
.
.
CALL INPUT
MODULE
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Defining Diagram
Input Processing Output
READ INPUT 1 PROCESS ALL VALUES
READ
Display number of families
with zero children
READ INPUT 2 If INPUT is invalid display
error message and read
INPUT again
Display number of families
with more than four children
READ INPUT 3 EVALUATE numbers of
families with ZERO children
Display largest number of a
children in a family
. EVALUATE numbers of
families with more than four
children
. EVALUATE largest number
of children that exists in a
family
.
UNTIL INPUT=999
Document Page
REFERENCES
Paul, R. (2015). Critical Thinking: How to Prepare Students for a Rapidly Changing World.
Foundation for Critical Thinking.
Radford, B. (2013). Media Mythmakers: How Journalists, Activists, and Advertisers Mislead Us.
Prometheus Books
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]