Answer to Question #343953 in C++ for Secret Agent

Question #343953

Create a one (1) program that will apply all polymorphism techniques such as function, runtime and operator overloading.


1
Expert's answer
2022-05-23T10:19:44-0400
#include <iostream>
using namespace std;
class Human{
    public:
        int power;
    
        Human(int n){
            power = n;
        }
        Human operator +(Human const &obj){
            Human combined(100);
            combined.power=power+obj.power;
            return combined;
        }
        
        virtual void scream(){
            for(int i=0; i<power;i++)
                cout<<"A";
            cout<<endl;
        }
        void scream(int n){
            for(int i=0; i<n;i++)   
                cout<<"A";
            cout<<endl;
        }
};


class Child: public Human{
    void scream(){
        cout<<"aaaaaa"<<endl;
    }
};
int main()
{
    Human me(10), you(5);
    me.scream();
    me.scream(2);
    Human mutant = me+you;
    mutant.scream();
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS