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;

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Modularization Techniques
Section: Chapter Questions
Problem 2GZ
icon
Related questions
Question
100%

C++ CODE HELP NEEDED

NEED  MISSING CODE THAT WILL 

  1. Read an integer as the number of Goat objects.
  2. 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;
}

Jump to level 1
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.
5 24 25 26 27 28 29123435357 38 39 40
23
25}
26 Goat::~Goat() { // Covered in section on Destructors.
cout << "Goat with age " << age << " and weight " << weight << " is deallocated." << endl;
28}
cout << "Goat's age: << age << endl;
cout << "Goat's weight: "<< weight << endl;
30 int main() {
36
40
Goat myGoats = nullptr;
int count;
int i;
/* Your code goes here */
delete[] myGoats;
return 0;
Transcribed Image Text:Jump to level 1 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. 5 24 25 26 27 28 29123435357 38 39 40 23 25} 26 Goat::~Goat() { // Covered in section on Destructors. cout << "Goat with age " << age << " and weight " << weight << " is deallocated." << endl; 28} cout << "Goat's age: << age << endl; cout << "Goat's weight: "<< weight << endl; 30 int main() { 36 40 Goat myGoats = nullptr; int count; int i; /* Your code goes here */ delete[] myGoats; return 0;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT