Read two doubles as the age and the weight of a Chicken object. Declare and assign pointer myChicken with a new Chicken

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 two doubles as the age and the weight of a Chicken object. Declare and assign pointer myChicken with a new Chicken

Post by answerhappygod »

Read two doubles as the age and the weight of a Chicken object.Declare and assign pointer myChicken with a new Chicken objectusing the age and the weight as arguments in that order. Then callmyChicken's IncreaseAgeAndWeight() member function.
Ex: If the input is 3.5 4.5, then the output is:
Chicken's age and weight are increased. Chicken's age: 24.5Chicken's weight: 31.5
#include <iostream>#include <iomanip>using namespace std;
class Chicken { public: Chicken(double ageValue, doubleweightValue); void IncreaseAgeAndWeight(); void Print(); private: double age; double weight;};Chicken::Chicken(double ageValue, double weightValue) { age = ageValue; weight = weightValue;}void Chicken::IncreaseAgeAndWeight() { age = age * 7.0; weight = weight * 7.0; cout << "Chicken's age and weight areincreased." << endl;}void Chicken::Print() { cout << "Chicken's age: " << fixed<< setprecision(1) << age << endl; cout << "Chicken's weight: " << fixed<< setprecision(1) << weight << endl;}
int main() { /* Additional variable declarations go here */
/* Your code goes here */
myChicken->Print(); return 0;}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply