Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Some of the characteristics of a book are the title, author(s), publisher, IS

ID: 3768795 • Letter: A

Question

a. Some of the characteristics of a book are the title, author(s), publisher,

ISBN, price, and year of publication. Design a class bookType that
defines the book as an ADT.
i. 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.
ii. 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 showthe 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).


b. Write the definitions of the member functions of the class bookType.

Explanation / Answer

#include <iostream>

using namespace std;
class booktype
{
public:
string title,authors[4],publisher,isbn;
double price;
int year_pub,num_authors,num_stock;
public:
booktype(string t,string author,string publisher);
void showtitle();
void readauthors(int n);
void setprice(double p);
void showprice();
void shownum_stock();
void setnumstock(int n);
};
booktype::booktype(string t,string isbn,string publisher)
{
title=t;
this->isbn=isbn;
this->publisher=publisher;
}
void booktype::showtitle()
{
cout<< "title"<<title<<endl;
}
void booktype::readauthors(int n)
{
int i;
if(n>4)
{
cout<< "number of authors exceeded"<<endl;
return;
}
for(i=1;i<=4;i++)
{
string s;
cout<<"enter author name"<<i<<endl;
cin>>s;
authors[i]=s;
}
cout<<"list of authors"<<endl;
for(i=1;i<=4;i++)
cout<<authors[i];
  
}

void booktype::setprice(double p)
{
price=p;
  
}
void booktype::showprice()
{
cout<<"price"<<price;
  
}
void booktype::shownum_stock()
{
cout<<"number of books in stock"<<num_stock<<endl;
  
}
void booktype::setnumstock(int n)
{
num_stock=n;
}
int main()
{
booktype bobj("oops thru cpp","123oop","pearson");
bobj.showtitle();
bobj.readauthors(2);
bobj.setprice(500);
bobj.showprice();
bobj.setnumstock(50);
bobj.shownum_stock();

return 0;
}

For any furthur queries please contact me.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote