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

Define a class called Odometer that will be used to track fuel and mileage for a

ID: 3844033 • Letter: D

Question

Define a class called Odometer that will be used to track fuel and mileage for an automobile. The class should have instance variables to track the miles driven and the fuel efficiency of the vehicle in miles per gallon. Include a mutator method to reset the odometer to zero miles, a mutator method to set the fuel efficiency, a mutator method that accepts miles driven for a trip and adds it to the odometer's total, and an accessor method hat returns the number of gallons of gasoline that the vehicle has consumed since the odometer was last reset.

Explanation / Answer

class Odometer{
   private:
       int miles;
       float fuel_eff;
   public:
       void reset()
       {
           miles = 0;
          
       }
      
       void set_eff()  
       {
           fuel_eff = 0.7;
       }
      
       void cal_miles(int m)   //m is miles accepted
       {
           miles += m;
       }
      
       float cal_gasoline()
       {
           float gas = 0;
           if(miles!=0)   //checking is miles are reset
               gas = miles/fuel_eff;   //calculating gas consumed
           return gas;
       }
      
};

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