Skip to content
Snippets Groups Projects
Commit 8a978688 authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 1 - Animal.cpp

parent f31ed2e1
No related branches found
No related tags found
No related merge requests found
......@@ -2,52 +2,41 @@
using namespace std;
class Animal
{
protected:
float number;
public:
Animal(){};//Default constructor
Animal (int numb):number(numb){}; //Constructor with member initialization list
class Animal {
protected:
float number;
public:
Animal(){}; // Default constructor
Animal(int numb) : number(numb){}; // Constructor with member initialization list
};
class SlaughterCattle: public Animal
{
private:
float weight;
public:
SlaughterCattle(int numb, float wei):Animal(numb),weight(wei){};
void displaydata()
{
cout <<"There are "<<number << " animals with " <<weight <<" kg each available"<<endl;
}
class SlaughterCattle : public Animal {
private:
float weight;
public:
SlaughterCattle(int numb, float wei) : Animal(numb), weight(wei){};
void displaydata() { cout << "There are " << number << " animals with " << weight << " kg each available" << endl; }
};
class DairyCattle: public Animal
{
private:
float milkyield;
public:
DairyCattle(int numb, float m_y):Animal(numb), milkyield(m_y){};
void displaydata()
{
cout << "There are " << number << " animals with an average milk yield of " << milkyield << " l available"<<endl;
}
class DairyCattle : public Animal {
private:
float milkyield;
public:
DairyCattle(int numb, float m_y) : Animal(numb), milkyield(m_y){};
void displaydata() { cout << "There are " << number << " animals with an average milk yield of " << milkyield << " l available" << endl; }
};
int main()
{
SlaughterCattle Pig(100,50);
Pig.displaydata();
DairyCattle Cow(25,5);
Cow.displaydata();
return 0;
}
int main() {
SlaughterCattle Pig(100, 50);
Pig.displaydata();
DairyCattle Cow(25, 5);
Cow.displaydata();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment