Software Engineering Theory Assignment 2 Library Management System Code
Software Engineering Theory Assignment 2 Library Management System Code
*******************************************************************************/
//main.cpp
#include <string>
#include <iostream>
#include <iomanip>
#include "Library.h"
void displayMenu();
bool menuSelection( int option, Library* lib );
void addBookInformation( Library* lib );
void removeBook( Library* lib );
void displayBook( Library* lib );
int main() {
Library lib;
int option = 0;
do {
std::cout << "\nChoose an option from the menu ";
std::cin >> option;
std::cout << '\n';
} while( menuSelection( option, &lib ) );
void displayMenu() {
std::cout << "================================================\n";
std::cout << "1: Add a book to the library\n";
std::cout << "2: Remove book from the library\n";
std::cout << "3: Display the number of books in the library\n";
std::cout << "4: Display a books information\n";
std::cout << "5: Display the list of all books\n";
std::cout << "6: Display menu option\n";
std::cout << "7: Exit the library and quit\n";
std::cout << "================================================\n";
}
bookId++; // increment our book id so each one is unique TODO: this can be
replaced to have same id for multiple books if the books are exact matches.
if( actualBook ) {
std::cout << *actualBook;
} else {
std::cout << "\nBook was not found.\n";
}
} else {
std::cout << "\nYou entered an invalid selection\n";
}
}
//Book.h
#ifndef BOOK_H
#define BOOK_H
#include <string>
#include <iostream>
#include <iomanip>
class Book {
private:
std::string title_;
std::string author_;
std::string releasedate_;
std::string language_;
public:
Book(); // default
Book( const std::string& title, const std::string& author, const std::string&
releasedate, const std::string& language );
#endif // BOOK_H
//Book.cpp
#include "Book.h"
Book::Book() {
} // default
releasedate_( releasedate ),
language_( language ){
}
//Library.h
#ifndef LIBRARY_H
#define LIBRARY_H
#include "Book.h"
#include <map>
class Library {
private:
std::multimap<std::string, Book> books_;
// This is used if the library has several copies of the same book
// that have the same ID in the multimap above.
std::map<std::string, unsigned int> inventory_;
public:
Library(); // deafault
private:
// Helper function to calculate the number of unique books.
std::size_t calculateUniqueNumberOfBooks() const;
};
#endif // LIBRARY_H
//Library.cpp
#include "Library.h"
#include <vector>
Library::Library() {
} // deafault