updated salesdb.db
[interests.git] / Documents / CW2 / bookshop.cc
blob40578e94afa690cca281fa34ee389bdc38984a6d
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:
5 * Author's name,
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 * ------------------------------------------------------------------------
17 * | | | | | |
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
34 * rewarded.
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
41 * - search function:
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>
47 #include <iostream>
48 #include <iomanip>
49 // #include <cstdio>
50 #include <string>
52 // put all global functions in an unnamed namespace so code is as OO as possible
53 namespace {
54 using std::setfill;
55 using std::setw;
56 using std::cout;
57 using std::cerr;
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 |" <<
68 " Book Title |" <<
69 " Unit Price |" <<
70 " Publisher |" <<
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();
88 // If
90 // BookSearch(std::string, std::string) { }
91 class Books {
92 public:
93 Books() : author_("Deitel & Deitel"),
94 title_("C++...Program"),
95 unitprice_(2500.00),
96 publisher_("Pearson"),
97 quantity_(15)
99 // {cout << "|" << author_ << " | " << title_ << " | " << unitprice_ <<
100 // " | " << publisher_ << " | " << quantity_ << "|" << '\n';
101 // };
102 double CustomerWants(int quantity) {quantity_ <= quantity ?: NotInStock() : return quantity * unitprice_;
103 private:
104 std::string author_;
105 std::string title_;
106 double unitprice_;
107 std::string publisher_;
108 int quantity_;
112 int main() {
113 NotInStock();
114 PrintStockTableHeader();
115 Books shelf;
116 shelf;