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

I\'m having trouble with this program I\'m writing which requires the use of a c

ID: 3766349 • Letter: I

Question

I'm having trouble with this program I'm writing which requires the use of a class. Its a program to display book information and up to four authors for each book, everything displays except all of the authors.Whenever I run my program it only displays the first author and I don't know how to get it to store all the other authors and display them.

my member variable for authors is:

string author[4];

so far for my setAuthor I have what is displayed below and everythin else i have to print and update the author:

void bookType::setAuthor(string a)
{
   for (int j = 0; j < numOfAuthors; j++)
   {
       if (author[j] != "")
           author[j];
       else
           return;
   }
      
}

void bookType::showAuthor()
{
   cout << "Author: ";
   for (int j = 0; j < numOfAuthors; j++)
   {
       cout << author[j];
   }
       cout << endl;  
}
//updates the author.
void bookType::updateAuthor(string b)
{
   setAuthor(b);

}

and for my getAuthor I have:

string *bookType::getAuthors()
{
   return author;
}

please help me....

Explanation / Answer

There are lot of problems with the code

1) numOfAuthors is not defined in the code. I am not seeing any declaration for the same. Please check

2. string a used in setAuthor is not getting used anywhere. Looks like some problem with the declaration.

function should be changed to as shown below:

void bookType::setAuthor(string a)
{
   for (int j = 0; j < 4; j++)
   {
       if (author[j] != " ")
           author[j] = a;
       else
           return;
   }
      
}

it should solve your problem.

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