Up Next
Go up to Homework
Go forward to Homework 2

Homework 1

For this exercise set, send your answers to me in an email message no later than 10pm Thursday 9/6. If you only have partial answers, or answers you are not sure of, send them in anyway and point out any places where you had problems. I won't assign grades to these but I will try to look them over and comment by email or in class on anything you have questions about or difficulty in answering.

You may want to work in groups on these exercises. This is fine as long as you don't depend too much on other members of the group--you may encounter similar questions when you take the exam, and you'll be on your own then. Include the names of all members of the group in any email you send me, and cc the message to all members; I'll do the same with my replies.

Do Exercises 2.10, 3.1, 3.3 from Accelerated C++.

In case you don't have this book yet, the text of these exercises is reproduced below. However, you should obtain the book as soon as possible so that you can do the reading assignments in it. What is an acceptable answer to an exercise from the book depends in part on the context provided by the discussion in the book. For example, a solution to Exercise 3.3 written in C, or even in C++ without making good use of the C++ Standard Library, would not be an acceptable solution. The book places strong emphasis on making effective use of the library as well as the non-C features of C++, and any programs you write in response to the book's exercises (or any other assignments in this course) should reflect that emphasis, even if the assignment doesn't explicitly call for it. In future homework assignments it will be assumed that you have the book and the text of exercises taken from it will not be reproduced here.

2-10.
Explain each of the uses of std:: in the following program:
int main()
{
    int k = 0;
    while (k != n) {     // invariant: we have written k asterisks so far
        using std::cout;
        ++k;
    }
    std::cout << std::endl; //std:: is required here
}
3-1.
Suppose we wish to find the median of a collection of values. Assume that we have read some of the values so far, and that we have no idea how many values remain to be read. Prove that we cannot afford to discard any of the values that we have read. Hint: One proof strategy is to assume that we can discard a value, and then find values for the unread--and therefore unknown--part of our collection that would cause the median to be the value that we discarded.
3-3.
Write a program to count how many times each distinct word appears in its input.


 

Up Next