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. //implementation #include <ios

ID: 663334 • Letter: I

Question

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

//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;
};

Explanation / Answer

Answer:

//header files

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

//constructor
bookType::bookType()
{

//declare the variables like title
title = " ";

//perform for loop due to accessing authors
for (int i = 0; i < 4; i++)

//initializing the variables
authors[i] = " ";
publisher = " ";
isbn = " ";
price = 0;
copies = 0;
authorsno = 0;
}
void bookType::settitle(string mytitle)//method for settitle
{
title = mytitle;//return the title
}
string bookType::gettitle()//method for gettitle
{
return title;//return title
}
bool bookType::comparetitle(string othertitle)//we have to compare the title among methods comparetitle and the argument other title
{
return (title.compare(othertitle) == 0);//return title
}
void bookType::setauthor(string myauthor)
{
authorsno = authorsno %4;//check authors number with in the value 4
if (myauthor.compare(" ") == 0)//compare the values using if condition
return;
else
{
authors[authorsno] = myauthor;//get myauthor function
authorsno++;//increment the value author
}
}
void bookType::showauthors()//display authors
{
for (int i = 0; i < authorsno; i++)
cout << authors [i] << ", ";
cout << " ";
}
void bookType::updateauthor(string myauthor)//update the book author names
{
setauthor(myauthor);//get myauthor from setauthor function
}
string *bookType::getauthors()
{
return authors;
}
void bookType::setcopies(int mycopies)//method for copies in the books
{
copies = mycopies;//return the copies
}
void bookType::showcopies()//method for display the authors
{
cout << "The number of copies " << copies;//print the copies
}
void bookType::updatecopies(int mycopies)//updating an copies method
{
copies = mycopies;
}
int bookType::getcopies()//fetch the copies
{
return copies;
}
void bookType::setpublisher(string mypublisher)//method for publisher set
{
publisher = mypublisher;
}
void bookType::showpublisher()//display the publisher from the book
{
cout << publisher;
}
void bookType::updatepublisher(string mypublisher)//update the publisher function
{
publisher = mypublisher;
}
string bookType::getpublisher()//fetch the publisher function
{
return publisher;//return publisher
}
void bookType::setisbn(string myisbn)//set ISBN value
{
isbn = myisbn;//return ISBN value
}
void bookType::showisbn()
{
cout << isbn;//display ISBN value
}
void bookType::updateisbn(string myisbn)//update the value ISBN value
{
isbn = myisbn;//return ISBN value

}
string bookType::getisbn()//fetch the function from the ISBN value
{
return isbn;
}
bool bookType::compareisbn(string myisbn)//evaluate ISBN number function
{
return (myisbn.compare(isbn) == 0);//return ISBN
}
void bookType::setprice(double myprice)//set price value
{
price = myprice;//return price value
}
void bookType::showprice()//display the function of price value
{
cout << "The book price is " << price;//print the price value
}
void bookType::updateprice(double myprice)//updating the price value
{
price = myprice;//return price value
}
double bookType::getprice()//fetch the function price value
{
return price;
};
//main

//header files
#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;

//get author name
mybooks[count].setauthor (str);
j++;

//get one or more authors
cout << "More authors (Y/N)? " << endl;
cin >> choice;
}
while (j < 4 && tolower (choice) != 'n');
cout << "Enter publisher: " << endl;
cin >> str;

//get the publisher value
mybooks[count].setpublisher (str);
cout << "Enter ISBN: " << endl;
cin >> str;

//get the ISBN value
mybooks[count].setisbn(str);
cout << "Enter price: " << endl;
cin >> price;

//get the price value
mybooks[count].setprice (price);
cout << "Enter copies: " << endl;
cin >> copies;

mybooks[count].setcopies (copies);
count++;
cout << "Enter more books (Y/N)? " << endl;
cin >> choice;

//fetch one or more books
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
{

//print the values
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;

//get the title of the book
for (i = 0; i < count; i++)
if (mybooks[i].comparetitle(str))//search the book if existing or not from the user input
break;
if (i == count)
cout << "Book not found." ;
else
cout << "Book found." ;
break;
case 'I' : cout << "Enter ISBN to search: " ;
cin >> str;

//get ISBN value
for (i = 0; i < count; i++)
if (mybooks[i].compareisbn(str))//find if the ISBN value existing or not
break;
if (i == count)
cout << "Book not found." << endl;
else
cout << "Book found." << endl;
break;
case 'U' : cout << "Enter title to search: " ;
cin >> str;

//get the title
for (i = 0; i < count; i++)
if (mybooks[i].comparetitle(str))//find if the title value is existing or not
break;
if (i == count)
cout << "Book not found." << endl;
else
cout << "Enter the copies " << endl;
cin >> copies;
mybooks[i].updatecopies(copies);

//update the copies values
break;
case 'Q':
return 0;
}
}
while (true);
return 0;
};