Page 1 of 1

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

Posted: Sun Jul 03, 2022 11:59 am
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;}