$20
Design a class to keep track of a book. Each book has a title, year, and an author. Your class must include the following constructors and functions (function names and prototype must match exactly):
• Book()
o A constructor that initializes a book to the default values: ("***", 0, "***").
• Book(string newTitle, int newYear, string newAuthor);
o A constructor that initializes a book’s title, year, and author to the specified parameters.
• Book(string allData)
o A constructor that splits the string specified (allData ) into the three book properties. The string is in the following format:
§ title|year|author
§ Example:
"The Hitchhiker's Guide to the Galaxy|1979|Douglas Adams"
• Setters (mutators) for all three member variables (e.g. setTitle)
• Getters (accessors) for all three member variables (e.g. getTitle)
• bool matchTitle(string targetTitle)
o Returns true if targetTitle is part of the book title o Using the example above it should return true if targetTitle is "galaxy", "GUIDE tO", "the hit", etc.
• bool matchAuthor(string targetAuthor)
o Returns true if targetAuthor is part of the name of the lead author o Using the example above it should return true if targetTitle is "Doug", "LAS", "aDaMs", etc.
• bool matchYear(string targetYear)
o Returns true if targetYear matches any part of the year.
o Using the example above it should return true if targetYear is "79", "19", or "1979" etc.
• bool match(string target);
o Returns true if target can be found any where in the book member variables § Using the example above it should return true if target is "97",
"douglas", "hitch", etc.
Write a main program to test all the functions.
Project Files:
Divide your project into three files:
• book.h
o Contains the class definition
• book.cc
o Contains the class implementation (all the functions)
• book_main.cc
o Main program to test your class Compiling your project:
1. g++ -Wall -c book.cc
• This creates the object file book.o
2. g++ -Wall -c book_main.cc
• This creates the object file book_main.o
3. g++ book.o book_main.o
• This creates the executable a.out
or
g++ -Wall -std=c++11 -c book.cc book_main.cc
There is a Makefile provided to allow you to compile your program using the command:
make
If you are using C++11 add the option –std=c++11 to your compile commands.
Hints:
• Start early. You may start by putting everything in one file and separate them later.
• Implement the getters, and setters functions first then start implementing the match functions one at a time. Test every function immediately after you write it.
• You may want to implement an output function to test your objects.
• Review the string functions. They will be useful in this project.
• Write a function that converts a string to all lower case.
• The function stoi allows you to convert a string object to an integer. It requires compiling your program with -std=c++11 option. int x = stoi("123"); will return the integer 123
• The function to_string converts a number to string. string s = to_string(123); will set s to the string "123"
For the third constructor, use the find and the substr string member functions