Quiz 3 Pseudocode Exercises for CMSC 131 Spring 2005, Study notes of Computer Science

Information about quiz 3 for the cmsc 131 spring 2005 course, including instructions, exercise list, and examples. Students are required to write pseudocode for various programming problems, such as computing the number of digits in an integer, determining if a sequence is decreasing, and generating a multiplication table.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-xgz
koofers-user-xgz 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 131 Spring 2005 Quiz 3 Worksheet
The third Quiz of the course will be on Wednesday, Feb 16 during your lab (discussion)
session. 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 last semester’s quiz solution at the end. Take a look at it so
you get an idea of the pseudocode we expect.
The following exercises include the material to be covered in Quiz #3. Solutions to these
exercises will not be provided, but you are welcome to discuss your solutions with TAs
and instructors 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 number of digits in an integer.
For example, for the integer 1776 the program will return 4.
2. Write pseudocode for a program that computes the average of a set of values after
the highest and lowest scores have been removed.
3. 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

Partial preview of the text

Download Quiz 3 Pseudocode Exercises for CMSC 131 Spring 2005 and more Study notes Computer Science in PDF only on Docsity!

CMSC 131 Spring 2005 Quiz 3 Worksheet

The third Quiz of the course will be on Wednesday, Feb 16 during your lab (discussion) session. 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 last semester’s quiz solution at the end. Take a look at it so you get an idea of the pseudocode we expect.

The following exercises include the material to be covered in Quiz #3. Solutions to these exercises will not be provided, but you are welcome to discuss your solutions with TAs and instructors 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 number of digits in an integer. For example, for the integer 1776 the program will return 4.
  2. Write pseudocode for a program that computes the average of a set of values after the highest and lowest scores have been removed.
  3. 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

  1. Write pseudocode for a program that displays 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 like the following:

1 2 3 4

1 1 2 3 4

2 2 4 6 8

3 3 6 9 12

4 4 8 12 16

  1. 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:


  1. Write pseudocode for a program that prints a line of text centered in a particular field width. The program takes as input a string and the size of the field where the text will be displayed. The program will generate a new string with the original string centered on the specified field width.
  2. Write pseudocode for a program that computes the atomic weight of a compound based on the compound formula. For simplicity assume only the following three 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.