For input 6 52, the age is 6 and the weight is 52. The Dog constructor is called with the age and the weight as arguments. The Dog constructor sets the age to 6 and the weight to 52. The address of the new Dog object is assigned to myDog. The object's IncreaseAge And Weight() is called to change the object's age and weight. Finally, the object's Print() is called. Thus, the output is: Dog's age and weight are increased. Dog's age: 60 Dog's weight: 520 Not all tests passed. X 1: Compare output A Output differs. See highlights below. Special character legend Input Your output Expected output 6 52 Dog's age and weight are increased. Dog's age: 60 Dog's weight: 520 Dog's age: 60 Dog's weight: 5204 Dog's age and weight are increased. Dog's age: 60 Dog's weight: 520
PLEASE HELP FIX CODE THAT GIVES OUT WRONG OUTPUT
(I've attached image showing the issue of output)
Here is the code I used:
#include <iostream>
using namespace std;
class Dog {
public:
Dog(int ageValue, int weightValue);
void IncreaseAgeAndWeight();
void Print();
private:
int age;
int weight;
};
Dog::Dog(int ageValue, int weightValue) {
age = ageValue;
weight = weightValue;
}
void Dog::IncreaseAgeAndWeight() {
age = age * 10;
weight = weight * 10;
cout << "Dog's age and weight are increased." << endl;
}
void Dog::Print() {
cout << "Dog's age: " << age << endl;
cout << "Dog's weight: " << weight << endl;
}
int main() {
// declaring variables for age and weight
int age;
int weight;
// reading age from user
cin >> age;
// reading weight from user
cin >> weight;
// creating object of class Dog
Dog * myDog = new Dog(age, weight);
// making function call to IncreaseAge
myDog -> IncreaseAgeAndWeight();
// making function call to Print
myDog -> Print();
myDog->Print();
return 0;
}


Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images









