I am trying to do an exercise. To test parts of the program, I want to populate some vectors and then read the data from these vector. The program I wrote compiles and runs, just not correctly. The program doesn't seem to be accessing the data in the populated vectors. When I run a function, the output doesn't print. The program goes directly to the end of program message (Enter a character to exit.) The error exceptions work correctly. I am least confident about the way I populated the vectors, using a Put_???? function. It was the best I could do to adapt the examples of constructors to this exercise.
What have I done wrong? Thanks.
class Book {
private:
vector<string>ISBNs;
vector<string>Titles;
vector<string>Authors;
vector<int>CR_Dates;
vector<char>Checked_In;
public:
void Get_author()
{
string title = " ";
int crdate = 1900;
cout <<"Please enter the book's title and copyright date, separated by a space.\n";
cin >> title >> crdate ;
if (crdate < 1900 || crdate > 2010) throw errorcrdate; // Copyright dates of books are after 1900 up to the current year.
for (int j = 0; j < title.length(); j++) { // Verifies that the characters of the book's title are letters.
if (isalpha(title[j])) {
continue;
} else {
throw errorauthor;
}
}
for (int i = 0; i < Titles.size(); i++) {
if (title == Titles[i] && crdate == CR_Dates[i]) {
cout << "The author of the requested book is " << Authors[i] << ".\n";
} else {
cout << "There is no author in our records corresponding to your book title and copyright date.\n";
}
}
}
SNIP
void Put_Titles()
{
Titles[0] = "CatintheHat";
Titles[1] = "CharlottesWeb";
Titles[2] = "NineteenEightyfour";
return;
}
void Put_CR_Dates()
{
CR_Dates[0] = 1957;
CR_Dates[1] = 1952;
CR_Dates[2] = 1949;
return;
}
void Put_Authors()
{
Authors[0] = "DrSeuss";
Authors[1] = "EBWhite";
Authors[2] = "GeorgeOrwell";
return;
SNIP
};
SNIP
The revised program compiles. However, I seem to have made another mistake which is leading to a range error upon running. I am re-checking my vectors and subscripts.
Re: Indention,
I use MS VC++ 2010 Express. It indents code automatically. When I cut and paste code into the forum, the VC++ format is completely erased. I try to re-indent the best I can.