Define a class named Treadmill that contains the appropriate data members and me
ID: 3590054 • Letter: D
Question
Define a class named Treadmill that contains the appropriate data members and methods. The class should have data members (what should they each be?) for:
Speed (0 - 12 MPH)
Incline (0 - 40%)
Time Exercised (upto one hour based on minutes and seconds)
Calories Burned
Use global constants to set the mins and maxes. The class should have mutator and accessor methods for EVERY data member listed above. The mutator method should ensure that the data members are "legally" set. In addition, these methods must be provided:
a mutator method to reset all data members to 0
a mutator method to calculate calories burned (assume a burn rate of 4 calories per minute or 4/60 per second)
an accessor method to print all data members
multiple constructors:
Two parameters to set speed and incline
four parameters to set all 4
default initializer sets the speed to 3 and Incline to 0;
You must also write an application that uses this object (i.e, a main program that instantiates three treadmill objects and thoroughly tests the methods.)
In order to test your class, you will create objects, show that every set and get works, the calculations work, and the print works The application must:
Define 3 treadmills in order to test all constructorsprint the values for each of the three treadmills to "prove" the instiantiation works
Test all set Methods by setting the datamamber then printing the data member useng the accessor method
Calculate the calories burned on all 3 treadsmills
Invoke the print method for all three teadmills at the end
Output should include:
Speed
Incline
Heart Rate
Amount of time exercised
Calories Burned
For example:
Treadmill with maximum speed of 7.5 mph and maximum incline of 12.5
Client is exercising at 3.6 mph, with an incline of 5, and heart rate of 126 bpm
Client has exercised for 25 minutes and burned 100 calories
Explanation / Answer
I tried my best . I have 3 objects for all 3 constructors but checked the set,get methods , caloriesburned() method , setallzero() method for first object only. I ensure that this programs works for correctly up to the mark.
Even if you still have any problem, rply us.
thank you for ur question.
My program:(in c++ , as no preferred programming language is given)
#include<iostream>
#include<stdio.h>
using namespace std;
struct timems
{
int min;
int seconds;
};
class treadmill
{
float speed;
float incline;
timems t;
float calories;
public:
treadmill()
{
speed=3;
incline=0;
}
treadmill(float s, float i)
{
speed=s;
incline=i;
}
treadmill(float s, float i,float c, timems t1)
{
speed=s;
incline=i;
calories=c;
t.min=t1.min;
t.seconds=t1.seconds;
}
void mut_speed(float s)
{
if(s!=0)
this->speed=s;
}
void mut_incline(float s)
{
if(s!=0)
this->incline=s;
}
void mut_time(timems t1)
{
if(t1.min!=0&&t1.seconds!=0)
{
this->t.min=t1.min;
this->t.seconds=t1.seconds;
}
}
void mut_calories(float s)
{
if(s!=0)
calories=s;
}
float get_speed()
{
return this->speed;
}
float get_incline()
{
return this->incline;
}
timems get_time()
{
return this->t;
}
float get_calories()
{
return this->calories;
}
void setallzero()
{
this->speed=0;
this->calories=0;
this->incline=0;
this->t.min=0;
this->t.seconds=0;
}
float caloriesburned()
{ float def=4.0/60.0;
//cout<<"def="<<def;
int sec=(this->t.min)*60 + this->t.seconds;
float a=(float)(sec*(def));
//cout<<"flaot a=="<<a;
return a;
}
void display()
{
cout<<"speed:"<<this->speed<<" ";
cout<<"incline:"<<this->incline<<" ";
cout<<"calories:"<<this->calories<<" ";
cout<<"time->minutes:"<<this->t.min<<" ";
cout<<"time->seconds:"<<this->t.seconds<<" ";
}
};
int main()
{
treadmill t1; // for default constructor
treadmill t2(3.0,12); // for constructor with 2 parameters
timems ob;
ob.min=23;
ob.seconds=40;
treadmill t3( 3.2,12,100,ob); //for constructor with 4 parameters
// test for display method for t1,t2,t3 objects to prove instantiation works
t1.display();
t2.display();
t3.display();
// test for set methods for t1 object by calling all mutator functions
ob.min=12;
ob.seconds=34;
t1.mut_speed(4);
t1.mut_calories(100);
t1.mut_incline(22);
t1.mut_time(ob);
// test for get methods for object t1 by callling all accessor function
cout<<"speed for t1 is "<<t1.get_speed();
cout<<" ";
cout<<"incline for t1 is "<<t1.get_incline();cout<<" ";
cout<<"heart rate for t1 is 120 beats per minute";cout<<" ";
cout<<"calories for t1 is "<<t1.get_calories();cout<<" ";
timems ob1=t1.get_time();
cout<<"exercised time for t1 is "<<ob1.min<<" minutes "<<ob1.seconds<<" seconds"<<" ";
cout<<"total calories burned is="<<t1.caloriesburned()<<" ";
// calling display function for object t1 after usinf set and get methods
t1.display();
// test for setallzero method for object t1
t1.setallzero();
// again printing to check if setallzero worked??
t1.display();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.