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

Modify the attached implementation of bookType and authorType so that the bookTy

ID: 3670585 • Letter: M

Question

Modify the attached implementation of bookType and authorType so that thebookType class uses a pointer to authorType and creates a dynamic array to store the authors.

//AUTHORTYPE HEADER FILE

#ifndef H_AuthorType
#define H_AuthorType

#include <iostream>

class authorType
{
public:
authorType();
void setName(std::string fullName);
void printName() const;
bool isAuthor(std::string fullName) const;
private:
std::string firstName;
std::string lastName;

std::string getFirstName(std::string fullName) const;
std::string getLastName(std::string fullName) const;
};

#endif

//BOOKTYPE HEADER FILE

#ifndef H_BookType
#define H_BookType

#include <iostream>

class bookType
{
public:
void printInfo() const;
void setInfo(std::string title, std::string ISBN,
std::string Publisher, int PublishYear,
std::string auth, double cost, int copies,
int numAuthors);
void setInfo(std::string title, std::string ISBN,
std::string Publisher, int PublishYear,
double cost, int copies, int numAuthors);

void addAuthor(std::string fullName);
int getMaxAuthors() const;

int getStock() const;
bool isInStock() const;

bool isISBN(std::string isbnStr) const;
bool isTitle(std::string titleStr) const;
bool isAuthor(std::string authorName) const;

bookType();
private:
static const int MAXAUTHORS = 4;
std::string bookTitle;
std::string bookISBN;
std::string bookPublisher;
int bookYear;

authorType authors[MAXAUTHORS];

int numberOfAuthors;
double price;
int inStock;
};

#endif

#include <iostream>


using namespace std;


int main()
{


return 0;
}


#include <iostream>
#include <string>
#include <sstream>

using namespace std;

authorType::authorType()
{
firstName = "";
lastName = "";
}

void authorType::printName() const
{
cout << "Author: " << lastName << ", " << firstName << endl;
}

void authorType::setName(string fullName)
{
firstName = getFirstName(fullName);
lastName = getLastName(fullName);
}

bool authorType::isAuthor(string authorName) const
{
string fName, lName;

lName = getLastName(authorName);

if (authorType::lastName == lName)
{
fName = getFirstName(authorName);
if (authorType::firstName == fName)
return true;
}

return false;
}

string authorType::getFirstName(string fullName) const
{
string firstName;

istringstream StrStream(fullName);

StrStream >> firstName;

return firstName;
}

string authorType::getLastName(string fullName) const
{
string firstName, lastName;

istringstream StrStream(fullName);

StrStream >> firstName;
StrStream >> lastName;

return lastName;
}

#include <iostream>
#include <iomanip>

using namespace std;

bookType::bookType()
{
bookTitle = "";
bookISBN = "";
bookPublisher = "";
numberOfAuthors = 0;
price = 9.99;
inStock = 0;
}

void bookType::printInfo() const
{
cout << "Title: " << bookTitle << endl;
cout << "ISBN: " << bookISBN << endl;
cout << "Publisher: " << bookPublisher << endl;
cout << "Number of authors: " << numberOfAuthors << endl;
for (int i = 0; i < numberOfAuthors; i++)
authors[i].printName();
cout << setprecision(2) << fixed
<< "Price: $" << price << endl;
cout << "Stock: " << inStock << endl;
}

void bookType::setInfo(std::string title, std::string isbn,
std::string publisher, int publishYear,
std::string author, double cost, int copies,
int numAuthors)
{
bookTitle = title;
bookISBN = isbn;
bookPublisher = publisher;
bookYear = publishYear;
authors[0].setName(author);
price = cost;
inStock = copies;
numberOfAuthors = numAuthors;
}

// Set information without author
void bookType::setInfo(std::string title, std::string isbn,
std::string publisher, int publishYear,
double cost, int copies, int numAuthors)
{
bookTitle = title;
bookISBN = isbn;
bookPublisher = publisher;
bookYear = publishYear;
price = cost;
inStock = copies;
numberOfAuthors = numAuthors;
}

void bookType::addAuthor(string fullName)
{
if (!isAuthor(fullName))
{
authors[numberOfAuthors].setName(fullName);
numberOfAuthors++;
}
}

int bookType::getMaxAuthors() const
{
return MAXAUTHORS;
}

int bookType::getStock() const
{
return inStock;
}

bool bookType::isInStock() const
{
if (inStock > 0)
return true;
else
return false;
}

bool bookType::isISBN(std::string isbnStr) const
{
return (bookISBN == isbnStr);
}

bool bookType::isTitle(std::string titleStr) const
{
return bookTitle == titleStr;
}

bool bookType::isAuthor(std::string authorName) const
{
for (int i = 0; i < numberOfAuthors; i++)
return authors[i].isAuthor(authorName);

return false;
}

Explanation / Answer


int main(){
bookType * bktype = new authType();

//we can pass length to dynamic array like
int length;
cout<<"Enter length";
cin>>length;
  
// dynamic memory allocation
bookType *bktype = new authType[length];
  
// remaining functions
  
}

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