have code, need comments. //header #include <string> using namespace std; class
ID: 663295 • Letter: H
Question
have code, need comments.
//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
The second part is good. Overall good.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.