How to get the integers 35 and 50 in the output of this program ?

I am really very new in C++ programming and its been only a month i started learning Object Oriented Programming and i was learning this program of inheritance and I am not getting the output i wanted. What is wrong in this source code below.

  #include<iostream>
using namespace std;
class enemy{
    private:
        int attackpower;
        public:
            void enemys(int x)
            {
                attackpower=x;
            }

    };

            class monster : public enemy
            {
                public:
                 enemy::enemys;

            };

            class ninja : public enemy
            {
                public:
                 enemy::enemys;
            };


int main()
{
    monster object1;
cout<<"You get points : - "<<endl;  object1.enemys( 35);

    ninja object2;
cout<<"You get points  : - "<<endl; object2.enemys( 50);

}

well the output I get is this :

output : You get points : - You get points : -

I am suppose to get the integers i mentioned after "You get points : - 35 " and "You get points - 50"

as per the program I am not getting the integers in output. WHat could be wrong?

I am new to programming so please kindly help me.

Thanks a lot.

Answers


Here's some code that makes (very slight) use of inheritance. Maybe you'll find it useful

  #include<iostream>
using namespace std;
class enemy{
    private:
        int attackpower;
        public:
            enemy(int ap)
            {
                attackpower = ap;
            }
            int get_attackpower()
            {
                return attackpower;
            }

    };

        class monster : public enemy
        {
        public:
            monster() : enemy(35)
            {
            }
        };

        class ninja : public enemy
        {
        public:
            ninja() : enemy(50)
            {
            }
        };


int main()
{
    monster object1;
    cout<<"You get points : - " << object1.get_attackpower() << endl;

    ninja object2;
    cout<<"You get points  : - "<< object2.get_attackpower() << endl;

}

output is

You get points : - 35
You get points  : - 50

Need Your Help

How to copy highlighted text from a webview in android honeycomb 3.0?

android webview android-3.0-honeycomb highlight

In Android 3.0 (Honeycomb) we have this feature that when we long press any text on webview it is highlighted &amp; some options come up on the action bar. One of which is copy. When we press copy ...

null value is evaluating to TRUE

swift parse.com

I have empty value (null) for "homeTeamScore" field on Parse backend. Parse field type is Number.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.