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

Help with data structures program Throttle Class Overload Create the \"throttle\

ID: 667359 • Letter: H

Question

Help with data structures program

Throttle Class Overload

Create the "throttle" class as shown in the text with

            a. data members of "position" and "Top_Position" (maximum throttle position)


            b. Default "constructor" with two arguments The first sets the "Top_position" and the second sets the current "position". The third is a copy constructor

Ex declaration:

throttle car                      - set Top_Position 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

throttle mythrottle(truck) -sets/initilizes obj mythrottle to the same values of obj truck


            c. Add a member function that will "compare" two throttles using the '==' symbol.
ex if ( car = truck ) ... Implement the '==' member function inside the class throttle.
            i. To test the above, write code to call the '==' function explicitly ie operator==.
            ii. Also code to call the above function using the nice syntax '=='.


            d. Add the member function '!=' to throttle and implement this function outside the class.
            i. To test the above, write code to call the '!=' function explicitly ie operator!=.
            ii. Also code to call the above function using the nice syntax '!='.

e.Write an overloaded output function (<<) to print out an object throttle showing the Top_position and the current position.


        f. Write a main program that will test the above implementation of throttle that will convince me your throttle class is correct. (ie all methods work.)

Explanation / Answer

http://ideone.com/HkS1VF for output

#include <iostream>
using namespace std;

class throttle{
   public:
       int Top_Position;
       int current_Position;
       throttle(){
           Top_Position = 6;
           current_Position = 0;
       }
       throttle(int n){
           Top_Position = n;
           current_Position = 0;
       }
       throttle(int n,int c){
           Top_Position = n;
           current_Position = c;
       }
       throttle mythrottle(throttle truck){
           throttle temp = truck;
           return temp;
       }
       bool compare(throttle t1, throttle t2){
           if (t1.Top_Position == t2.Top_Position && t1.current_Position == t2.current_Position) return true;
           return false;
       }
       bool Not_Equal(throttle t1, throttle t2);
       void output(){
           cout << Top_Position << " " << current_Position << endl;
       }
};

bool throttle::Not_Equal(throttle t1, throttle t2){
   if (t1.Top_Position != t2.Top_Position || t1.current_Position != t2.current_Position) return true;
   return false;
}

int main() {
   throttle car();
   throttle truck(30);   
   throttle shuttle(20,6);
   throttle t = truck.mythrottle(truck);
   t.output();
   return 0;
}

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