

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CMSC 131 Quiz 3 Worksheet
The third Quiz of the course will be on Monday, Oct 11 during your lab session (either at 10 am or 11 am). The following list provides more information about the quiz:
The following exercises cover 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
4. 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:
1 2 3 4
1 1 2 3 4
2 2 4 6 8
3 3 6 9 12
4 4 8 12 16
5. 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:
This is a bit tricky. An easier variant is to print the histogram bars horizontally.
6. Write pseudocode for a program that prints a line of text centered in a particular field with. 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. 7. 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