C++ programming problem The Class Workout represents the way some folks keep fit
ID: 640669 • Letter: C
Question
C++ programming problem
The Class Workout represents the way some folks keep fit. Consider the following diagrams below.
This instance was created by saying:
Workout weightsWorkout;
// 30 minute workout with a heart-rate of 165
This instance was created by saying:
Workout crewWorkout( 60, 155 );
// 60 minute workout with a heart-rate of 155
Each Workout is defined by its length and the heart-rate it achieved. For the constructors shown above, here is the class definition (.h)
Workout( );
Workout( int minutes, int heartRate );
int getLength( ) const;
int getHeartRate( ) const;
Workout ( );
Workout( int minutes, int heartRate );
int getLength( ) const;
int getHeartRate( ) const;
int my_Length; // this workout's length
int my_HeartRate; // this workout's acheived heart-rate
Based on the information shown here, a possible implementation (.cpp) for Workout is shown below.
Workout::Workout ()
{
my_HeartRate = 165;
my_Length = 30;
}
Workout::Workout( int len, int rate )
{
my_HeartRate = rate;
my_Length = len;
}
int Workout::getLength() const
{
return my_Length;
}
int Workout::getHeartRate() const
{
return my_HeartRate;
}
Based on this implementation of Workout, define and implement the class BikeWorkout. A
BikeWorkout is a special kind of Workout that uses a bicycle and tracks a particular maximum
speed. The relationship between Workout and BikeWorkout is shown in the class diagram below.
// By default, a bike workout that uses machines, lasts 1 hour and get a heart rate of 175
BikeWorkout b;
// A bike workout that lasts for 30 minutes, achieving a maximum speed of 40 miles per hour
// and a heart rate of 185
BikeWorkout fastRide( 40, 30, 185 );
TO RECEIVE FULL CREDIT, YOUR BIKEWORKOUT CONSTRUCTOR MUST CALL THE PARENT-CLASS WORKOUT CONSTRUCTOR.
Workout lasts 30 minutes with a heart-rate of 165
This instance was created by saying:
Workout weightsWorkout;
// 30 minute workout with a heart-rate of 165
Workout lasts 60 minutes with a heart-rate of 155
This instance was created by saying:
Workout crewWorkout( 60, 155 );
// 60 minute workout with a heart-rate of 155
Explanation / Answer
#include<iostream>
using namespace std;
class Workout {
public:
Workout ( );
Workout( int minutes, int heartRate );
int getLength( ) const;
int getHeartRate( ) const;
private:
int my_Length; // this workout's length
int my_HeartRate; // this workout's acheived heart-rate
};
Workout::Workout ()
{
my_HeartRate = 165;
my_Length = 30;
}
Workout::Workout( int len, int rate )
{
my_HeartRate = rate;
my_Length = len;
}
int Workout::getLength() const
{
return my_Length;
}
int Workout::getHeartRate() const
{
return my_HeartRate;
}
class BikeWorkout: public Workout{
private:
int speed;
public:
BikeWorkout();
BikeWorkout(int speed, int len, int rate );
};
BikeWorkout::BikeWorkout():Workout(60,175){}
BikeWorkout::BikeWorkout(int speed, int len, int rate ) :Workout(len, rate){
this->speed = speed;
}
int main(){
BikeWorkout b;
// A bike workout that lasts for 30 minutes, achieving a maximum speed of 40 miles per hour
// and a heart rate of 185
BikeWorkout fastRide( 40, 30, 185 );
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.