1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
//Baka.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <string>
#include "Baka.h"
using namespace std;
Book::Book()
{
}
BookList::BookList()
{
}
BookList::~BookList()
{
return;
}
void BookList::insert(string bookt, int bquan, double bookpri)
{
//validate userinput to see if name is correct
bool loop = false;
string bookt = "";
while (loop = false) {
if (bookt == "")
{
cout << "Please enter book title: " << endl;
cin >> bookt;
if (!cin) {
cout << "Invalid word, please try again...:" << endl;
cin.clear();
cin.ignore();
bookt = "";
;
}
else {
loop = true;
break;
;
}
;
}
;
}
//validate if userinput for quantity is a number
bool loop = false;
int bquan = -1;
while (loop = false) {
if (bquan == NULL)
{
cout << "Please enter how many books to add: " << endl;
cin >> bquan;
if (!cin) {
cout << "Invalid amount, please try again...:" << endl;
cin.ignore();
cin.clear();
bqex = -1;
;
}
else if (bquan < 0) {
cout << "Invalid amount, please try again...:" << endl;
cin.clear();
cin.ignore();
bqex = -1;
;
}
else {
loop = true;
break;
;
}
;
}
;
}
//validate if price is a double
bool loop = false;
int bookpri = -1;
while (loop = false) {
if (bookpri == NULL)
{
cout << "Please enter book price: " << endl;
cin >> bookpri;
if (!cin) {
cout << "Invalid amount, please try again...:" << endl;
cin.ignore();
cin.clear();
bpex = -1;
;
}
else if (bookpri < 0) {
cout << "Invalid amount, please try again...:" << endl;
cin.ignore();
cin.clear();
bookpri = -1;
;
}
else {
loop = true;
break;
;
}
;
}
;
}
cout << "Item(s) added to inventory." << endl;
}
void BookList::search(string key)
{
cout << "Please enter a keyword to search inventory with:" << endl;
cin >> key;
//display items with that word or print that there is no such item that exists
}
void BookList::remove(string t)
{
cout << "Please enter an item to remove from inventory: " << endl;
cin >> t;
//presume to check for item to remove otherwise print item doesn't exist
}
void BookList::print()
{
cout << "Number of total books: " << count << endl;
//print list with books, quantity and prices
}
//Baka.h
//YOU CAN'T ALTER THE HEADER, ONLY ADD THINGS TO IT
#pragma once
class Book
{
public:
Book(); // default constructor
Book(string bookt, int bquan, double bookpri); // constructor
string bookt;
int bquan;
double bookpri;
private:
string title; // book title
int quantity; // number of copies in stock
double price; // book price
// Assign friendship to class BookList
// so that BookList object can directly access private data of Book
friend class BookList; // Assign friendship to class BookList
};
class BookList
{
public:
BookList(); // Constructor
~BookList(); // Destructor
//--------------------------------------------------------
void insert(string bookt, int bquan, double bookpri);
// Insert a new book record into the book list.
// The book has title bookt, number of copies in stock bquan
// and the price bookpri.
// Note that the vector of books should be maintained
// in the lexicographical order of the book titles.
// If the book title already exists in the list,
// then upgrade the quantity by adding bquan to current quantity;
// and upgrade the price with bookpri
//--------------------------------------------------------
void search(string key);
// Search for matched book titles with the given key
// The book title which contains key as substring matches
// If a book is found, print its title, quantity and price;
// If more than one, display them in lexicographical order
// otherwise report No Matched Book is in stock
//--------------------------------------------------------
void remove(string t);
// Delete a book record with title exactly matching t,
// If the book is not in stock, report it then do nothing.
//--------------------------------------------------------
void print();
// First display totally how many books in stock;
// then display the book records in stock in the
// lexicographical order of book titles
//--------------------------------------------------------
// other member functions if you need…
private:
vector<Book> BL; // a vector to store Book objects in stock
int count; // total number of books in stock
};
//BakaMain.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <string>
#include "Baka.h"
using namespace std;
bool sentinel = true;
int main()
{
int selection;
BookList list1;
//loop that continues until the user chooses Quit (5)
while (sentinel == true) {
//Menu
//------
if (int count = 0) {cout << "The list is currently empty" << endl;}
cout << "Welcome to Book Management System for Wildcar Bookstore" << endl;
cout << "Select from:" << endl;
cout << "1. Insert a book record" << endl;
cout << "2. Delete a book record" << endl;
cout << "3. Print a book record" << endl;
cout << "4. Search the book list" << endl;
cout << "5. Quit" << endl;
//------
//End of menu
int selection = 0;
if (selection == 1) {
list1.insert("", -1, -1);
; }
else if (selection == 2) {
list1.remove("example");
; }
else if (selection == 3) {
list1.print();
; }
else if (selection == 4) {
list1.search("examplekey");
; }
else if (selection == 5) {
sentinel = false;
cout << "Thanks for using my program!" << endl << endl;
exit(0);
; }
else {
cout << "Invalid input, please try again..." << endl;
continue;
; }
;}
system("pause");
return 0;
}
|