Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a c++ program that uses the \'Throttle\' class with the addition of a ‘Top

ID: 667126 • Letter: W

Question

Write a c++ program that uses the 'Throttle' class with the addition of a ‘Top Position” defaulted to a value of 6. The data members will consist of 'position' and 'top_position'. The 'top_position' will be the maximum value that the throttle position can reach. You will also use a default constructor that contains two arguments. The first sets the 'top_position' and the second sets the current 'position'.

The following is an example of the declaration:

throttle car                  - set top_positon to 6 and current to 0

throttle truck(30)          - sets top_position to 30 and current position to 0

throttle shuttle(20,6)    - sets top_position to 20 and current position to 6

Explanation / Answer

throttle.h

                                                        /**this is throttle.h text
* define some method
*/

#ifndef MAIN_THROTTLE
#define MAIN_THROTTLE
namespace main_throttle_2A{
class throttle{
public:
    //construct
    throttle();
    throttle(int size);
    //modified
    void shut_off(){position = 0;}
    void shift(int amount);
    //constant
    double flow() const {position/double(top_position);}
    bool is_on() const {return (position > 0);}
    int current_position();
    int current_top_position();
private:
    int position;
    int top_position;
};
}
#endif

throttlle.cpp

                                              //implement throttle.h

#include "throttle.h"
//#include <cassert>
main_throttle_2A {

//construction
throttle::throttle()
{
position = 0;
top_position = 1;
}

throttle::throttle(int size)
{
assert(size > 0);
position = 0;
top_position = size;
}
void throttle::shift(int amount)
{
position += amount;
if(position < 0){
   position = 0;
}
if(position > top_position){
   position = top_position;
}
}
int throttle::current_position()
{
return position;
}
int throttle::current_top_position()
{
return top_position;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote