Question: C++ using xcode Define the class Car which has the following private members: brand: e.g. Toyota, Honda etc. model: eg. Camry, Civic, etc. consumption: giving

C++

using xcode

C++ using xcode Define the class Car which has the following privatemembers: brand: e.g. Toyota, Honda etc. model: eg. Camry, Civic, etc. consumption:

Define the class Car which has the following private members: brand: e.g. Toyota, Honda etc. model: eg. Camry, Civic, etc. consumption: giving the number of liters of petrol the car consumes per kilometer (2 to 18) kilometers: giving the number of kilometers the car has run since its production (10 to 1000) petrol Price: a decimal number giving the price of one liter of petrol in dirham (20 to 35) age: giving the age of the car in days since its production (100 to 250) and the following public members: a default constructor (without parameters) a parameterized constructor a set() function which sets all the data member values. This function should check the validity of the last 4 data members, setting the value to 0 if not satisfied. a get function which returns the values of all the data members. a function averageKmsPex Daxo which returns the average number of kilometers a car has traveled per day (kilometers / age) a function averageltsPer Daxo which returns the daily average petrol consumption of a car in dirham (kilometers * consumption * petrolPrice/age) a function print which prints a car object details in the given format. . . Implement the member functions of the class Car enforcing the least privileged principle. Create a project containing the class interface in a header file (car.b), the class implementation in a carImp.cpp file and the main program in a car.cpp file. The following driver produces the given sample of input/output: int main() { string objectBrand object Model: int obiectConsumption obiectKilometers. obiectAge: double object PetrolPrice: Car mycar Car NiceCart"Honda", "Civic", 11, 453, 123, 21.25); cout > objectBrand; cout > objest Model: cout > objectConsumption: cout > objectKilometers: cout > objectAge: cout > objectPetrolPrice: myCar set(objectBrand, objest Models objectConsumption obiectKilometers, objectAge, obiectPetrol Price); myCar.printo; NiceCac printo; return 0; } Sample input / output: Enter the brand of the car: Toyota Enter the model of the car: Corola Enter the petrol consumption: between 3 and 18: 13 Enter the kilometers: between 10 and 1000: 340 Enter the age: between 100 and 250: 140 Enter the petrol price: between 20 and 35: 22 Brand is Toyota, Model is Corola, Consumption is 13 Kilometers is 340, Age is 140, Petrol price is 22 Average kilometers per day is: 2.42857 kilometers Average petrol consumption per day is: 694.571 dirhams Brand is Honda, Model is Civic, Consumption is 11 Kilometers is 453, Age is 123, Petrol price is 21.25 Average kilometers per day is: 3.68293 kilometers Average petrol consumption per day is: 860.884 dirhams Define the class Car which has the following private members: brand: e.g. Toyota, Honda etc. model: eg. Camry, Civic, etc. consumption: giving the number of liters of petrol the car consumes per kilometer (2 to 18) kilometers: giving the number of kilometers the car has run since its production (10 to 1000) petrol Price: a decimal number giving the price of one liter of petrol in dirham (20 to 35) age: giving the age of the car in days since its production (100 to 250) and the following public members: a default constructor (without parameters) a parameterized constructor a set() function which sets all the data member values. This function should check the validity of the last 4 data members, setting the value to 0 if not satisfied. a get function which returns the values of all the data members. a function averageKmsPex Daxo which returns the average number of kilometers a car has traveled per day (kilometers / age) a function averageltsPer Daxo which returns the daily average petrol consumption of a car in dirham (kilometers * consumption * petrolPrice/age) a function print which prints a car object details in the given format. . . Implement the member functions of the class Car enforcing the least privileged principle. Create a project containing the class interface in a header file (car.b), the class implementation in a carImp.cpp file and the main program in a car.cpp file. The following driver produces the given sample of input/output: int main() { string objectBrand object Model: int obiectConsumption obiectKilometers. obiectAge: double object PetrolPrice: Car mycar Car NiceCart"Honda", "Civic", 11, 453, 123, 21.25); cout > objectBrand; cout > objest Model: cout > objectConsumption: cout > objectKilometers: cout > objectAge: cout > objectPetrolPrice: myCar set(objectBrand, objest Models objectConsumption obiectKilometers, objectAge, obiectPetrol Price); myCar.printo; NiceCac printo; return 0; } Sample input / output: Enter the brand of the car: Toyota Enter the model of the car: Corola Enter the petrol consumption: between 3 and 18: 13 Enter the kilometers: between 10 and 1000: 340 Enter the age: between 100 and 250: 140 Enter the petrol price: between 20 and 35: 22 Brand is Toyota, Model is Corola, Consumption is 13 Kilometers is 340, Age is 140, Petrol price is 22 Average kilometers per day is: 2.42857 kilometers Average petrol consumption per day is: 694.571 dirhams Brand is Honda, Model is Civic, Consumption is 11 Kilometers is 453, Age is 123, Petrol price is 21.25 Average kilometers per day is: 3.68293 kilometers Average petrol consumption per day is: 860.884 dirhams

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!