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

I have the code, but I need comments added to it. //header #include <string> usi

ID: 663304 • Letter: I

Question

I have the code, but I need comments added to it.

//header

#include <string>
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 ();

private:
   string title;
   string authors [4];
   string publisher;
   string isbn;
   double price;
   int copies;
   int authorsno;
};

//implementation

#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)
{
   authorsno = authorsno %4;
   if (myauthor.compare(" ") == 0)
       return;
   else
   {
       authors[authorsno] = myauthor;
       authorsno++;
   }
}

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 << "The number of copies " << copies;
}

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::setprice(double myprice)
{
   price = myprice;
}

void bookType::showprice()
{
   cout << "The book price is " << price;
}

void bookType::updateprice(double myprice)
{
   price = myprice;
}

double bookType::getprice()
{
   return price;
};

//main

#include <iostream>
#include "bookType.h"
using namespace std;

int main()
{
   cout << "Program that works with an ADT booktype" << endl;
   bookType mybooks[100];

   string str;
   double price;
   int copies;
   char choice;
   int count = 0;

   do
   {
       cout << "Enter book title: " << endl;
       cin >> str;
       mybooks[count].settitle (str);
       int j = 0;

           do
           {
               cout << "Enter author name: " << endl;
               cin >> str;
               mybooks[count].setauthor (str);
               j++;

               cout << "More authors (Y/N)? " << endl;
               cin >> choice;
           }

           while (j < 4 && tolower (choice) != 'n');
           cout << "Enter publisher: " << endl;
           cin >> str;
           mybooks[count].setpublisher (str);

           cout << "Enter ISBN: " << endl;
           cin >> str;
           mybooks[count].setisbn(str);

           cout << "Enter price: " << endl;
           cin >> price;
           mybooks[count].setprice (price);

           cout << "Enter copies: " << endl;
           cin >> copies;
           mybooks[count].setcopies (copies);

           count++;
               cout << "Enter more books (Y/N)? " << endl;
           cin >> choice;

           if (choice < 92)
               choice += 32;
   }

   while (choice != 'n');
   do
   {
       cout << "Search for a book by its title: T" << endl;
       cout << "Search for a book by its ISBN: I" << endl;
       cout << "Update the number of copies: U" << endl;
       cout << "Quit: Q" << endl;
       cout << "Enter your choice: " << endl;
       cin >> choice;

       int i;
       switch (tolower(choice))
       {
       case 'T' : cout << "Enter title to search: " ;
           cin >> str;

           for (i = 0; i < count; i++)
               if (mybooks[i].comparetitle(str))
                   break;

           if (i == count)
               cout << "Book not found." ;
           else
               cout << "Book found." ;
           break;

           case 'I' : cout << "Enter ISBN to search: " ;
           cin >> str;

           for (i = 0; i < count; i++)
               if (mybooks[i].compareisbn(str))
                   break;

           if (i == count)
               cout << "Book not found." << endl;
           else
               cout << "Book found." << endl;
           break;

           case 'U' : cout << "Enter title to search: " ;
           cin >> str;

           for (i = 0; i < count; i++)
               if (mybooks[i].comparetitle(str))
                   break;

           if (i == count)
               cout << "Book not found." << endl;
           else
               cout << "Enter the copies " << endl;
           cin >> copies;
           mybooks[i].updatecopies(copies);
           break;

           case 'Q':
               return 0;
       }
   }
   while (true);
   return 0;
   };

Explanation / Answer

#include <string>
using namespace std;
class bookType
{
public:
//Constructor which will be setting the data members to some initial value.  
bookType ();
//Function to set title of the book
void settitle (string);
//Function to get title of the book
string gettitle ();
//Function to compare title of the book
bool comparetitle (string);
//Function to set author of the book
void setauthor (string = " ");
//Function to show authors of the book
void showauthors ();
//Function to update authors of the book
void updateauthor (string = " ");
//Function to get authors of the book
string *getauthors ();
//Function to set copies of the book
void setcopies (int);
//Function to show copies of the book
void showcopies ();
//Function to update copies of the book
void updatecopies (int);
//Function to get copies of the book
int getcopies ();
//Function to set publisher of the book
void setpublisher (string);
//Function to show publisher of the book
void showpublisher ();
//Function to update publisher of the book
void updatepublisher (string);
//Function to get publisher of the book
string getpublisher ();
//Function to set isbn of the book
void setisbn (string);
//Function to show isbn of the book
void showisbn ();
//Function to update isbn of the book
void updateisbn (string);
//Function to get isbn of the book
string getisbn ();
//Function to compare isbn of the book
bool compareisbn (string);
//Function to set price of the book
void setprice (double);
//Function to show price of the book
void showprice ();
//Function to update price of the book
void updateprice (double);
//Function to get price of the book
double getprice ();
private:
//data member that will hold title of the book
string title;
//data member that will hold authors of the book
string authors [4];
//data member that will hold publisher of the book
string publisher;
//data member that will hold isbn of the book
string isbn;
//data member that will hold price of the book
double price;
//data member that will hold copies of the book
int copies;
//data member that will hold number of authors of the book
int authorsno;
};
//implementation
#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)
{
authorsno = authorsno %4;
if (myauthor.compare(" ") == 0)
return;
else
{
authors[authorsno] = myauthor;
authorsno++;
}
}
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 << "The number of copies " << copies;
}
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::setprice(double myprice)
{
price = myprice;
}
void bookType::showprice()
{
cout << "The book price is " << price;
}
void bookType::updateprice(double myprice)
{
price = myprice;
}
double bookType::getprice()
{
return price;
};
//main
#include <iostream>
#include "bookType.h"
using namespace std;
int main()
{
cout << "Program that works with an ADT booktype" << endl;
//Creates 100 objects of books
bookType mybooks[100];
string str;
double price;
int copies;
char choice;
int count = 0;
//For each of the books set the properties of books
do
{
    //get the book title  
cout << "Enter book title: " << endl;
cin >> str;
mybooks[count].settitle (str);
int j = 0;
do
{
cout << "Enter author name: " << endl;
cin >> str;
mybooks[count].setauthor (str);
j++;
cout << "More authors (Y/N)? " << endl;
cin >> choice;
}
while (j < 4 && tolower (choice) != 'n');
cout << "Enter publisher: " << endl;
cin >> str;
mybooks[count].setpublisher (str);
cout << "Enter ISBN: " << endl;
cin >> str;
mybooks[count].setisbn(str);
cout << "Enter price: " << endl;
cin >> price;
mybooks[count].setprice (price);
cout << "Enter copies: " << endl;
cin >> copies;
mybooks[count].setcopies (copies);
count++;
cout << "Enter more books (Y/N)? " << endl;
cin >> choice;
if (choice < 92)
choice += 32;
}
while (choice != 'n');//If user type n then stop getting the values
//loop which will perform searches on the objects we created
do
{
cout << "Search for a book by its title: T" << endl;
cout << "Search for a book by its ISBN: I" << endl;
cout << "Update the number of copies: U" << endl;
cout << "Quit: Q" << endl;
cout << "Enter your choice: " << endl;
cin >> choice;
int i;
switch (tolower(choice))
{
case 'T' : cout << "Enter title to search: " ;
cin >> str;
for (i = 0; i < count; i++)
if (mybooks[i].comparetitle(str))
break;
if (i == count)
cout << "Book not found." ;
else
cout << "Book found." ;
break;
case 'I' : cout << "Enter ISBN to search: " ;
cin >> str;
for (i = 0; i < count; i++)
if (mybooks[i].compareisbn(str))
break;
if (i == count)
cout << "Book not found." << endl;
else
cout << "Book found." << endl;
break;
case 'U' : cout << "Enter title to search: " ;
cin >> str;
for (i = 0; i < count; i++)
if (mybooks[i].comparetitle(str))
break;
if (i == count)
cout << "Book not found." << endl;
else
cout << "Enter the copies " << endl;
cin >> copies;
mybooks[i].updatecopies(copies);
break;
case 'Q':
return 0;
}
}
while (true);
return 0;
};