| CS 451 | Willamette University | Spring, 2019 |
|
Topics in Computer Science:
Operating Systems and Concurrency |
||
Supplemental Problems extend the range of problems considered in the course and help sharpen problem-solving skills. Through the semester, several supplemental problems will be required.
The very beginning of every lab, project, and supplemental problem must contain the following lines:
/***********************************************************************
* Name(s) (identify both lab partners for labs, projects) *
* Box(s): *
* Assignment name (Lab, Project, Sup. Problem Number _______) *
* (25% off if name/number does not match assignment) *
* Assignment for <due date>; *
***********************************************************************/
/* *********************************************************************
* Academic honesty certification: *
* Written/online sources used: *
* [include textbook(s), CS 451 labs or readings; *
* complete citations for Web or other written sources *
* write "none" if no sources used] *
* Help obtained *
* [indicate names of instructor, class mentors *
* or evening tutors, consulted according to class policy; *
* write "none" if none of these sources used] *
* ["none" or the instructor's name for Supplemental Problems *
* My/our signature(s) below confirms that the above list of sources *
* is complete AND that I/we have not talked to anyone else *
* (e.g., CSC 161 students) about the solution to this problem *
* *
* Signature: *
***********************************************************************/
No coursework can be accepted, if this certification is incomplete or if the statement is not signed by ALL collaborators involved.
Since every programming task should yield readable and carefully tested code, the grading of all programs for this course will begin with the following algorithm (expressed in C format):
if ((no_comments)
|| (missing pre- or post-conditions)
|| (formatting_does_not_show_structure)
|| (long_procedures_not_divided_into_sections_with_clarifying_comments)
|| (no_evidence_of_compilation)
|| (no_test_plan,__no_listing_of_circumstances__OR__no_listing_of_test_cases)
|| (no_test_runs)
|| (no_commentary_on_correctness)
|| (no_signed_certification_regarding_sources_and_help)
|| (use of Bubble Sort or non-approved sorting algorithm)
return (no_grade);
Global constants (identifiers declared with const) may be used in any supplemental problems. As an example, any solution to a supplemental problem may include scale-notes.h, which includes declarations, such as
const int pitchA0 = 27;
Use of global variables is expressly forbidden (although global constants are allowed).
When a program and its output are submitted according to the above instructions, it should be understood that any output was generated by the program as given, unless explicit comments indicate changes that might have been made. Discrepancies between a program and an output file may raise questions of academic dishonesty; and, by College policy, any evidence of academic dishonesty must be turned over to the Academic Standing Committee for action.
The game of Scrabble is a word game, in which players place letters on a grid to form words. For this problem, after the first word is placed on the board, subsequent words must intersect one or more existing words. In the game, letters from a player are connected to letters already on the board to form words. Many descriptions of the game are available online, including a reasonably thorough discussion on Wikipedia.
This problem considers the addition of a word to the board, where a new word will intersect with an existing word. For example, consider the following grid:
P R O G R A M
M E M O R Y
N E T W O R K
S Y S T E M E
S T R I N G A N T I Q U E
O L U
C O L L E G E A
T P A D E T S
H H L L B I C
E Y C E R O H I O
O S U A N E
G R I N N E L L M
Y C U E
S S
This grid contains numerous words arranged horizontally or vertically, and each word is connected to one or more other words at various letters. When inserting a word, it is not required that every letter of the new word must form a word with every adjacent letter. For example, the words PROGRAM, MEMORY, NETWORK, SYSTEM and STRING at the top left are positioned along the vertical word POETS. Reading down in the next column from POETS, one gets the sequence RRTET; this is not a word, but that is irrelevant to the rules for this problem.
Within this context, a first word may be placed anywhere on the grid. Thereafter adding a new word requires that the word connect with at least one existing letter already on the grid. If the new word would extend over several existing letters, then the corresponding letters must match. For example, in the illustration, the word RARE could be added vertically using the R in PROGRAM and the R in NETWORK. However, the word RAKE could not be added in this position. The first R would fit with the R of PROGRAM, but the K in RAKE does not match the grid element already on the grid (the R in NETWORK).
This problem asks you to write a program to support the addition of new words for this type of word grid. In particular, the program should do the following.
When the program starts, it should ask for the number R of rows and the number C of columns for the grid, and a blank grid of this size should be created internally. (This blank grid need not be printed.)
rows columns
word H rowi colj
If the user enters a word, followed by a space, the letter V, a space, a number i, a space, and another number j, then the word is to be placed vertically with the first letter at the row i and column j.
word V rowi colj
word R
If the word placement is given and is valid, the word is added to the grid, and the grid is printed. (I.e., the word is added if it intersects with at least one letter already on the board, and the letters match each time the new word intersects an existing one letter in the grid).
If the word placement is not given (letter R is entered), then the word is added to the grid once at any valid position (if such a position exists), and the grid is printed.
If the word cannot be added at the specified location or if no position is possible for an open placement, then an error message is printed.
The program continues to ask the user to enter words until the user enters QUITQUIT, in which case the program stops.
Programming Notes:
/* check if the given word can be added horizontally at the given location
pre-conditions
row is a valid row location within the grid
col is a valid column location within the grid
word is a valid string
num_rows is the total number of rows in the grid
num_cols is the total number of columns in the grid
grid is the two-dimensional array representing the grid
post-conditions
returns true (i.e., 1) if the word can be added to the grid
horizontally with the first letter at the given row and col
returns false (i.e., 0) otherwise
the grid is NOT changed
*/
int check_horizontal (char * word, int row, int col,
int num_rows, int num_cols, char grid[num_rows][num_cols])
/* check if the given word can be added horizontally at the given location
pre-conditions
row is a valid row location within the grid
col is a valid column location within the grid
word is a valid string
num_rows is the total number of rows in the grid
num_cols is the total number of columns in the grid
grid is the two-dimensional array representing the grid
post-conditions
returns true (i.e., 1) if the word can be added to the grid
vertically with the first letter at the given row and col
returns false (i.e., 0) otherwise
the grid is NOT changed
*/
int check_vertical (char * word, int row, int col,
int num_rows, int num_cols, char grid[num_rows][num_cols])
Grading Form
Program namelist-2019-451.c contains a simple framework for maintaining a singly-linked list of names (with no more than 20 characters). The program has these features:
This problem asks you to implement two additional functions within this program.
Function removeDuplicates removes duplicate nodes from the current list:
In this processing,
Function duplicate adds a duplicate of each node after the node on the current list:
In this processing for duplicate,
For example, if the original list had 3 nodes:
Then the new list after duplicate would have 6 nodes:
Programming Hints:
This problem uses multiple processes and a stored file of information to address two questions about gemstones.
Given a color, select all gemstones of the given color, and print them in alphabetical order by gemstone name.
Print all gemstones, whose hardness and specific gravity values are within specified ranges.
Gemstones are attractive forms of rock crystal, commonly used for decoration and in jewelry. Gemstones also have interesting mineral properties. Gemstones may be classified in a variety of ways, including chemical composition, crystal structure, color, specific gravity, refractive index, and hardness:
Chemical Composition: While some gemstones are primarily composed of atoms of one element (e.g., diamonds are mostly carbon, with coloring coming from traces of other elements), other gemstones are made up of atoms of several atoms (e.g., mica molecules include oxygen, hydrogen, silicon, aluminum, iron, and/or many others). On-line sources of information include general references (e.g., Common Mineral Groups) and references to specific minerals (e.g., micas).
Color may be classified informally (e.g., red, yellow, etc.) or more formally by viewing thin slices of mineral crystals through the microscope, using polarized light (see, for example, Minerals under the Microscope).
Specific Gravity is a measure of the density of a mineral. More precisely, specific gravity is the ratio of the weight of the mineral in air to its weight in an equal volume of water. More details are available from various on-line sources (see, for example, the Mineral and Gemstone Kingdom's glossary for specific gravity.
Refractive Index provides a measure of how much light bends within a crystal. The higher the refractive index, the more bending and the more brilliant a crystal is likely to appear. For more information, see various on-line sources, such as Refractive Index.
Crystal Structure: Crystals typically have one of several standard shapes or structures, including cubic, tetragonal, orthorhombic, hexagonal, monoclinic, and triclinic. While the details of such structures are beyond the scope of this problem, the World Wide Web contains many useful references, including crystal forms (at the macro-level).
Hardness often is measured on the (nonlinear) Mohs Scale, which associates a hardness number to each mineral, from 1 (softest) to 10 (hardest):
As a comparison, a fingernail has hardness 2.5, glass has hardness 5.5, and a steel file has hardness 6.5. Minerals of the same hardness should not scratch each other, but a mineral of one hardness will scratch minerals with a lower hardness number.
File gems.txt contains information on several gemstones, including color, hardness, specific gravity, and refractive index. Within the file, each line contains information about a specific gemstone.
Here are a couple of sample lines, and a character 'ruler' to show how wide the fields are:
11111111112222222222333333333344444444445555555555666666666677777
012345678901234567890123456789012345678901234567890123456789012345678901234
Zircon RED 7.5 4.50 1.95
Topaz YELLOW 8 3.53 1.62
To clarify, the names of the gemstones come first in a line and are right-justified in a column of width 22 characters. (A gemstone name may contain multiple words, but the overall width of the name field is 22 characters.) The colors come next, followed by hardness (on a scale 1 to 10), then specific gravity, and finally refractive index (generally between 1.3 and 2.5).
To answer the questions posed at the start of this question, five programs are to be utilized, as described below and as illustrated in the following diagram:
Altogether,
If the user types "GREY" as the color of gemstones, processing should return a table, such as the following:
Specific Refractive
Gemstone Color Hardness Gravity Index
Alabaster GREY 2 2.32 1.53
Bakelite GREY 2.5 1.28 1.65
Calcite GREY 3 2.7 2.71
Casein GREY 2.5 1.33 1.55
Celluoid GREY 2 1.35 1.50
Chalcedony GREY 7 2.62 1.53
Corundum GREY 9 3.99 3.99
Diamond GREY 10 3.52 3.52
Hematite GREY 6 5.10 5.05
Ivory GREY 2.5 1.80 1.54
Jadeite GREY 7 3.34 3.33
Labradorite GREY 6 2.7 2.70
Marble GREY 3 2.71 1.50
Meerschaum GREY 2 1.50 1.53
Nephrite GREY 3.5 3.00 2.96
Opal GREY 6 2.10 2.10
Quartz GREY 7 2.65 1.55
Quartz GREY 7 3.33 2.65
Talc GREY 1 2.70 2.75
Another possible format might be:
Specific Refractive
Gemstone Name Color Hardness Gravity Index
Alabaster GREY 2 2.32 1.53
Bakelite GREY 2.5 1.28 1.65
Calcite GREY 3 2.70 2.71
Casein GREY 2.5 1.33 1.55
Celluoid GREY 2 1.35 1.50
Chalcedony GREY 7 2.62 1.53
Corundum GREY 9 3.99 3.99
Diamond GREY 10 3.52 3.52
Hematite GREY 6 5.10 5.05
Ivory GREY 2.5 1.80 1.54
Jadeite GREY 7 3.34 3.33
Labradorite GREY 6 2.70 2.70
Marble GREY 3 2.71 1.50
Meerschaum GREY 2 1.50 1.53
Nephrite GREY 3.5 3.00 2.96
Opal GREY 6 2.10 2.10
Quartz GREY 7 2.65 1.55
Quartz GREY 7 3.33 2.65
Talc GREY 1 2.70 2.75
As shown in each example, the gemstone names and properties must appear in labeled columns. Gemstone names may be either left-justified or right-justified.
A similar format could be used in printing gemstone information for the second question.
Note that some gemstones, such as Quartz above, appear several times in the table, since variations of a gemstone may have different properties.
Any of the following problems may be done for extra credit. As noted in the course syllabus, however, a student's overall problems' average may not exceed 120%.
Many books state variations of the Sleeping Barber Problem, which was first proposed by Edsger W. Dijkstra in 1968. (E. W. Dijkstra, "Co-operating Sequential Processes", in F. Genuys (ed.), Programming Languages, Academic Press, 1968, pp. 43-112.) This exercise considers the following version:
Three barbers work independently in a barber shop:
The barbershop has 3 barber chairs, each of which is assigned to one barber.
Each customer follows the following sequence of events.
For this problem, you are to write a C program to simulate activity for this barbershop:
[approximately 12 points]
Sometimes one can simplify a problem by removing the parts that don't matter, and then looking at what's left.
For instance if you wanted to figure out if two collections of "stuff" were the same, you might remove matching items from each collection until you see if there are items left over. If you have leftover items, the collections were different, and if both collections become empty at the same time, they are identical.
Use this technique to write a program which will determine whether or not two strings are anagrams of each other. For this program, each string should be entered on a line of its own, with no assumptions regarding the characters entered (except that the characters can be typed on a keyboard and that each string is no longer than 40 characters.
Test it by deciding whether or not "one plus twelve" is an anagram of "eleven plus two", among other test cases.
Note: Two programs, one iterative and one recursive, might be eligible for bonus points.
[Approximately 13 points]
This exercise is a slightly modified version of exercises 4.9 and 4.10 in Stephen Hartley, Concurrently Programming: The Java Programming Language.
An amusement park includes a roller coaster ride. Use of the roller coaster follows these rules.
For this problem, you are to write a C program to simulate activity for this roller-coaster problem:
|
created 20 January 2019 revised 11 February 2019 revised 25 February 2019 revised 6-10 March 2019 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |