Question

Animal classes and create instances of them. In the main method do the following: Create a Farm of size 10 Create 5 Animal Ob

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code in cpp:

#include <iostream>

#include <iomanip>

using namespace std;

class Animal

{

private:

string name;

int birthYear;

float weight;

char gender;

public:

Animal(string n, int b, float w, char g)

{

name = n;

birthYear = b;

weight = w;

gender = g;

}

void

printData()

{

cout << "Name : " << name << endl;

cout << "Birth year : " << birthYear << endl;

cout << "Weight : " << weight << endl;

cout << "gender : " << gender << endl;

cout << endl;

}

};

// Driver function

int

main()

{

Animal a1("cow", 2012, 1000.5, 'f');

Animal a2("pig", 2009, 550.5, 'm');

Animal a3("donkey", 1999, 773.42, 'm');

Animal a4("sheep", 2016, 164.23, 'f');

Animal a5("goose", 2004, 10.75, 'f');

a1.printData();

a2.printData();

a3.printData();

a4.printData();

a5.printData();

}

Output:

Birth year: 2012 Weight 1000.5 gender f Name pig Birth year: 2009 Weight 550.5 genderm Name donkey Birth year 1999 Weight 773

Add a comment
Know the answer?
Add Answer to:
Animal classes and create instances of them. In the main method do the following: Create a Farm of size 10 Create 5 Animal Objects with the details specified in the table below Add the 5 Animal objec...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT