COMS W3101-2
Homework 3: Functions, Templates, Classes, and Error Handling
Worth: 20% of total homework grade.
Goals:
The goal of this homework is to give you practice creating functions, creating classes, and handling errors with the C++ exception mechanisms.
Assignment:
-
hw3a.cc
(30%)
Make three functions taking an double as input:
- A function to calculate the area of a square given the length of one side.
- A function to calculate the area of a circle given the diameter
- A function (that uses the first two functions) to calculate the black area in the figure below, given the length of one side:
Finally, write a main function that asks the user for the length of the square's side and prints out the black area.
-
hw3b.cc
(20%)
Rewrite hw3a.cc so function 3 tests for:
- negative input
- non-numeric input
and throws exceptions for these two cases.
Have your main function call function 3 in try/catch block requesting a positive number to be entered instead.
-
hw3c.cc
(50%)
Write a class for use as an email header.
Your class should contain the following information:
- To: the field holding the addresses to which the email was sent
- From: the field holding the address from which the email was sent
- Subject: the email subject
- Date: the month, day, and year (all integer values - this should be encapsulated in a struct named Date - if you do not use a struct points will be deducted)
Override the input and output operators to take in your class and print it out.
input format:
Bob@us.gov
reich@cs.columbia.edu
how are you doing?
4 5 2006
ouput format:
TO: Bob@us.gov
FROM: reich@cs.columbia.edu
SUBJECT: how are you doing?
DATE: 4/5/2006
Finally, write a main function that asks the user:
input a new header
A single header is inputed by the user, after which the program should
print out a message "### HEADERS BELOW ####", followed by the header.
(use the input/output format specified above).
Files to be submitted:
- hw3a.cc
- hw3b.cc
- hw3c.cc
- typescript
- REAMDE
Remember, all source code files should be clearly commented.
Code should be clean and easily readable.
Errors should be checked or handled according to your current knowledge-base.
If your files are not named according the above conventions, they will not be graded and you will receieve NO CREDIT.
For README and typescript requirements, look in the "How To" section.
How To:
Make your submission
Write a README
Make a typescript
Use CUNIX
Joshua Reich reich@cs.columbia.edu
Last Modified: March 20, 2006