Lab 7
Objectives:
Use strings and file I/O
The assignment contains two parts.
Use multiple files and create a makefile for each. Name the main function code as specified.
Book Notices:
Write a program, Lab7_notice, that asks the user for the mailing information and prints a letter for an overdue
book. The dialog should be as follows- one line per prompt and answer:
last name: William
first name: Schmidt
middle name: John
house number: 1825
street name: Silver Lane
city: Fresno
state: CA
zip code: 93704
overdue book: The History of Rome
days overdue: 15
cost of replacement: $189.95
You are to generate the following letter for the output:
===================
= OVERDUE =
= The History of Rome =
===================
William J. Schmidt
1825 Silver Lane
Fresno, CA 93704Dear William:
The above book is overdue by 15 days. Please return the book and pay the fine of $3.75 (15 days X $.25 per day) or we will charge you for the replacement of the book, $189.95. We look forward to hearing from you immediately so no additional fines will be incurred.
Sincerely,
The Town Library
In the body of the notice, days overdue (15 in this case) is inserted at two places. The fine is calculated as days overdue times $.25. The replacement charge is from the input.
You may assume that the person's data is available except for the middle name. If the middle name is present, on
the address label it has to be shortened to only the initial followed by a period. If the middle name is not present,
the user inputs _ (underscore). The underscore should not be printed in the label. Note that there has to be a
comma after the city name.
The symbols that make up the frame of the overdue notice at the top of the letter should meet the following specifications:
1) For the output of the longer of the book title and the word OVERDUE, the line should be
= XXXXXXX =
where XXXXXXX is the book title or the word OVERDUE, one blank appears before and after the word,and "=" appears on either side.
2) The shorter of the book title or the word OVERDUE, should be centered in the horizontal space occupied by = XXXXXXX =
3) The line of equal signs, "=====...==" should nicely frame the words as shown.
You may not make the frame too large. That is, you have to adjust the frame size to fit the longest line (either the book title or the word OVERDUE ) plus the two additional characters on each end of a blank and an equal sign.
Hints: To make the notice line up as given, count the letters in the book name (including spaces) and decide whether
it is larger than the word OVERDUE or not. This would allow you to calculate the length of the label box. Output
appropriate number of spaces in the shorter line to pad it to the right size so that the "="s and "|"
are aligned.
To store the information about each customer, you could declare a collection of strings:
string lastName, firstName, ... , state, zipCode, etc.
You can either form lines of the address in the letter to be output in strings:
string labelLine2 = "* " + firstName + " " + ...
and then output the formed strings, or you can form output directly by
stacking the insertion operators.
File. Create
a project titled Lab7_File. Repeat the assignment assuming that the input comes from a file such as this one . Note that you must
now handle more than one letter. Save the file in your computer (cut-and-past is acceptable) in a file database.txt.
The output of your program should go to a different file named notice.txt You may reuse the code from the first
part of the lab assignment. You may assume that in the input file, the fields are always named the same and the
order of the fields is the same. There are no blank lines. The labels used in the prompts are NOT in the data file.
However, the data in the fields of the file may change on an official run. That is, you may not program your assignment
such that it works with the names and addresses only in the provided example file.
Make sure your programs adhere to proper programming style. Submit your projects to the subversion repository.
Do not forget to verify your submission on the web.