辅导Patron​ class和Book​ class 程序、辅导C语言图书馆 Library程序

- 首页 >> C/C++编程


Task 1

This task will have you create a simple piece of software that simulates a Library. We will start

by creating a Book class, and a Patron class. Once we have built those classes we can then

use them as building blocks to implement our rudimentary library. For each task, make sure

that you test your code to make sure it works before moving on to the next one.

Task 1.1

Implement a Book class. The book class should have the following have private member variables

for the ISBN (store as a string), title, author and whether or not the book is checked out or not.

● Write a constructor that assigns values to each member variable as well as a default

constructor that leaves data uninitialized.

● Write public methods for retrieving these data values.

● Write a public method for checking a book in and out.

● Write a public method -- istream& read_book(istream& is);

○ We will use this function to load a single book’s data into a Book object.

○ This method will read a Book’s data in the following form

( Title: "Blah Blah" ) ( ISBN: ###-########## ) ( Author: Jane Doe )

Task 1.2

Add operators for the Book class. Have the == operator check whether the ISBN numbers are the

same for two books. Have != also compare the ISBN numbers. Have << print out the title, author,

and ISBN on separate lines. ==, != should be class methods, and << must be a function.

Task 1.3

Create a Patron class for the library. The class will contain a user’s name and library card number

as private member variables.

● Write a constructor that assigns values to each member variable as well as a default

constructor that leaves data uninitialized.

● Write public methods that access this data.

● Write a public method -- istream& read_patron(istream& is);

○ We will use this function to load a single patron’s data into a Patron object.

○ This method will read a Patron’s data in the following form

( Name: John Smith ) ( Number: #### )

Task 1.4

Create a Transaction struct that contains a Book and a Patron as member variables.

CSCI 1300

Summer 2018

Assignment 6

Task 1.5

Create a Library class. It should contain vectors of Books, Patrons, and Transactions.

● Write a constructor that takes two filenames as arguments

○ The first filename will refer to a file containing a list of books (one per line)

○ The second will refer to a file containing a list of patrons (one per line)

○ The file formats will be the same as described in Tasks 1.1 and 1.3

○ You should read each file and populate the Book and Patron vectors

● Write methods that add Books and Patrons to the library system.

● Write a method to let a Patron check out a Book

○ Use a Library card number and ISBN as inputs

○ If the number isn’t in our list of Patrons, then print out an error message and exit

the function

○ If the book is already checked out, then print out an error message and exit the

function

○ Otherwise, add a Transaction to the system.

● Write a method to check in a Book

○ If the Book wasn’t check out to begin with, print out an error message and exit

the function.

○ Otherwise, set the Book’s status to be checked in.

○ Don’t worry about creating a Transaction for this.

● Write a method to print out each Transaction

○ I will leave the formatting up to you.

○ Just make sure you print out the relevant details for the Book/Patron

Task 1.6

Let’s test out the final product in our main.

● Create a Library object constructed with booklist.txt and patronlist.txt

● Create a rudimentary menu using a while loop and a switch-case statement.

○ The menu should have the following options

1. Add a book

2. Add a patron

3. Check out a book

4. Check in a book

5. Print out all Transactions

6. Quit Program

○ For choices 1 through 4. Prompt the user for relevant input.

CSCI 1300

Summer 2018

Assignment 6

Task 2 (Extra Credit -- 10pts)

Write a class called Vector that will inherit from std::vector.

● Override the [] operator to check if the index is out of bounds or not

● If the index is out of bounds, throw a out_of_range exception.

● Demonstrate our added functionality in your main with a try-catch statement


站长地图