I have a class BookType and it has authors in an array(4 maximum) how can i set the authors and return the array to print it out?
class BookType{
public:
/// method GetAuthors to return an array of authors
string GetAuthors() const;
/// method SetNrOfAuth to set the nr of authors
void SetNrOfAuth(int nr);
private:
string authors[4];
int nrOfAuthors;
};
#include "BookType.h"
int main (int argc, char * const argv[]) {
BookType b[100];
int nr;
cout << "enter nr of authors, max 4 authors" << endl;
cin >> nr;
b[0].SetNrOfAuth(nr);
string a[nr];
for (int i=0; i<nr; i++) {
cout << "enter author nr "<< i+1 <<endl;
cin >> a[i];
}
b[0].SetAuthor(a);
//How do i print out the authors to the screen?
for (int x=0; x<b[0].GetNrOfAuth(); x++) {
cout << //????
}
return 0;
}
I have supplied a main, to represent what i want to do, can someone help me?
First this doesn't makes sense, IMO your class name "BookType" does not have/do what its name imply!?
You could try to store your authors names in a vector of string's, and when you add author to the vector you just clamp it to your max (4).
Something like:
Thank you so much for your time, i did not include all variables and methods, probably why i didnt make any sense, but you answered my question very good thank you