Need help with classes (NOT SCHOOL)

Okay I been out of the game for awhile, I forgot how to put the users input into the function when working with classes. Even the damn lingo for coding I'm rusty on so bare with me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef ACTION_H
#define ACTION_H

using namespace std;

class action
{
    public:
        action();
        int getNumberOfBooks();
        string getSection();
        string getBookName();
        int getRating();
        void displayInfo();


    private:
        int numberOfBooks;
        string section;
        string bookName;
        int rating;

};

#endif // ACTION_H



#include <iostream>
#include "action.h"

using namespace std;


int main()
{
    action Info;
    string answer;

    cout << "What book are you interested in? ";
    getline(cin, answer);
    //HOW TO PUT THIS ANSWER INSIDE OF OUR GETBOOKNAME SHIT...


    return 0;
}



#include <iostream>
#include "action.h"

using namespace std;

// GETS NUMBER OF BOOKS
int action::getNumberOfBooks()
{
    return numberOfBooks;
}

//GETS SECTION OF BOOK
string action::getSection()
{
    return section;
}

//GETS BOOK NAME
string action::getBookName()
{
    return bookName;
}

//GETS BOOK RATING
int action::getRating()
{
    return rating;
}


//THIS GATHERS ALL INFO THE USER TYPES THEN DISPLAYS IT
void action::displayInfo()
{
    cout << "You said there is: " << numberOfBooks << " books in the library.\n";
    cout << "The section is: " << section << ".\n";
    cout << "Book name is: " << bookName << ".\n";
    cout << "Rating of that book is: " << rating << ".\n";
}

//DON'T WORRY ABOUT
action::action()
{

}
Last edited on
So to put that 'answer' in your getBookName() function, you will need to create an object and use that object to call that function.

So on line 42, you should do something like this:
1
2
action myobject;  // create an object of action class
answer = myobject.getBookName();


Hope this helps!
Thanks for the refresher. Problem solved.
Topic archived. No new replies allowed.