Compare sallaries of two employs from class

Write your question here.please tell me that how to acces instances of class and how i compare instances in main ???????????


class book{
private:
int id;
string name;
int n;

public :
void add()
{

cout<<"Enter Book ID number "<<endl;
cin>>id;
cout<<"Enter book name "<<endl;
cin>>name;
cout<<"Enter number of Page of Book"<<endl;
cin>>n;

}
int page()
{
return n;
}
int main()
{
if(ad.page()>c.page())


{cout<<"Page more"<<ad.page()<<endl;
}
}
What does your book class have to do with employee salaries?

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
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
#include <iostream>
#include <string>

using namespace std;

class book{
    private:
        int id;
        string name;
        int pages; // changed n to pages to make it easier to understand

    public:
        void add(){
            cout << "Enter book ID number" << endl;
            cin >> id;
            cout << "Enter book name" << endl;
            cin >> name;
            cout << "Enter number of pages" << endl; // changed to make it easier to understand
            cin >> pages;
            cout << endl;
        }
        int getPages(){ return pages; } // changed the name of this function to make it easier to understand
        string getName(){ return name; } // added this function to get the name
};

int main(){
    book ad, c; // you have to create books here in order to use them

    // run these 2 functions to enter information about the books
    ad.add();
    c.add();

    // Now that the books have been created, you can compare instances of both

    if(ad.getPages() > c.getPages()){
        cout << ad.getName() << " has " << ad.getPages() - c.getPages() << " more pages." << endl;
    }
    else if(ad.getPages() < c.getPages()){
        cout << c.getName() << " has " << c.getPages() - ad.getPages() << " more pages." << endl;
    }
    else{
        cout << ad.getName() << " and " << c.getName() << " have the same number of pages." << endl;
    }

    return 0;
}
Topic archived. No new replies allowed.