0% found this document useful (0 votes)
696 views

Assignment #5 (2%) : CSD 1133 Problem Solving/Program Logic

The document provides instructions for two programming assignments. Assignment 1 involves writing a program that takes in test scores for multiple students, calculates the average score for each student, and calculates an overall class average. Assignment 2 involves simulating dealing cards from a deck and counting the number of cards from each suit that are dealt over 1,000 simulations. Pseudocode and flowcharts are provided to help with Assignment 1, while pseudocode is provided to help with Assignment 2.

Uploaded by

prabh kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
696 views

Assignment #5 (2%) : CSD 1133 Problem Solving/Program Logic

The document provides instructions for two programming assignments. Assignment 1 involves writing a program that takes in test scores for multiple students, calculates the average score for each student, and calculates an overall class average. Assignment 2 involves simulating dealing cards from a deck and counting the number of cards from each suit that are dealt over 1,000 simulations. Pseudocode and flowcharts are provided to help with Assignment 1, while pseudocode is provided to help with Assignment 2.

Uploaded by

prabh kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CSD 1133 Problem Solving/Program Logic

Assignment #5 [2%]
Chapter 6: More about Loops and Decisions

Other Instructions will be provided by the instructor

Question 1: Draw flowchart and write a program – Flowchart + Pseudocode

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

Declare StudentCount As Integer

Declare Name As String

Declare Score1, Score2, Score3, Score4, sumAverage, classAverage As Float

//Function calls

Call initial_values(classAverage, studentCount, sumAverage)

Call student_average(sumAverage, StudentCount, Score1, Score2, Score3, Score4)

Call class_average(classAverage)
End program

End Module

//initial_values module

Module initial_values

Set classAverage = 0

Set StudentCount= 0

Set sumAverage = 0

End initial_values Module

//student_average module

Module student_average

Write"Enter the name of the student or z to quit: "

input Name

for (Name != "z")

Set StudentCount = StudentCount + 1

Write"Enter score1: "

input Score1

Write"Enter score2: "

input Score2

Write"Enter score3: "

input Score3

Write"Enter score4: "

input Score4

average = (Score1 + Score2 + Score3 + Score4) / 4

sumAverage = sumAverage + average

Write"The average score for "+ Name + "is" + average +"."

Write"Enter another student name or z to quit: "

input Name

End student_average Module


//class_average module

Module class_average

Set classAverage = sumAverage / StudentCount

Write"The average of class is " + classAverage + "."

End class_average Module

Question 2: Programming – Pseudocode + Python Code

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.”

Output should look like:


C 255
D 230
H 275
S 240
----
1000

 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

You might also like