class animals
{
   public:
   int weight ;
   string name;
   string sound;
   public :
   void setName(string name){
  this->name=name;
  }
   string getName(){
    return this->name;
   }
 
    void setSound(string sound){
    cout<<sound<<endl;
  this->sound=sound;
    }
   string getSound(){
    return this->sound;
   }
    void setWeight(int weight){
    if(weight>0)
    this->weight=weight;
    else cout<<"weight should be more than 0";
   }
    int getWeight(){
    return this->weight;
   }
};

class cat : public animals
 {
  public :
  cat():animals()
   {
 
  setSound("meoooow");
 }
 void drinkmilk()
 {
  cout<<"cat love milks";
 }
 
 };

class dog : public animals
 {
  public :
  dog():animals()
   {
  setSound("bark");
 }
 void digHole()
 {
  cout<<"dig hole";
 }
 
 };

#include<bits/stdc++.h>
using namespace std;
#include "animals.h"
#include "dog.h"
#include "cat.h"
int main()
{

dog fido ;
fido.digHole();
cout<<fido.getSound()<<endl;
fido.setWeight(10);
cout<<fido.getSound();
}

Comments

Popular posts from this blog

What are Master and Slave databases and how does pairing them make web apps faster?

Storage Scalability ->Vertical scaling and Horizontal scaling Sharding