1 // Copyright 2013 Carey Riley, Dwayne Reid
2 // A Bookshop Inventory Management System
3 /* A small Bookshop maintains the inventory of books sold in the shop. The list
4 * includes (but is not limited to) the following details:
6 * Title of the book(s),
7 * Price of each each book,
8 * Publisher of each book,
9 * Stock levels of each type in a tabular form as shown below
10 * ----------------------------------------------------------------------
11 * | BOOKSHOP DATABASE |
12 * ------------------------------------------------------------------------
13 * | Author's Name | Book Title | Unit Price | Publisher | Stock Count |
14 * -----------------------------------------------------------------------
15 * | Deitel & Deitel| C++...Program| $2500.00| Pearson | 15 Copies |
16 * ------------------------------------------------------------------------
18 * ------------------------------------------------------------------------
20 * Whenever a customer wants a book, the sales person inputs the title and author
21 * and the system searches the list (database) and displays whether it is available
22 * or not. If available, the total cost of the requested copies is displayed;
23 * otherwise the message "Required copies not in stock" is displayed.
25 * Design a system using a class called books with suitable member functions,
26 * member variables and constructors. Use the New operator in your constructors
27 * to apportion possible memory requriements. Objects created in main should be
28 * able to access appropriate member functions to carry out whichever task(s) they
29 * are designed to perform.
31 * In writing your program, use comments to facilitate comprehension and explain
32 * all assumptions you might be forced to make for the system to function
33 * optimally. Innovation as well as user friendliness of your interface would be
37 /* TODO(Carey): disorded breakdown of needed actions
38 * - class Books with functions, variables and constructors
39 * - contructors should use the new operator
40 * - comment, comment, comment
42 input title and author; searches inventory, returns total cost and
43 requested number of copies.
44 - anymore observations follow the above syntax of TODO(name||email): <todos>
52 // put all global functions in an unnamed namespace so code is as OO as possible
59 // print stock shortage to screen
60 void NotInStock(void) {cerr
<< "Required copies not in stock\n";}
62 // Stock Table layout with header
63 void PrintStockTableHeader(void) {
64 cout
<< setw(80) << setfill('_') << '\n' << setfill(' ') <<
65 '|' << setw(41) << "BOOKSHOP DATABASE" << setw(38) << '|' << '\n' <<
66 setw(80) << setfill('_') << '\n' << setfill(' ');
67 /* "| Author's Name |" <<
71 " Stock Count|" << '\n' <<
72 setw(80) << setfill('_') << '\n' << setfill(' ');
74 // Share 80 spaces properly
75 cout
<< "| Author's Name "; // about 17 spaces wide
76 cout
<< "| Book Title ";
77 cout
<< "| Unit Price "; // about 12 spaces wide
78 cout
<< "| Stock Count |"; // about 13 spaces
82 // Attempt at a search function
83 *SearchAuthorTitle(std::string author
, std::string title
, Books
*booklist
) {
84 for(int i
=0; i
<= 10; ++i
)
85 // author and title string matches list instance
86 (booklist
[i
].author_
== author
&& books
[i
].title_
== title
) ?: booklist
.ConstomerWants();
90 // BookSearch(std::string, std::string) { }
93 Books() : author_("Deitel & Deitel"),
94 title_("C++...Program"),
96 publisher_("Pearson"),
99 // {cout << "|" << author_ << " | " << title_ << " | " << unitprice_ <<
100 // " | " << publisher_ << " | " << quantity_ << "|" << '\n';
102 double CustomerWants(int quantity
) {quantity_
<= quantity
?: NotInStock() : return quantity
* unitprice_
;
107 std::string publisher_
;
114 PrintStockTableHeader();