Added assignment two, completed Library Book.
++ librarybook.cpp ++ userInventory.cpp ++ fraction.cpp
This commit is contained in:
parent
eb191a70b4
commit
2b85212dae
4 changed files with 186 additions and 0 deletions
0
assignmentTwo/fraction.cpp
Normal file
0
assignmentTwo/fraction.cpp
Normal file
BIN
assignmentTwo/librarybook
Executable file
BIN
assignmentTwo/librarybook
Executable file
Binary file not shown.
186
assignmentTwo/librarybook.cpp
Normal file
186
assignmentTwo/librarybook.cpp
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
Program Name: Library Book
|
||||
Process: ???
|
||||
Function Input/Parameters: ???
|
||||
Function Output/Parameters: ???
|
||||
Function Output/Returned: ???
|
||||
Device Input/Device: ???
|
||||
Device Output/Monitor: ???
|
||||
Dependencies: ???
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// class definitions
|
||||
class LibraryBook
|
||||
{
|
||||
private:
|
||||
string title;
|
||||
string author;
|
||||
string ISBN;
|
||||
bool checkedOut;
|
||||
public:
|
||||
LibraryBook()
|
||||
{
|
||||
// default constructor
|
||||
title = "";
|
||||
author = "";
|
||||
ISBN = "";
|
||||
checkedOut = false;
|
||||
}
|
||||
LibraryBook(string bookTitle, string bookAuthor, string bookIsbn)
|
||||
{
|
||||
// most likely definition for a book
|
||||
title = bookTitle;
|
||||
author = bookAuthor;
|
||||
ISBN = bookIsbn;
|
||||
checkedOut = false;
|
||||
}
|
||||
~LibraryBook()
|
||||
{
|
||||
// default destructor
|
||||
}
|
||||
// accessor functions
|
||||
string getBookTitle()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
string getBookAuthor()
|
||||
{
|
||||
return author;
|
||||
}
|
||||
string getBookIsbn()
|
||||
{
|
||||
return ISBN;
|
||||
}
|
||||
bool isCheckedOut()
|
||||
{
|
||||
return checkedOut;
|
||||
}
|
||||
void printBookDetails()
|
||||
{
|
||||
// print out a formatted book detail 'card'
|
||||
cout << "Library Book:" << endl;
|
||||
cout << "\tBook Title : " << title << endl;
|
||||
cout << "\tBook Author : " << author << endl;
|
||||
cout << "\tBook ISBN : " << ISBN << endl;
|
||||
cout << "\tBook Checked Out: " << boolalpha << checkedOut << endl;
|
||||
}
|
||||
// mutator functions
|
||||
void setBookTitle(string bookTitle)
|
||||
{
|
||||
title = bookTitle;
|
||||
}
|
||||
void setBookAuthor(string bookAuthor)
|
||||
{
|
||||
author = bookAuthor;
|
||||
}
|
||||
void setBookIsbn(string bookIsbn)
|
||||
{
|
||||
ISBN = bookIsbn;
|
||||
}
|
||||
void checkOutBook()
|
||||
{
|
||||
checkedOut = true;
|
||||
}
|
||||
void checkInBook()
|
||||
{
|
||||
checkedOut = false;
|
||||
}
|
||||
void getBookDetails()
|
||||
{
|
||||
// ask the user for each book detail.
|
||||
cout << "New Library Book:" << endl;
|
||||
cout << "\tEnter in a book title: ";
|
||||
// cin >> title;
|
||||
getline(cin, title);
|
||||
// cin.ignore(256, '\n');
|
||||
cout << "\tEnter in " << title << "'s Author: ";
|
||||
// cin >> author;
|
||||
getline(cin, author);
|
||||
// cin.ignore(256, '\n');
|
||||
cout << "\tEnter in " << title << "'s ISBN: ";
|
||||
// cin >> ISBN;
|
||||
getline(cin, ISBN);
|
||||
// cin.ignore(256, '\n');
|
||||
cout << "\tThe book will be set to not checked out." << endl;
|
||||
// set the book checked out to false.
|
||||
checkedOut = false;
|
||||
}
|
||||
};
|
||||
|
||||
// function definitions
|
||||
|
||||
// main function
|
||||
int main()
|
||||
{
|
||||
bool finishBookInput = false;
|
||||
char finishBookInputChar;
|
||||
string requestTitle;
|
||||
int shelfSize = 0;
|
||||
// create a vector storage for a 'bookshelf.'
|
||||
vector<LibraryBook> bookshelf;
|
||||
// working book definition
|
||||
LibraryBook workingBook;
|
||||
cout << "--- Library Book Program ---" << endl;
|
||||
cout << "----- Program Start -----" << endl;
|
||||
cout << "" << endl;
|
||||
// need a while loop
|
||||
while (!finishBookInput)
|
||||
{
|
||||
// cin.ignore();
|
||||
// ask user to input book.
|
||||
workingBook.getBookDetails();
|
||||
// once details are input, save to the shelf.
|
||||
bookshelf.push_back(workingBook);
|
||||
// display the book input.
|
||||
workingBook.printBookDetails();
|
||||
// check in/out book by title.
|
||||
// ask user for another book title.
|
||||
cout << "Enter a title to check out: " << endl;
|
||||
// cin >> requestTitle;
|
||||
getline(cin, requestTitle);
|
||||
shelfSize = bookshelf.size();
|
||||
// for loop through the vector, if the title is found, check out the book.
|
||||
for(int shelfIterator = 0; shelfIterator < shelfSize; shelfIterator++)
|
||||
{
|
||||
// check to see if the book matches
|
||||
if(bookshelf[shelfIterator].getBookTitle() == requestTitle)
|
||||
{
|
||||
// the book matched,
|
||||
if(bookshelf[shelfIterator].isCheckedOut())
|
||||
{
|
||||
// check back in the book
|
||||
bookshelf[shelfIterator].checkInBook();
|
||||
cout << requestTitle << " has been checked in." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// check out the book
|
||||
bookshelf[shelfIterator].checkOutBook();
|
||||
cout << requestTitle << " has been checked out." << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ask user if they want to input another book.
|
||||
cout << "Enter another book?: ";
|
||||
// finishBookInputChar = getchar();
|
||||
cin >> finishBookInputChar;
|
||||
cin.ignore();
|
||||
if(finishBookInputChar == 'n' || finishBookInputChar == 'N')
|
||||
{
|
||||
finishBookInput = true;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
0
assignmentTwo/userInventory.cpp
Normal file
0
assignmentTwo/userInventory.cpp
Normal file
Loading…
Add table
Add a link
Reference in a new issue