The book collection
Problem description
Write a program to maintain a small collection of books, stored with title and author. The program should be able to add a new book, delete an existing book (if it is in the collection) and print the number of books and the contents of the collection.
Procedure
Follow these steps to end up with a sucessful program:
- Write a one sentence problem statement.
- Write the problem description, as given above.
- Do the analysis for object design, ending up with at least three classes (including a class for the application), choosing suitable representations for the class members. Write the object design down.
- Do the analysis for process design, adding suitable function members to your classes with appropriate parameters. The application class with have (at least) a function member
run
.
- Write C++ program code from your analysis in 3 and 4.
- Create a source file using the editor.
- Compile the source code using g++.
- Test the program by inserting code in you application's run function to do the following:
- create an empty collection
- add the books "Dracula" by Stoker; "Relativity" by Einstein; "Frankenstein" by Woolstencraft; and "Foundation" by Asimov, by prompting the user to type in title and author.
- display the collection on the screen.
- delete the book "Relativity" by Einstein (no need to prompt here).
- display the collection again, showing the absence of the deleted book.
- Deliverables:
- your design document with its four sections: problem statement, problem description, object design and process design.
- your source code, suitably commented and with good layout
- the output produced by the program with the tests as given in 8.
- your source code e-mailed to the grader, login name iflores.
Notes and hints
- Keep your classes to the minimum necessary (but at least three in total)
- Keep the member representations as simple as possible. You do not need anything more fancy than base types, a simple array, and the string class which is obtained by including the file "
string
" (note it is not string.h
).
- Keep all data private: use accessor functions to selectively open up access to other classes. Don't use global variables!!
- use this control structure for reading in your books:
read info
while (!cin.eof()) {
store info.
read more info.
}
This give the correct behavior for end of file.
- if an array has an element type which is a declared class, then that class needs a default constructor, so that the array can be constructed (see page 170 of Eckel's book),
- to efficiently compare two objects of a declared class type, the class can have an overloaded
==
operator. e.g. for class X, I could define a comparison operator with:
class X {
private:
int x, y;
public:
bool operator==(const X obj2) {
return x == obj2.x && y == obj2.y;
}
...
};
See page 416 for another example.
- end of input on UNIX is signalled by typing ctrl-D on a line by itself (ctrl-Z in DOS)
- prompt the user for input
- display screen output with reasonable layout
- use
cin
and cout
, not printf
and scanf
- when you are ready to produce the final output of the program, redirect the standard output produced by
cout
into a file by typing:
a.out > outputfile
which you can then print on the lineprinter.
- mail your source code with:
mail iflores < filename.cc