Quiz 2 Worksheet for CMSC 131 Summer 2005 - Pseudocode Exercises, Quizzes of Computer Science

Information about quiz 2 for the cmsc 131 summer 2005 course, including instructions, exercise prompts, and examples. Students are required to write pseudocode for various programming problems, such as computing averages, determining decreasing sequences, generating multiplication tables, creating histograms, calculating atomic weights, and identifying increasing sequences.

Typology: Quizzes

2019/2020

Uploaded on 11/25/2020

koofers-user-1cr
koofers-user-1cr 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 131 Summer 2005 Quiz 2 Worksheet
The second Quiz of the course will be on Friday, Jun 17. The following list provides
more information about the quiz:
You will have 25 minutes to complete the quiz.
It will be a written quiz (not using any computer).
It will be closed-book, closed-notes, and no calculator is allowed.
Answers must be neat and legible. We recommend that you use pencil and eraser.
The quiz will be based on the exercises you will find below. The quiz will ask
you to write pseudocode for a particular problem.
We have provided previous semesters’ quizzes at the end. Take a look at them so
you get an idea of the pseudocode we expect.
The following exercises cover the material to be covered in Quiz #2. Solutions to these
exercises will not be provided, but you are welcome to discuss your solutions with the TA
and the instructor during office hours. Keep in mind that in the following exercises you
are being asked to provide only pseudocode.
1. Write pseudocode for a program that computes the average of a set of values after
the highest and lowest scores have been removed.
2. Write pseudocode for a program that reads a sequence of integer values and determines
whether it is a decreasing sequence. A decreasing sequence is one where each value is
greater than or equal to the next element in the sequence. The program will first read the
number of values to process followed by the values in the sequence. The program will
print the message "Decreasing" for a decreasing sequence and "Non-Decreasing"
otherwise. For example, here are two decreasing sequences:
90 87 30 0 -1 -2
110 4 0 -20
The following are non-decreasing sequences:
90 100 20 4
30 24 -2 -1 8 9
pf3
pf4

Partial preview of the text

Download Quiz 2 Worksheet for CMSC 131 Summer 2005 - Pseudocode Exercises and more Quizzes Computer Science in PDF only on Docsity!

CMSC 131 Summer 2005 Quiz 2 Worksheet

The second Quiz of the course will be on Friday, Jun 17. The following list provides

more information about the quiz:

• You will have 25 minutes to complete the quiz.

• It will be a written quiz (not using any computer).

• It will be closed-book, closed-notes, and no calculator is allowed.

• Answers must be neat and legible. We recommend that you use pencil and eraser.

• The quiz will be based on the exercises you will find below. The quiz will ask

you to write pseudocode for a particular problem.

• We have provided previous semesters’ quizzes at the end. Take a look at them so

you get an idea of the pseudocode we expect.

The following exercises cover the material to be covered in Quiz #2. Solutions to these

exercises will not be provided, but you are welcome to discuss your solutions with the TA

and the instructor during office hours. Keep in mind that in the following exercises you

are being asked to provide only pseudocode.

1. Write pseudocode for a program that computes the average of a set of values after

the highest and lowest scores have been removed.

2. Write pseudocode for a program that reads a sequence of integer values and determines

whether it is a decreasing sequence. A decreasing sequence is one where each value is greater than or equal to the next element in the sequence. The program will first read the number of values to process followed by the values in the sequence. The program will print the message " Decreasing " for a decreasing sequence and " Non-Decreasing " otherwise. For example, here are two decreasing sequences: 90 87 30 0 -1 - 110 4 0 - The following are non-decreasing sequences: 90 100 20 4 30 24 -2 -1 8 9

3. Write pseudocode for a program that display a multiplication table for a range

starting at 1 up to a designated upper limit. For example, for a limit of 4 the table

will look as follows:

4. Write pseudocode for a program that prints a histogram for a set of five values.

For example, for the set of values 2 5 1 3 1 the program will generate the

following histogram:

5. Write pseudocode for a program that computes the atomic weight of a compound

based on the compound formula. For simplicity assume only the following

elements can be part of any compound:

Element Atomic Weight

Ca 20

H 1

N 7

For example, the weight of the component 2Ca3N will be 40 + 21 → 61.

Examples of other possible components are: Ca3N4H3N, 2H, CaHN

6. Note: This problem was a previous quiz. The solution has been provided at the

end.

Write pseudocode for a program that reads a sequence of unique integer values and determines whether it is an increasing sequence. An increasing sequence is one where each value is greater than the preceding one. The sequence will be terminated by the special value -999, which is not considered to be part of the sequence. The program will print the message " Increasing " for an increasing sequence and " Non-Increasing " otherwise. For example, here are two increasing sequences: 2 45 90 134 -

Problem 6 One possible solution increasing = true prev = read() do { curr = read() if ( curr != -999 ) { if ( curr <= prev ) then increasing = false else prev = curr } while (increasing and curr != 999 ) if ( increasing ) then print(“Increasing”) else print(“Non-Increasing”) Problem 7 One possible solution sum = 0 number = read() curr = 0 while (curr < number) { x = read() if (curr is even) { _OR_ if (x is even) { sum += x } curr++ } print(sum)