Read an integer as the number of Sheep objects. Assign mySheep with an array of that many Sheep objects. For each object

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
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

Post by answerhappygod »

Read An Integer As The Number Of Sheep Objects Assign Mysheep With An Array Of That Many Sheep Objects For Each Object 1
Read An Integer As The Number Of Sheep Objects Assign Mysheep With An Array Of That Many Sheep Objects For Each Object 1 (53.11 KiB) Viewed 26 times
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().
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() {
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply