Dear All
Although my tutor said that it takes 25 minus, I have been trying to understand for more than a week that how to do my task.
I have done something as you said before in terms of "putting at least some efforts".
Please see the codes below and do help me on my mistakes.
I also enclose the errors at the and of codes when I complied it.
I made semi colon mistakes some where and I did not declared some of variables.But I am stil confusing.
I need your corrections and advice
Regards
#include <string.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
const int MAX_BOOKS = 1000;
const int MAX_USERS = 500;
enum bookCategory
{
Adventure = 'A',
Detective = 'D',
SciFi = 'S',
Romance = 'R'
};
struct Book
{
string bookID;
string title;
string authorSurname;
string authorFirstname;
string category;
string location;
string onLoan;
};
struct User
{
string userID;
string name;
string houseNo;
string address;
string noOfLoans;
};
int findBookAuthor(Book[], string, int);
int main()
{
fstream bookDataFile;
fstream 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);
noOfBooks++;
}
while(!userDataFile.eof() && noOfUsers < MAX_USERS)
{
getline(userDataFile, users[noOfUsers].name);
getline(userDataFile, users[noOfUsers].houseNo);
getline(userDataFile, users[noOfUsers].address);
getline(userDataFile, users[noOfUsers].userID);
noOfUsers++;
}
string author;
int bookID;
int option;
while(true)
{
cout << "1. Loan Book" << endl;
cout << "2. Find Book By Author" << endl;
cin >> option;
switch(option)
{
case 1:
cout << "Under Construction" << endl;
break;
case 2:
cout << "Enter Author Name: ";
cin >> author;
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 userID, int noOfUsers)
{
for(int bookNo = 0; bookNo < noOfBooks; bookNo++)
{
if(books[bookNo].authorSurname == author)
{
}
}
return -1;
}
/*
ERRORS
g++ library.cc
library.cc:20: syntax error before `;'
library.cc:21: syntax error before `;'
library.cc:22: syntax error before `;'
library.cc:23: syntax error before `;'
library.cc:24: syntax error before `;'
library.cc:25: syntax error before `;'
library.cc:26: syntax error before `;'
library.cc:31: syntax error before `;'
library.cc:32: syntax error before `;'
library.cc:33: syntax error before `;'
library.cc:34: syntax error before `;'
library.cc:35: syntax error before `;'
library.cc:38: type specifier omitted for parameter
library.cc: In function `int main()':
library.cc:50: no matching function for call to `fstream::open (const char[13])'
/usr/local/depot/gcc-2.95.3/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/../../../../include/g++-3/fstream.h:89: candidates are: void fstream::open(const char *, int, int = 436)
library.cc:51: no matching function for call to `fstream::open (const char[13])'
/usr/local/depot/gcc-2.95.3/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/../../../../include/g++-3/fstream.h:89: candidates are: void fstream::open(const char *, int, int = 436)
library.cc:55: `struct Book' has no member named `authorSurname'
library.cc:55: implicit declaration of function `int getline(...)'
library.cc:55: warning: cannot pass objects of type `fstream' through `...'
library.cc:56: `struct Book' has no member named `authorFirstname'
library.cc:56: warning: cannot pass objects of type `fstream' through `...'
library.cc:57: `struct Book' has no member named `title'
library.cc:57: warning: cannot pass objects of type `fstream' through `...'
library.cc:58: `struct Book' has no member named `category'
library.cc:58: parse error before `)'
library.cc:58: warning: cannot pass objects of type `fstream' through `...'
library.cc:59: `struct Book' has no member named `bookID'
library.cc:59: warning: cannot pass objects of type `fstream' through `...'
library.cc:66: `struct User' has no member named `name'
library.cc:66: warning: cannot pass objects of type `fstream' through `...'
library.cc:67: `struct User' has no member named `houseNo'
library.cc:67: warning: cannot pass objects of type `fstream' through `...'
library.cc:68: `struct User' has no member named `address'
library.cc:68: warning: cannot pass objects of type `fstream' through `...'
library.cc:69: `struct User' has no member named `userID'
library.cc:69: warning: cannot pass objects of type `fstream' through `...'
library.cc:73: `string' undeclared (first use this function)
library.cc:73: (Each undeclared identifier is reported only once
library.cc:73: for each function it appears in.)
library.cc:73: parse error before `;'
library.cc:89: `author' undeclared (first use this function)
library.cc: At top level:
library.cc:98: type specifier omitted for parameter
library.cc:98: parse error before `,'
library.cc: In function `int findBookAuthor(...)':
library.cc:100: `noOfBooks' undeclared (first use this function)
library.cc:102: `books' undeclared (first use this function)
library.cc: At top level:
library.cc:117: type specifier omitted for parameter
library.cc:117: parse error before `,' /*
*/*