Using the classes designed in Programming Exercises 10 and 11, write a program t
ID: 3664128 • Letter: U
Question
Using the classes designed in Programming Exercises 10 and 11, write a program to simulate a bookstore. The bookstore has two types of customers: those who are members of the bookstore and those who buy books from the bookstore only occasionally. Each member has to pay a $10 yearly member- ship fee and receives a 5% discount on each book purchased. For each member, the bookstore keeps track of the number of books purchased and the total amount spent. For every eleventh book that a member buys, the bookstore takes the average of the total amount of the last 10 books purchased, applies this amount as a discount, and then resets the total amount spent to 0.
Write a program that can process up to 1000 book titles and 500 members. Your program should contain a menu that gives the user different choices to effec- tively run the program; in other words, your program should be user driven.
Explanation / Answer
/*bookType.h*/
#include <string.h>
#include <iostream>
#include <iomanip>
using namespace std;
class bookType
{
public:
bookType();
void setTitle (string);
string getTitle ();
bool compareTitle(string);
void setAuthor(string="");
void showAuthors();
void updateAuthor(string="");
string *getAuthors ();
void setCopies (int);
void showCopies ();
void updateCopies(int);
int getCopies();
void setPublisher(string);
void showPublisher();
void updatePublisher(string);
string getPublisher();
void setISBN(string);
void showISBN();
void updateISBN(string);
string getISBN();
bool compareISBN(string);
void setPrice(double);
void showPrice();
void updatePrice(double);
double getPrice();
void setAuthorsNo(int n);
int getAuthorsNo();
private:
string title;
string authors [4];
string publisher;
string ISBN;
double price;
int copies;
int authorsNo;
};
/*bookType.cpp*/
#include <iostream>
#include "bookType.h"
using namespace std;
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::setAuthor(string myAuthor[])
{
for(int j=0;j<authorsNo;j++)
authors [j]=myAuthor[j];
}
void bookType::showAuthors()
{
for (int i=0; i< authorsNo; i++)
cout<<authors [i]<< ", ";
cout<<" ";
}
void bookType::updateAuthor(string myAuthor[])
{
setAuthor(myAuthor);
}
string *bookType::getAuthors()
{
return authors;
}
void bookType::setCopies(int myCopies)
{
copies=myCopies;
}
void bookType::showCopies()
{
cout<<"There are" <<copies<< "copies of this book.";
}
void bookType::updateCopies(int myCopies)
{
copies=myCopies;
}
int bookType::getCopies()
{
return copies;
}
void bookType::setPublisher(string myPublisher)
{
publisher=myPublisher;
}
void bookType:: showPublisher()
{
cout<<publisher;
}
void bookType::updatePublisher(string myPublisher)
{
publisher=myPublisher;
}
string bookType::getPublisher ()
{
return publisher;
}
void bookType::setISBN(string myISBN)
{
ISBN=myISBN;
}
void bookType:: showISBN()
{
cout<< ISBN;
}
void bookType::updateISBN(string myISBN)
{
ISBN=myISBN;
}
string bookType::getISBN()
{
return ISBN;
}
bool bookType::compareISBN(string myISBN)
{
return(myISBN.compare(ISBN) == 0);
}
void bookType::showPrice()
{
cout<< "The price of this book is "<<price;
}
void bookType::updatePrice( double myPrice)
{
price=myPrice;
}
double bookType::getPrice()
{
return price;
}
#include<iostream>
#include<string.h>
using namespace std;
class memberType
{
public:
string Name;
string ID;
int no_books;
float amount;
memberType()
{
Name=" ";
ID=" ";
no_books=0;
amount=0.00;
}
public: void set(string name, string id, int no, float a);
void modifyName(string name);
void modifyAmount(float amount);
void modifyNumOfBooks(int no, float a);
void show();
};
void memberType::modifyAmount(float a)
{
amount=a;
}
void memberType::modifyNumOfBooks(int n)
{
no_books=n;
}
void memberType::set(string n, string id, int no, float a)
{
Name=n;
ID=id;
no_books+=no;
amount+=a;
}
void memberType::modifyName(string name)
{
Name=name;
}
void memberType::show()
{
cout<<"Person's Name is: "<<Name<<endl;
cout<<"Person's ID is: "<<ID<<endl;
cout<<"Number of Books is: "<<no_books<<endl;
cout<<"Amount Spent is: "<<amount<<endl;
}
class bookStore
{
bookType books[1000];
memberType members[500];
public:
int numOfBooks;
int numOfMembers;
bookStore(){
numOfBooks=0;
numOfMembers=0;
}
void storeMembers()
{
string Name;
string ID;
for(int i=0;i<numOfMembers;i++)
{
cout<<endl<<"Enter member "<<i<<": ";
cout<<endl<<"Enter Name: ";
cin>>Name;
cout<<endl<<"Enter ID: ";
cin>>ID;
members[i].set(Name,ID,0,0);
}
}
void storeBooks()
{
string title;
string authors[4];
string publisher;
string ISBN;
double price;
int copies;
int authorsNo;
for(int i=0;i<numOfBooks;i++)
{
cout<<endl<<"Enter Book "<<i<<": ";
cout<<endl<<"Enter title: ";
cin>>title;
books[i].setTitle(title);
cout<<endl<<"Enter the number of authors <1-4>:";
cin>>authorsNo;
books[i].setAuthorsNo(authorsNo);
for(int k=0;k<authorsNo;k++)
{
cout<<endl<<"Enter author "<<k<<": ";
cin>>author[k];
}
books[i].setAuthors(author);
cout<<endl<<"Enter publisher: ";
cin>>publisher;
books[i].setpublisher(publisher);
cout<<endl<<"Enter ISBN: ";
cin>>ISBN;
books[i].setISBN(ISBN);
cout<<endl<<"Enter price: ";
cin>>price;
books[i].setprice(price);
cout<<endl<<"Enter Number Of Copies: ";
cin>>copies;
books[i].setNumOfCopies(copies);
}
}
void bookPurchase()
{
string name;
string id;
char member;
cout<<endl<<"Is already a member: <y/n>";
cin>>member;
int pos=-1;
if(member=='y')
{
cout<<endl<<"Enter member ID: ";
cin>>id;
for(int i=0;i<numOfMembers;i++)
{
if(id==members[i].ID)
{
pos=i;
break;
}
}
if(pos==-1)
{
member='n' ;
cout<<endl<<"You are not a member."
}
}
else
{
cout<<endl<<"Enter Name: ";
cin>>name;
}
cout<<endl<<"Enter the number of books you want? ";
int n;
cin>>n;
int totalBooks=n;
float amount=0;
for(int b=0;b<n;b++)
{
cout<<endl<<"Enter Book "<<i<<": ";
cout<<endl<<"Enter title: ";
cin>>title;
cout<<endl<<"Enter publisher: ";
cin>>publisher;
cout<<endl<<"Enter Number Of Copies: ";
cin>>copies;
totalBooks+=copies;
amount=B
}
if(member=='y')
{
if(totalBooks==11)
{
amount=members[pos].amount/10;
cout<<endl<<"You have to pay"<<amount;
amount=0;
}
members[pos].modifyAmount(amount);
}
else
cout<<endl<<"You have to pay"<<amount;
}
};
int main()
{
bookStore BS;
cout<<endl<<"Enter the number of books: ";
cin>>BS.numOfBooks;
coutt<<endl<<"Enter the number of members: ";
cin>>BS.numOfMembers;
BS.storeBooks();
BS.storeMembers();
bookPurchase();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.