Introduction to Computer Programming: C++

Assignment #2, Book and Student classes

Due

Thursday, 16th October at noon

Overview

For this project you will implement two classes, a Book class and a Student class. Your Book class will have the following fields (or member variables):

  1. int bookNumber
  2. char* bookName
  3. char* authorName
  4. bool checkedOut
You will also create a Student class that can check out Books. Your Student class will have the following fields (or member variables):
  1. int studentID
  2. char* name
  3. Book* currentBook
As you can see, the Student can only check out one book at a time. If the student has no book checked out, then currentBook should be NULL.

Instructions

  1. Write a file Book.h that defines the Book class. It needs the following functions:
    1. Book(int num, char* bkName, char* authName)
      Constructor which initializes the book.
    2. ~Book()
      Destructor. Does it need to do anything? If so, also write a copy constructor and an operator= method for your class.
    3. int getBookNumber() const, char* getBookName() const, char* getBookAuthor() const
      Accessor functions for the data members.
    4. bool isAvailable() const
      Returns true if the book is not checked out, and otherwise true.
    5. void setBookNumber(int num)
      Mutator function to change the book number.
    6. void displayBook() const
      Output function which displays the book details to standard out.
    7. bool checkOut()
      Checks out the book from the library, if possible (returns true if succeeded with check out).
    8. bool checkIn()
      Checks in the book to the library, if possible (returns true if succeeded with check in).
    9. bool equals(Book const & book) const
      Return true if the current object and the parameter object represent the same book.
  2. You will need a file called Book.cpp that implements the above functionality.
  3. Write a file Student.h that defines the Student class. It needs the following functions:
    1. Student(int num, char* sName)
      Constructor which initializes the student.
    2. ~Student()
      Destructor. Does it need to do anything? If so, also write a copy constructor and an operator= method for your class.
    3. int getStudentID() const, char* getName() const
      Accessor functions for the data members.
    4. bool hasABook() const
      Returns true if the student currently has a book checked out, otherwise false.
    5. void setStudentID(int num)
      Mutator function to change the student ID.
    6. void displayStudent() const
      Output function which displays the student details to standard out.
    7. bool checkOutBook(Book* book)
      Checks out the book from the library, if possible (returns true if succeeded with check out).
    8. bool checkInBook()
      Checks in the book to the library, if possible (returns true if succeeded with check in).
    9. bool equals(Student const & stud) const
      Return true if the current object and the parameter object represent the same student.
  4. You will need a file called Student.cpp that implements the above functionality.
  5. You will use these classes in a main function inside testLibrary.cpp to test the functionality of your Book and Student classes. The main file I provide already reads from an input file such as library.in. Note that each line beginning with "Book" should create an object of the Book class, with the given fields. A line beginning with "Student" describes an action taken by a student. If you have not seen the student before, you must create an instance of the Student class, and then perform the proper action on the Student object in regards to checking in or out. You should maintain a list of Books and a list of Students - you can use either an array or a vector - whatever you wish. I recommend creating your Books and Students on the heap, i.e. your lists can contain pointers to Books and pointers to Students, respectively, and you use "new" to create them. You should also implement one separate method called printLibrary that can print your list of books, and whether each is available or not (define the parameters to this method that best fits your design). You will see the line "Print library" in the input file that would then tell your program to call this method. After each action taken by a student, please print the details of that Student (call their displayStudent method). In general, you can create other helper methods inside testLibrary.cpp if you want, and if it makes your code easier to organize or more readable.
  6. Compile and run your code in Visual Studio. Use Build Solution and Start With Debugging or Start Without Debugging.
  7. When you're happy with your code, turn in a folder labeled Library_[yourlastname]of all of your files to DropBox in Minerva the following files: Book.h, Book.cpp, Student.h, Student.cpp, and testLibrary.cpp to the DropBox in Minerva. Make sure your name is on the top of each file. You can turn in your files as many times as you want to Minerva; I will only take the last one submitted.

Submission Checklist

Extra Credit (+6%)

Answer the following questions in written form in comments after your name at the top of testLibrary.cpp. For the implementation questions, implement them in the appropriate file.