my getter and setter function not working

Please learn to use code tags, they make reading and commenting on source code MUCH easier.

How to use code tags: http://www.cplusplus.com/articles/jEywvCM9/

There are other tags available.

How to use tags: http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either.
Then your code should be shorter. Try to post a "minimal" example that illustrates the problem!

...instead of throwing in loads of code, requiring people to figure out what might be the relevant part 😑

(often, writing a minimal example that shows the problem already brings you to the solution)
Last edited on
Well you wrote:
1
2
3
4
5
6
cout<< getNoID(bookNoID) << endl;
cout<< getAuthorName(authorName) << endl;
cout<< getbookName(bookName) << endl;
cout<< getbookFormat(bookFormat) << endl;
cout<< getbookGenre(bookGenre) << endl;
cout<< getbookRating(bookRating) << endl;

Each of those functions were called with ONE argument (none of which were actually defined).


However, when you defined your functions you wrote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
string getAuthorName()
{
return authorName;
}
string getbookName()
{
return bookName;
}
string getbookFormat()
{
return bookFormat;
}
string getbookGenre()
{
return bookGenre;
}
int getbookRating()
{
return bookRating;
}

and those functions take NO arguments.


But take the advice of the others:
- USE CODE TAGS
- write and test ONE FUNCTION AT A TIME
First off, you need to get rid of the compilation errors.
Lines 2, 4: You should have no need for C headers in a C++ program.
Lines 33-36: No need to initialize strings. Their constructors will initialize them to an empty string.
Lines 41-71: It's a poor habit to name your arguments the same as your class members.
Line 102: What's the purpose of having unnamed arguments?
Lines 104-108: Each call to Book2's constructor wipes out what was set by the previous call.
Line 333: You declare driver as a local variable in main.
Line 114: This instance of driver overrides the variable you declared at line 333.
Lines 116-120: Each call to Book2's constructor wipes out what was set by the previous call.
Lines 123-128: Your arguments do not exist. Your getters take no arguments.
Line 154: You call New_Book(). Line 175: New_Book() declares another instance of driver which overrides the instance in the calling function.
Lines 176-188: Why are these arrays?
Line 216-220: Each iteration through the loop wipes out the previous values.
Line 226: The local instance of driver goes out of scope losing the last set of values you stores in it.
Line 227: Delete_Book() has the same problems.

You need to go back and study arrays, passing arguments.

You have been asked multiple times to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?

Last edited on
Do NOT remove the text you already had! Edit the post to ADD code tags.

[ETA]: Hmmmm, I guess that doesn't matter any more, the OP was given the boot by someone.
Last edited on
Topic archived. No new replies allowed.