a. Each object of the class BookType can hold the following information about a book: title, up to four authors, publisher, ISBN, price, and number of copies in stock. To keep track of the number of authors, add another member variable.
b. Include the member functions to perform the various operations on objects of type BookType. For example, the usual operations that can be performed on the title are to show the title, set the title, and check whether a title is the same as the actual title of the book. Similarly, the typical operations that can be performed on the number of copies in stock are to show the number of copies in stock, set the number of copies in stock, update the number of copies in stock, and return the number of copies in stock. Add similar operations for the publisher, ISBN, book price, and authors. Add the appropriate constructors and a destructor (if one is needed). Also add the necessary preconditions and postconditions.
#include <iostream>
#include <string>
using namespace std;
class BookType
{
string title;
string* auth;
int numAut;
string publish;
int ISBN;
double price;
int numCopy;
public:
BookType(){}
BookType(string _title, string* _auth, int _numAut, string _publish,
int _ISBN, double _price, int _numCopy):title(_title),numAut(_numAut),
publish(_publish),ISBN(_ISBN),price(_price),numCopy(_numCopy)
{
auth = new string[numAut];
for (int i = 0; i < numAut; i++)
{
auth[i] = _auth[i];
}
}
~BookType() { delete[]auth;}
void setTitle()
{
cout << "Enter a title of book: ";
cin >> title;
}
string getTitle() { return title; }
bool checkTitle(string tit)
{
if (title == tit)
return true;
else
return false;
}
void showCopies() { cout << "There are " << numCopy << " copies"; }
void setCopies()
{
cout << "Enter a number of copies: ";
cin >> numCopy;
}
void updateCopies()
{
cout << "There are " << numCopy << " copies"<<endl;
cout << "Enter a title of copies to update: ";
cin >> numCopy;
}
int GetCopies() { return numCopy; }
void showPublisher() { cout << "Publisher is " << publish; }
void setPublisher()
{
cout << "Enter a publisher: ";
cin >> publish;
}
void updatePublisher()
{
cout << "Publisher is " << publish<<endl;
cout << "Enter a publisher: ";
cin >> publish;
}
string GetPublisher() { return publish; }
void showISBN() { cout << "ISBN is " << ISBN; }
void setISBN()
{
cout << "Enter ISBN: ";
cin >> ISBN;
}
void updateISBN()
{
cout << "ISBN is " << ISBN << endl;
cout << "Enter ISBN: ";
cin >> ISBN;
}
int GetISBN() { return ISBN; }
void showPrice() { cout << "Price is " << price; }
void setPrice()
{
cout << "Enter price: ";
cin >> price;
}
void updatePrice()
{
cout << "Price is " << price << endl;
cout << "Enter price: ";
cin >> price;
}
double GetPrice() { return price; }
void showAuthors()
{
cout << "\nAuthors are ";
for(int i =0 ;i<numAut;i++)
cout<< auth[i];
}
void setAuthors()
{
do
{
cout << "Enter a number of authors (4 - max): ";
cin >> numAut;
} while (numAut > 4);
delete[]auth;
auth = new string[numAut];
cout << "Enter authors: ";
for (int i = 0; i<numAut; i++)
cin>> auth[i];
}
void updateAuthors()
{
cout << "\nAuthors are ";
for (int i = 0; i<numAut; i++)
cout << auth[i]<<" ";
do
{
cout << "Enter a number of authors (4 - max): ";
cin >> numAut;
} while (numAut > 4);
delete[]auth;
auth = new string[numAut];
cout << "Enter authors: ";
for (int i = 0; i<numAut; i++)
cin >> auth[i];
}
string* GetAuthors() { return auth; }
};
int main()
{
string aut[2] = { "Joan Roaling","Ron Uisley" };
BookType a("Harry Potter", aut, 2, "Bloomsbury", 1234, 305, 100);
cout << "\na.showAuthors() = ";
a.showAuthors();
cout << "\na.checkTitle(\"World\") = " << a.checkTitle("World");
cout << "\na.GetCopies() = " << a.GetCopies();
cout << "\na.GetISBN() = " << a.GetISBN();
cout << "\na.GetPrice() = " << a.GetPrice();
cout << "\na.GetPublisher() = " << a.GetPublisher()<<endl;
BookType b;
b.setAuthors();
b.setCopies();
b.setISBN();
b.setPrice();
b.setTitle();
cout << "\nb.showAuthors() = ";
cout << endl;
cout << "\nb.checkTitle(\"World\") = " << b.checkTitle("World");
cout << "\nb.GetCopies() = " << b.GetCopies();
cout << "\nb.GetISBN() = " << b.GetISBN();
cout << "\nb.GetPrice() = " << b.GetPrice();
cout << "\nb.GetPublisher() = " << b.GetPublisher();
b.updatePrice();
b.showPrice();
}
Comments
Leave a comment