CSC161 2010F Imperative Problem Solving

Exam 1: Basic Concepts

Assigned: Wednesday, 22 September 2010

Due: 11 p.m., Wednesday, 29 September 2010

Preliminaries

Exam Format

This is a take-home examination. You may use any time or times you deem appropriate to complete the exam, provided you return it to me by the due date.

There are five problems on this examination. They are not necessarily of equal difficulty. Each problem may include subparts. Five correct or mostly-correct solutions will earn you an A. Four correct or mostly-correct solutions will earn you a B. Three correct or mostly-correct solutions will earn you a C. Two correct or mostly-correct solutions will earn you a D. One or Zero correct or mostly-correct solutions will earn you an F. Failure to attempt the exam will earn you a 0. Partially-correct solutions may or may not earn you a partial grade, at the discretion of the grader.

Read the entire exam before you begin.

I expect that someone who has mastered the material and works at a moderate rate should have little trouble completing the exam in a reasonable amount of time. In particular, this exam is likely to take you about four hours, depending on how well you've learned the topics and how fast you work. You should not work more than six hours on this exam. Six hours of work, documented attempts on all five problems, and a signed statement that There's more to life than computer science will earn you at least a C on this exam.

I would also appreciate it if you would write down the amount of time each problem takes. Each person who does so will earn a modicum of extra credit.

Academic honesty

This examination is open book, open notes, open mind, open computer, open Web. However, it is closed person. That means you should not talk to other people about the exam. Other than as restricted by that limitation, you should feel free to use all reasonable resources available to you.

As always, you are expected to turn in your own work. If you find ideas in a book or on the Web, be sure to cite them appropriately. If you use code that you wrote for a previous lab or homework, cite that lab or homework and the other members of your group. If you use code that you found on the course Web site, be sure to cite that code. You need not cite the code provided in the body of the examination.

Although you may use the Web for this exam, you may not post your answers to this examination on the Web. And, in case it's not clear, you may not ask others (in person, via email, via IM, by posting a please help message, or in any other way) to put answers on the Web.

Because different students may be taking the exam at different times, you are not permitted to discuss the exam with anyone until after I have returned it. If you must say something about the exam, you are allowed to say This is among the hardest exams I have ever taken. If you don't start it early, you will have no chance of finishing the exam. You may also summarize these policies. You may not tell other students which problems you've finished. You may not tell other students how long you've spent on the exam.

You must include both of the following statements on the cover sheet of the examination.

  1. I have neither received nor given inappropriate assistance on this examination.
  2. I am not aware of any other students who have given or received inappropriate assistance on this examination.

Please sign and date each statement. Note that the statements must be true; if you are unable to sign either statement, please talk to me at your earliest convenience. You need not reveal the particulars of the dishonesty, simply that it happened. Note also that inappropriate assistance is assistance from (or to) anyone other than Professor Rebelsky (that's me).

Presenting your work

You must present your exam to me in two forms: both physically and electronically. That is, you must write all of your answers using the computer, print them out, number the pages, put your name on the top of every page, and hand me the printed copy. You must also email me a copy of your exam. You should create the emailed version by copying the various parts of your exam and pasting them into an email message. In both cases, you should put your answers in the same order as the problems. Failure to name and number the printed pages will lead to a penalty of two points. Failure to turn in both versions may lead to a much worse penalty.

In many problems, I ask you to write code. Unless I specify otherwise in a problem, you should write working code and include examples that show that you've tested the code. Do not include images; I should be able to regenerate those.

Unless I explicitly tell you not to document a procedure, you should assume that you must document every procedure you write.

Just as you should be careful and precise when you write code and documentation, so should you be careful and precise when you write prose. Please check your spelling and grammar. Since I should be equally careful, the whole class will receive one point of extra credit for each error in spelling or grammar you identify on this exam. I will limit that form of extra credit to five points.

I may give partial credit for partially correct answers. I am best able to give such partial credit if you include a clear set of work that shows how you derived your answer. You ensure the best possible grade for yourself by clearly indicating what part of your answer is work and what part is your final answer.

Getting help

I may not be available at the time you take the exam. If you feel that a question is badly worded or impossible to answer, note the problem you have observed and attempt to reword the question in such a way that it is answerable. If it's a reasonable hour (before 10 p.m. and after 8 a.m.), feel free to try to call me in the office (269-4410) or at home (236-7445).

I will also reserve time at the start of each class before the exam is due to discuss any general questions you have on the exam.

Problems

Problem 1: Tallying Common Letters

Topics: Tallying, Input, Characters

Write a program that reads text from input and prints out a histogram of the number of occurrences of the twelve most commonly occurring letters in the English language. (In case you didn't know, those letters are ETAOIN SHRDLU.) You should treat lowercase and uppercase letters identically.

Problem 2: Classifying Triangles

Topics: Conditionals, Simple arithmetic

Write a program that takes three numbers on the command line, interprets those numbers as side lengths, and describes the triangle given by those numbers. If the side lengths do not represent a triangle, indicate so. For valid triangles, the options are

You should also indicate whether the triangle is right, acute, or obtuse.

Problem 3: Reverse Polish Notation, Revisited

Topics: Stacks, Input, Output, Arrays

In a recent assignment, you wrote a program that interpreted reverse polish notation, taking the input either from a predefined array or from the command line.

Rewrite that program so that it takes its input from standard input. You should support one additional operation, p, that prints out the top of the stack. For example,

% rpn
3 p
3
4 p
4
+ p
7
5 * p
35

Problem 4: Interpreting Bits

Topics: Command-line processing, Integer representations

Write a program that reads in eight bits (character '0' or character '1') and then prints out the value of those bits in

For example,

% interpret 0 0 0 0 0 0 0 1
Unsigned:            1
Signed magnitude:    1
One's complement:    1
Two's complement:    1
Excess 128:       -127
% interpret 1 1 1 1 0 0 0 0
Unsigned:          240
Signed magnitude: -112
One's complement:  -15
Two's complement:  -16
Excess 128:        112

Problem 5: Floating-Point Exponents

Topics: IEEE floating-point representation, Bitwise operations

Write a program that reads in a 32-bit floating-point number (a float) and prints out the exponent portion (as an integer). For example,

% ./ieee-exponent 1
For float 1.000000, the exponent is 0.
% ./ieee-exponent 2
For float 2.000000, the exponent is 1.
% ./ieee-exponent 0.5
For float 0.500000, the exponent is -1.
% ./ieee-exponent 7.56
For float 7.560000, the exponent is 2.
% ./ieee-exponent 127.5
For float 127.500000, the exponent is 6.
% ./ieee-exponent 128.6
For float 128.600006, the exponent is 7.

To solve this problem, you will likely need to do the following:

To convert from float to int while preserving the bits, you can use the following procedure.

int
f2i (float f)
{
  return *((int *) &f);
} // f2i

Questions

Here you will find answers to questions of general interest. Please check here before emailing your questions!

Errata

Here you will find errors of spelling, grammar, and design that students have noted. Remember, each error found corresponds to a point of extra credit for everyone. We usually limit such extra credit to five points. However, if I make an astoundingly large number of errors, then I will provide more extra credit.

 

History

Tuesday, 21 September 2010 [Samuel A. Rebelsky]

  • Created.

Wednesday, 22 September 2010 [Samuel A. Rebelsky]

  • Minor updates.

Monday, 27 September 2010 [Samuel A. Rebelsky]

  • Inserted more error corrections. Consistency is the hobgoblin of small minds.

 

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Mon Sep 27 08:27:06 2010.
The source to the document was last modified on Mon Sep 27 08:27:04 2010.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CSC161/2010F/Exams/exam.01.html.

Samuel A. Rebelsky, rebelsky@grinnell.edu