YALE UNIVERSITY
DEPARTMENT OF COMPUTER SCIENCE
CPSC 427: Object-Oriented Programming | Handout #2 | |
Professor M. J. Fischer | September 2, 2016 | |
Problem Set 1
Due by 11:55 pm on Monday, September 12, 2016.
You are to write a program called aboutme that, when run, prompts the user to enter their first name, last name, and year of birth. The program then prints out the first name, last name, and age, which we take to be the difference between the current year and the year of birth. Here’s what a sample run for me might look like:
The lines before the first prompt are printed by banner(). The lines after the age line are printed by bye().
Your own code will go into the file main.cpp before and/or after function main(). You will need to define the function run().
We will study later how the try and catch blocks work. This code as written will catch any exceptions thrown by run() or by any function that run() calls. A statement inside run() of the form throw Fatal(format, data1, data2, …) will be caught by the first catch block and will cause the same string to be printed as printf(format, data1, data2, …) would print in C. For example,
throw Fatal("Can’t open file %s", "data.in");
would cause the two lines to be printed:
Catching Fatal exception
Can’t open file data.in
A variable of type string acts just like one would expect. You can store a string literal of any length into it. You can copy one string to another using the assignment operator. You can print it using the << operator and read a whitespace-delimited string into it using the >> operator. A string manages its own storage so that you do not have to worry about allocating storage. You should use string variables to store the first and last names to be read in.
Your assignment will be graded according to the scale given in Figure 1 (see below).
# | Pts. | Item |
1. | 1 | All source code is contained in the single file main.cpp. |
2. | 1 | The source code is an ASCII text file (not a .doc file). |
3. | 1 | main.cpp contains required authorship information. |
4. | 1 | main.cpp #includes the tools header file. |
5. | 1 | main() calls banner() and bye(). |
6. | 1 | main() contains the required try and catch blocks. |
7. | 1 | The only code inside the try block is a call on run() (which you must write). |
8. | 1 | Each function is preceded by a comment that describes briefly what it does. |
9. | 1 | Program uses C++ I/O operators << and >> with standand streams cout and cin. |
10. | 1 | Program uses good() to check for errors after reading input and throws a Fatal exception in case of error. |
11. | 2 | Program correctly computes the current year using time() and localtime() functions. |
12. | 1 | A well-formed Makefile or makefile is submitted that specifies compiler options -O1 -g -Wall -std=c++14. |
13. | 1 | Running make results in an executable file aboutme. |
14. | 1 | There are no compiler warnings when compiled with -Wall. |
15. | 1 | There is a block comment at the bottom of main.cpp that contains the input and actual output from at least one test run of the program. |
16. | 2 | The compiled program, when run on the input data described in the comment at the bottom of main.cpp, yields the same output as in the comment, and that output is correct. (1 point each.) |
17. | 2 | All required files are submitted on classes*v2 as described in lecture 2. |
20 | Total points. |
|