[Solved] CS2400 Homework 7-Book class

$25

File Name: CS2400_Homework_7-Book_class.zip
File Size: 263.76 KB

SKU: [Solved] CS2400 Homework 7-Book class Category: Tag:
5/5 - (1 vote)

Design classes, search strings, tokenizing strings, string member functions, and separate compilation.

Important:

This is the first part of your final project. The Book class will be used in the second part of this project. Do not change the function names or their prototypes. Also, use the same file names given in the repository on GitHub (book.h, book.cc).

You may use any function or library discussed in class or in the chapters we covered from your textbook. Do not use any other libraries or functions.

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 books 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 Hitchhikers 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)

  • Returns true if targetYear matches any part of the year.
  • 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:

  • h
    • Contains the class definition
  • cc
    • 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 o
  2. g++ -Wall -c book_main.cc
    • This creates the object file 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 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 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.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS2400 Homework 7-Book class
$25