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

#include using namespace std; const int MAXNUMCARS100; class Car private: string

ID: 3590314 • Letter: #

Question

#include using namespace std; const int MAXNUMCARS100; class Car private: string m_make; string m_model; double m_earnedOnCar 1 all the money the car has earned public: hi class Dealership Car(string make, string model); double getAmountEarned0nCar) const; //part a private: Cars m cars[MAXNUMCARS] int m-numCars; // # of cars void swapCars(int pos1, int pos2);use in c public: double getTotalSales) const; // part b void updateInventory (double limit); // partc void addCar (Car*); IIuse in e //Rest of class not shoown hi

Explanation / Answer

a). Car member function definition for getting Amount Earned On Car:

double getAmountEarnedOnCar() const {

return m_earnedOnCar;

/* Return the amount earned on the car which is a private variable hence can be accessed by this public getter method. This concept of accessing private member variables through member methods is called Encapsulation. */

}

b). Member function definition for getting total sales:

double getTotalSales() const {

int i=0;

double totalAmount=0.0;

for(i=0; i<MAXNUMCARS; i++) {

Car car=*(m_cars[i]) //get the car at 'i'th index

totalAmount+=car.getAmountEarnedOnCar(); //add amount earned on each car to total amount

}

return totalAmount;

}

c). Dealership member function definition for updateInventory :

void updateInventory( double limit ) {

// remove cars whose earnings are less than limit

int i;

for( i=0; i < MAXNUMCARS; i++) {

Car car=*(m_cars[i]);

double amountEarnedOnCar = car.getAmountEarnedOnCar();

if ( amountEarnedOnCar < limit ) {

// exclude this car using swapCars : definition of swapCars needed, in order to understand how this is done.

swapCars( i, -1); /* using -1 as dummy position here, to exclude the car from the lst, please update according to swapCars definition */

}

}

}