I wrote this code and it shows so many errors can someone please help me with th
ID: 3861672 • Letter: I
Question
I wrote this code and it shows so many errors can someone please help me with the code and explain the errors. Its a C++ code. Thank you in advance for the great help
/* 8. Create a Patron class for the library. The class will have a user’s name, library card number,
and library fees (if owed). Have functions that access this data, as well as a function to set the fee of the user.
Have a helper function that returns a Boolean (bool) depending on whether or not the user owes a fee.*/
#include "std_lib_facilities_4.h"
#include <iostream>
class Patron {
private:
string name1;
double card;
double fees;
public:
string getname();
double getcard();
double getfees();
bool isfee();
void set_name(string n);
void set_card(double m);
void set_fees(double f);
Patron(){
name1 = "H" ; card = 0; fees=0;
}
Patron(string n, double c,double f){
name1 = n ; card = c; fees=f;
}
};
string Patron::getname(){
return name1;
}
void Patron :: set_name(string n) {
name1=n;
}
void Patron :: set_card(double m){
card=m;
}
void Patron :: set_fees(double f){
fees=f;
}
double Patron::getcard(){
return card;
}
double Patron :: getfees() {
return fees;
}
bool Patron:: isfee(){
if (fees > '0'){
return true;}
return false;
}
bool operator==(const Patron& a1, const Patron& b1 ) {
return (a1.getfees()==b1.getfees());
}
ostream& operate << (ostream& os , const Patron& d ){
return os << "User Name "<< d.get_username()<<endl<<"Library fees "<<d.getfees()<<endl;
}
int main(){
Patron a1{"H1",5,1};
Patron b1{"YYYY ",7,10};
a1.Patron::set_fees(10);
cout<<"Is there a fee :" << a1.Patron::isfee()<<endl;
cout<<"Fee is : "<<a1.Patron:: set_fees()<<endl;
cout<<"Is there a fee :" << a1.Patron::isfee()<<endl;
cout<<"Fee is : "<<a1.Patron:: set_fees()<<endl;
bool mmm=a1==b1;
cout<<a1;
cout<<b1;
return 0;
}
Explanation / Answer
Here is the below C++ Code for the above scenario :
#include "../custom_std_lib_facilities.h"
#include <string>
#include <vector>
#define MAX_DATE 2015
using namespace std;
enum Genre
{
fiction, nonfiction, periodical, biography, children
};
class Book
{
private:
string ISBN;
string title;
string author;
int copyright_date;
bool checked_in;
Genre book_genre;
public:
Book(string ISBN, string title, string author, int copyright_date, Genre book_genre);
string isbn() const { return ISBN; }
string book_title() const { return title; }
string author_name() const { return author; }
int copy_date() const { return copyright_date; }
Genre genre() const { return book_genre; }
bool check() const { return checked_in; }
void check_book_in(bool checked_in);
void check_book_out(bool checked_in);
};
class Patron
{
private:
string user_name;
double library_card_number;
string library_fee;
public:
string username() const { return user_name; }
double card_number() const { return library_card_number; }
string fee() const { return library_fee; }
string set_fee(string library_fee) { return library_fee; }
bool is_fee_owed(string fee_owed);
Patron(string user_name, double library_card_number, string library_fee);
};
void printBookData(Book& book);
Book checked_out_book(Book& book);
void printPatronData(Patron& patron, Book& book);
bool operator==(Book& book1, Book& book2);
bool operator!=(Book& book1, Book& book2);
int main()
{
try
{
Book book1{"0-15-204560-0", "Heir Apparent", "Vivian Vande Velde", 2002, Genre::fiction};
book1.check_book_in(book1.check());
Book book2{"0-375-82668-8", "Eragon", "Christopher Paolini", 2003, Genre::fiction};
book2.check_book_out(book2.check());
Book book3{"0-590-55356-9", "Sandry's Book", "Tamora Pierce", 1997, Genre::fiction};
book3.check_book_out(book3.check());
Patron patron1{"Mike", 3-2504-58140-9664, patron1.set_fee("$0.00")};
if (patron1.is_fee_owed(patron1.fee()))
{
error("error: a fee is owed");
}
Patron patron2{"Osman", 4-2512-21408-5521, patron2.set_fee("$0.00")};
if (patron2.is_fee_owed(patron1.fee()))
{
error("error: a fee is owed");
}
Patron patron3{"Draco", 2-1262-52741-6185, patron2.set_fee("$0.00")};
if (patron3.is_fee_owed(patron3.fee()))
{
error("error: a fee is owed");
}
cout << "Note: 0 == Fiction, 1 == Nonfiction, 2 == Periodical, 3 == Biography, 4 == Children ";
cout << "The information for " << book1.book_title() << " is: ";
printBookData(book1);
cout << " ";
cout << "The information for " << book2.book_title() << " is: ";
printBookData(book2);
cout << " ";
cout << "The information for " << book3.book_title() << " is: ";
printBookData(book3);
cout << " Information on Library Patrons: ";
printPatronData(patron1, book1);
cout << " ";
printPatronData(patron2, book2);
cout << " ";
printPatronData(patron3, book3);
cout << " ";
keep_window_open();
}
catch(runtime_error& r)
{
cout << r.what() << " ";
keep_window_open();
return 1;
}
catch(...)
{
cout << "Whoops! Unknown exception! Please try again later. ";
keep_window_open();
return 2;
}
}
Book::Book(string isbn_number, string title_of_book, string name_of_author, int date, Genre genre_of_book)
{
ISBN = isbn_number, title = title_of_book, author = name_of_author;
copyright_date = date;
book_genre = genre_of_book;
if (date <= 0 || date > MAX_DATE)
{
error("invalid copyright date");
}
stringstream ss(isbn_number);
char valid = '-';
char invalid = ' ';
for (int i = 0; i < 3; i++)
{
int integer = -1;
char character = invalid;
ss >> integer >> character;
if (integer < 0 || character != valid)
{
error("Invalid ISBN");
}
}
string final;
ss >> final;
if (final.size() != 1)
{
error("Invalid ISBN");
}
else if(!isdigit(final[0]) && !isalpha(final[0]))
{
error("Invalid ISBN");
}
}
void Book::check_book_in(bool checked_in)
{
checked_in = true;
}
void Book::check_book_out(bool checked_in)
{
checked_in = false;
}
void printBookData(Book& book)
{
cout << "ISBN number: " << book.isbn() << " "
<< "Title: " << book.book_title() << " "
<< "Author: " << book.author_name() << " "
<< "Copyright date: " << book.copy_date() << " "
<< "Genre: " << book.genre() << " ";
}
bool operator==(Book& book1, Book& book2)
{
return book1.isbn() == book2.isbn() && book1.book_title() == book2.book_title()
&& book1.author_name() == book2.author_name() && book1.copy_date() == book2.copy_date()
&& book1.genre() == book2.genre();
}
bool operator!=(Book& book1, Book& book2)
{
return !(book1.author_name() == book1.isbn());
}
Patron::Patron(string name, double number, string user_fee)
{
user_name = name;
library_card_number = number;
library_fee = user_fee;
}
void printPatronData(Patron& patron, Book& book)
{
cout << "Patron's name: " << patron.username() << " "
<< "Library card no: " << patron.card_number() << " "
<< "Fee owed (in Dollars): " << patron.set_fee(patron.fee()) << " "
<< "Book checked out: " << book.book_title() << " ";
}
bool Patron::is_fee_owed(string fee_owed)
{
if (fee_owed != "$0.00")
{
return true;
}
return false;
}