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

There is an error at the beginning of my code. Could anyone explain why and what

ID: 3535524 • Letter: T

Question

There is an error at the beginning of my code. Could anyone explain why and what approach I should take about it? Thanks!


Here's my code:


#include <string>

#include <iostream>

#include <iomanip>


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;

};


#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<<"There are" <<copies<< "copies of this book.";

}


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::showPrice()

{

cout<< "The price of this book is "<<price;

}


void bookType::updatePrice( double myPrice)

{

price=myPrice;

}


double bookType::getPrice()

{

return price;

}


//---------------------------------------------------------------------------------------------------------


#include <iostream>

#include "bookType.h"


using namespace std;


int main()

{

cout<<"This program allows you to work with an ADT bookType.";

bookType myBooks[100];


string str;

double price;

int copies;

char choice;

int count=0;


do

{

cout<<"Please Enter A Book Title: "<<endl;

cin>>str;

myBooks[count].setAuthor(str);

int j=0;

do

{

cout<<"Please Enter The Author's Name: "<<endl;

cin>>str;

myBooks[count].setAuthor(str);

j++;


cout<< "Would You Like To Enter More Authors (Y/N)? ";

cin>> choice;

} while (j<4 && tolower(choice) != 'n');


cout<<" Please Enter A Publisher: ";

cin>>str;

myBooks[count].setPublisher(str);


cout<<" Please Enter An ISBN Number: ";

cin>>str;

myBooks[count].setISBN(str);


cout<<" Please Enter The Price Of The Book: ";

cin>>price;

myBooks[count].setPrice(price);


cout<<"Please Enter How Many Copies Of The Book Are Available: ";

cin>>copies;

myBooks[copies].setCopies(copies);


count++;

cout<<"Would You Like To Enter More Books (Y/N)? ";

cin>> choice;


if (choice <92)

choice += 32;


} while ( choice != 'n');


do

{

cout<<"To Search For A Book By Title Press 'T'. "<<endl;

cout<<"To Search For A Book By ISBN Number Press 'I'. "<<endl;

cout<<"To Update The Number Of Copies Press 'U'. "<<endl;

cout<< " Press 'Q' to quit. "<<endl;

cout<<" Please Enter Your Choice: "<<endl;


int i;

switch( tolower(choice))

{

case 'T': cout<<"Please Enter The Title You Would Like To Search: ";

cin>> str;


for( i=0; i< count; i++)

if(myBooks[i].compareTitle(str))

break;

if(i==count)

cout<<"Cannot Be Found.";

else

cout<<" A Book Has Been Found!";

break;


case 'U': cout<<"Please Enter The Title You Would Like To Search: ";

cin>>str;


for( i=0; i< count; i++)

if (myBooks[i].compareTitle(str))

break;

if (i==count)

cout<<"Cannot Be Found";

else

{

cout<<" Enter The Number Of Copies: ";

cin>> copies;

myBooks[i].updateCopies(copies);

} break;


case 'Q':

return 0;

}

} while ( true);

return 0;

}

















Explanation / Answer

#include <string>#include <iostream> #include <iomanip> 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; }; #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<<"There are" <<copies<< "copies of this book."; } 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::showPrice() { cout<< "The price of this book is "<<price; } void bookType::updatePrice( double myPrice) { price=myPrice; } double bookType::getPrice() { return price; } #include <string>#include <iostream> #include <iomanip> 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; }; #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<<"There are" <<copies<< "copies of this book."; } 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::showPrice() { cout<< "The price of this book is "<<price; } void bookType::updatePrice( double myPrice) { price=myPrice; } double bookType::getPrice() { return price; }
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