Assignment #5 (2%) : CSD 1133 Problem Solving/Program Logic
Assignment #5 (2%) : CSD 1133 Problem Solving/Program Logic
Assignment #5 [2%]
Chapter 6: More about Loops and Decisions
Alberta Einstein teaches a business class at Podunk University. To evaluate the students in this class,
she has given four tests.
It is now the end of the semester and Alberta asks you to Draw flowchart and write a program that inputs
each student’s test scores and outputs the average score for each student and the overall
class average.
(Hint: The outer loop should allow for Ms. Einstein to input all the students, one by one, and the inner
loop should accept the three exam scores and compute the average for each student.)
FLOWCHART
assignment5.rap
PSEUDOCODE
Main Module ()
//declare variables
//Function calls
Call class_average(classAverage)
End program
End Module
//initial_values module
Module initial_values
Set classAverage = 0
Set StudentCount= 0
Set sumAverage = 0
//student_average module
Module student_average
input Name
input Score1
input Score2
input Score3
input Score4
input Name
Module class_average
Write a program that will simulate the process of dealing cards from a 52-card deck by generating
1,000 random integers in the range 1–52.
Assume that numbers 1–13 represent clubs, 14–26 represent diamonds, 27–39 represent hearts, and
40–52 represent spades. Display the number of times each suit occurred in the 1,000 “deals.”
PSEUDOCODE
Main Module ()
//declare variables which store counts
Declare clubsCount, diamondsCount, heartsCount, spadesCount As Integer
//declare variable that store random number
Declare Number As Integer
//declare variable for loop
Declare i As Integer
//Function calls
Call getting_values
Call calc_Count
Call print_data
End Program
End Module
//getting_values module
Module getting_values
Set clubsCount = 0
Set diamondsCount = 0
Set heartsCount = 0
Set spadesCount = 0
End getting_values Module
//calc_Count module
Module calc_Count
for(i=1; i<=1000;i++)
Number= Floor(Random*52)+1
If ((Number >= 1)AND(Number <= 13))Then
Set clubsCount = clubsCount + 1
Else If (Number >= 14)AND(Number <= 26))Then
Set diamondsCount = diamondsCount + 1
Else If (Number >= 27)AND(Number <= 39))Then
Set heartsCount = heartsCount + 1
Else If (Number >= 40)AND(Number <= 52))Then
Set spadesCount = spadesCount + 1
End If
End for(i)
End calc_Count module
//print_data module
Module print_data
Write("C "+ clubsCount)
Write("D "+ diamondsCount)
Write("H "+ heartsCount)
Write("S "+ spadesCount)
Write(" ---------")
Write(" 1000")
End Module
PYTHON