Read an integer as the number of Sheep objects. Assign mySheep with an array of that many Sheep objects. For each object
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Read an integer as the number of Sheep objects. Assign mySheep with an array of that many Sheep objects. For each object
Answer in C++ please!
#include <iostream>using namespace std;
class Sheep { public: Sheep(); void Read(); void Print(); ~Sheep(); private: int age; int weight;};Sheep::Sheep() { age = 0; weight = 0;}void Sheep::Read() { cin >> age; cin >> weight;}void Sheep::Print() { cout << "Sheep's age: " << age << endl; cout << "Sheep's weight: " << weight << endl;}Sheep::~Sheep() { // Covered in section on Destructors. cout << "Sheep with age " << age << " and weight " << weight << " is deallocated." << endl;}
int main() { Sheep* mySheep = nullptr; int count; int i;
// Your Solution goes here // delete[] mySheep; return 0;}
Read an integer as the number of Sheep objects. Assign mySheep with an array of that many Sheep objects. For each object, call object's Read() followed by the object's Print(). Ex: If the input is 1 8 99, then the output is: Sheep's age: 8 Sheep's weight: 99 Sheep with age 8 and weight 99 is deallocated. 1 #include <iostream> 2 using namespace std; 3 4 class Sheep { 5 public: 6 7 8 9 10 11 12 Sheep(); void Read(); void Print(); ~Sheep(); private: int age; int weight; 13}; 14 Sheep::Sheep() { 15 age = 0; 16 weight = 0; 17 } 18 void Sheep:: Read() {