1. #include "stdafx.h"
#include
#include
using namespace std;
const int MAX_ARRAY_SIZE = 4;
class memberType {
public:
string name; // Name of the person
int id; // Member ID
int n_books; // Number of books
double amount; // Total amount spent
public:
memberType();
memberType(string ID, string first, string last, int books, double amount);
//
void setMemberInfo(string ID, string fName, string lName, int bPurchased, double amount);
// member Name access methods
void setMemberID(string);
void setName(string, string); // set new name
string getName(); // get Name
bool isMemberID(string) const;
int getBooksPurchased() const;
double getTotalAmountSpent() const;
void purchaseBook(double amount);
void resetbooksBoughtAndAmount();
void printMemberID() const;
void printName() const;
void printInfo() const;
private:
string memberID;
string firstName;
string lastName;
int booksPurchased;
double amountSpent;
};
2. class bookType
{
public:
void setTitle(string); //functions dealing with the title
string getTitle();
bool compareTitle(string);
//functions dealing with the copies of book
void setCopies(int);
void showCopies();
void updateCopies(int);
int getCopies();
void setPublisher(string); //functions dealing with publisher of book
void showPublisher();
void updatePublisher(string);
string getPublisher();
void setISBN(string); //functions dealing with ISBN of book
void showISBN();
void updateISBN(string);
string getISBN();
bool compareISBN(string);
void setPrice(double bookPrice); //functions dealing with price of book
void showPrice();
void updatePrice(double compPrice);
double getPrice();
void setAuthors(string); //functions dealing with author of book
void showAuthors();
void updateAuthor(string compAuthor);
string getAuthors(int i); //ith number of author will return
bookType();
private:
string title;
string authors[4]; //objects of type bookType can contain up to 4 authors
string publisher;
string ISBN;
double price;
int copies;
3. int authorsNo;
};
bookType::bookType()
{
title = "";
for (int i = 0; i < 4; i++)
authors[i] = "";
publisher = "";
ISBN = "";
price = 0;
copies = 0;
authorsNo = 0;
}
void bookType::setTitle(string myTitle)
{
title = myTitle;
}
string bookType::getTitle()
{
return title;
}
bool bookType::compareTitle(string otherTitle)
{
return (title.compare(otherTitle) == 0);
}
void bookType::setAuthors(string myAuthor)
{
authorsNo = authorsNo % 4;
if (myAuthor.compare("") == 0)
return;
else
{
authors[authorsNo] = myAuthor; //store the author name
authorsNo++; //keep track of authors count
}
}
9. cout << "Enter--" << endl;
cout << "1: MemberInfo:" << endl;
cout << "2: Number of books purchased:" << endl;
cout << "3: Spent Amount: " << endl;
cout << "99:To quit the program." << endl;
}
Solution
#include "stdafx.h"
#include
#include
using namespace std;
const int MAX_ARRAY_SIZE = 4;
class memberType {
public:
string name; // Name of the person
int id; // Member ID
int n_books; // Number of books
double amount; // Total amount spent
public:
memberType();
memberType(string ID, string first, string last, int books, double amount);
//
void setMemberInfo(string ID, string fName, string lName, int bPurchased, double amount);
// member Name access methods
void setMemberID(string);
void setName(string, string); // set new name
string getName(); // get Name
bool isMemberID(string) const;
int getBooksPurchased() const;
double getTotalAmountSpent() const;
void purchaseBook(double amount);
void resetbooksBoughtAndAmount();
void printMemberID() const;
void printName() const;
10. void printInfo() const;
private:
string memberID;
string firstName;
string lastName;
int booksPurchased;
double amountSpent;
};
class bookType
{
public:
void setTitle(string); //functions dealing with the title
string getTitle();
bool compareTitle(string);
//functions dealing with the copies of book
void setCopies(int);
void showCopies();
void updateCopies(int);
int getCopies();
void setPublisher(string); //functions dealing with publisher of book
void showPublisher();
void updatePublisher(string);
string getPublisher();
void setISBN(string); //functions dealing with ISBN of book
void showISBN();
void updateISBN(string);
string getISBN();
bool compareISBN(string);
void setPrice(double bookPrice); //functions dealing with price of book
void showPrice();
void updatePrice(double compPrice);
double getPrice();
void setAuthors(string); //functions dealing with author of book
void showAuthors();
void updateAuthor(string compAuthor);
string getAuthors(int i); //ith number of author will return
11. bookType();
private:
string title;
string authors[4]; //objects of type bookType can contain up to 4 authors
string publisher;
string ISBN;
double price;
int copies;
int authorsNo;
};
bookType::bookType()
{
title = "";
for (int i = 0; i < 4; i++)
authors[i] = "";
publisher = "";
ISBN = "";
price = 0;
copies = 0;
authorsNo = 0;
}
void bookType::setTitle(string myTitle)
{
title = myTitle;
}
string bookType::getTitle()
{
return title;
}
bool bookType::compareTitle(string otherTitle)
{
return (title.compare(otherTitle) == 0);
}
void bookType::setAuthors(string myAuthor)
{
authorsNo = authorsNo % 4;
12. if (myAuthor.compare("") == 0)
return;
else
{
authors[authorsNo] = myAuthor; //store the author name
authorsNo++; //keep track of authors count
}
}
void bookType::showAuthors()
{
for (int i = 0; i < authorsNo; i++)
cout << authors[i] << ", ";
cout << " ";
}
void bookType::updateAuthor(string myAuthor)
{
setAuthors(myAuthor);
}
string bookType::getAuthors(int i)
{
return authors[i];
}
void bookType::setCopies(int myCopies)
{
copies = myCopies;
}
void bookType::showCopies()
{
cout << " tThe number of copies " << copies;
}
void bookType::updateCopies(int myCopies)
{
copies = myCopies;
}
int bookType::getCopies()
{