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
|
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
const int MAX_BOOKS = 2000;
const int MAX_USERS = 500;
struct User
{
string userID;
string name;
string houseNo;
string address;
string noOfLoans;
};
struct Book
{
string bookID;
string title;
string authorSurname;
string authorFirstname;
string category;
string location;
string onLoan;
};
enum bookCategory
{
Adventure = 'A',
Detective = 'D',
SciFi = 'S',
Romance = 'R'
};
int findBookAuthor(Book[], string, int);
int main()
{
ifstream bookDataFile;
ifstream userDataFile;
Book books[MAX_BOOKS];
User users[MAX_USERS];
int noOfBooks = 0;
int noOfUsers = 0;
bookDataFile.open("bookdata.txt");
userDataFile.open("userdata.txt");
while(!bookDataFile.eof() && noOfBooks < MAX_BOOKS)
{
getline(bookDataFile, books[noOfBooks].authorSurname);
getline(bookDataFile, books[noOfBooks].authorFirstname);
getline(bookDataFile, books[noOfBooks].title);
getline(bookDataFile, books[noOfBooks].category);
getline(bookDataFile, books[noOfBooks].bookID);
if (! bookDataFile.eof())
noOfBooks++;
}
bookDataFile.close();
string author;
int bookID;
int option;
cout << "1. Loan Book" << endl;
cout << "2. Find Book By Author" << endl;
cin >> option;
while(true)
{
switch(option)
{
case 1:
cout << "Under Construction" << endl;
break;
case 2:
cout << "Enter the Author's Surname and Forename: " << endl;
getline(cin, author, '\n');
bookID = findBookAuthor(books, author, noOfBooks);
break;
}
}
return 0;
}
int findBookAuthor(Book books[], string author, int noOfBooks)
{
for(int bookNo = 0; bookNo < noOfBooks; bookNo++)
{
if(books[bookNo].authorSurname == author)
{
cout << "--------------------------------------------------" << endl;
cout << "BookID: " << books[bookNo].bookID << endl;
cout << "Title: " << books[bookNo].title << endl;
cout << "Author: " << books[bookNo].authorSurname << "," << books[bookNo].authorFirstname<< endl;
cout << "Category: " << books[bookNo].category << endl;
cout << "Location: " << books[bookNo].location << endl;
cout << "onLoan: " << books[bookNo].onLoan << endl;
cout << "--------------------------------------------------" << endl << endl;
}
}
return -1;
}
int findUser(User users[], string userName, int noOfUsers)
{
for(int userID = 0; userID < noOfUsers; userID++)
{
if(users[userID].name == userName)
{
cout << "--------------------------------------------------" << endl;
cout << "UserID: " << users[userID].userID << endl;
cout << "Name: " << users[userID].name << endl;
cout << "House No: " << users[userID].houseNo << endl;
cout << "Address: " << users[userID].address << endl;
cout << "No of Loans: " << users[userID].noOfLoans << endl;
cout << "--------------------------------------------------" << endl << endl;
}
}
return -1;
}
|