C++ CODE HELP NEEDED NEED MISSING CODE THAT WILL Read an integer as the number of Goat objects. Assign myGoats with an array of that many Goat objects. For each object, call object's Read() followed by the object's Print(). Ex: If the input is 2 5 87 7 71, then the output is: Goat's age: 5 Goat's weight: 87 Goat's age: 7 Goat's weight: 71 Goat with age 7 and weight 71 is deallocated. Goat with age 5 and weight 87 is deallocated. #include using namespace std; class Goat { public: Goat(); void Read(); void Print(); ~Goat(); private: int age; int weight; }; Goat::Goat() { age = 0; weight = 0; } void Goat::Read() { cin >> age; cin >> weight; } void Goat::Print() { cout << "Goat's age: " << age << endl; cout << "Goat's weight: " << weight << endl; } Goat::~Goat() { // Covered in section on Destructors. cout << "Goat with age " << age << " and weight " << weight << " is deallocated." << endl; } int main() { Goat* myGoats = nullptr; int count; int i; /* Your code goes here */ delete[] myGoats; return 0;
C++ CODE HELP NEEDED
NEED MISSING CODE THAT WILL
- Read an integer as the number of Goat objects.
- Assign myGoats with an array of that many Goat objects. For each object, call object's Read() followed by the object's Print().
Ex: If the input is 2 5 87 7 71, then the output is:
Goat's age: 5
Goat's weight: 87 Goat's age: 7 Goat's weight: 71 Goat with age 7 and weight 71 is deallocated. Goat with age 5 and weight 87 is deallocated.
#include <iostream>
using namespace std;
class Goat {
public:
Goat();
void Read();
void Print();
~Goat();
private:
int age;
int weight;
};
Goat::Goat() {
age = 0;
weight = 0;
}
void Goat::Read() {
cin >> age;
cin >> weight;
}
void Goat::Print() {
cout << "Goat's age: " << age << endl;
cout << "Goat's weight: " << weight << endl;
}
Goat::~Goat() { // Covered in section on Destructors.
cout << "Goat with age " << age << " and weight " << weight << " is deallocated." << endl;
}
int main() {
Goat* myGoats = nullptr;
int count;
int i;
/* Your code goes here */
delete[] myGoats;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images