Answered step by step
Verified Expert Solution
Question
1 Approved Answer
its as screenshot read > solve Objectives After completing this lab, you will be able to: Use Classes Define default and parameterized constructors and use
its as screenshot read > solve
Objectives After completing this lab, you will be able to: Use Classes Define default and parameterized constructors and use them Define and use projects Mark Out of Lab En. Program Code (correctness, style, modularity, etc Comments, indentation Naming of identifiers Output correctness Output format 10 TOTAL: age: Define the class Car which has the following private members - brand: c.g. Toyota, Honda etc - model: e.g. 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) petrolPrice a decimal number giving the price of one liter of petrol in dirham (20 to 35) 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 ser 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 ger() function which returns the values of all the data members. . a function averageKms Per Dave) which returns the average number of kilometers a car has traveled per day (kilometers/age) a function averagelisPer Day which returns the daily average netrol consum consumption .age: Define the class Car which has the following private members: brand: c.g. Toyota, Honda etc. . model: c.g. 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) petrolPrice a decimal number giving the price of one liter of petrol in dirham (20 to 35) 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 parameterised constructor a ser() 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 gero function which returns the values of all the data members. a function averageKms Per Day which returns the average number of kilometers a car has traveled per day (kilometers/ age) . a function average LesPerDay) 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 (carh), 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 maino > string objectBrand, objectModel: int objectConsumption, objectKilometers, objectAge: double objectPetrolPrice: Car myCar; Car NiceCar("Honda", "Civic", 11, 453, 123.21.25); cout> objectBrand: cout> objectModel: cout> objectConsumption: cout> objectKilometers cout> objectAge: cout> object microbial Prodhiwald tinn class implementation in a carlmp.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 objectConsumption, objectKilometers, objectAge: double objectPetrolPrice: Car myCar: Car NiceCar("Honda", "Civie", 11,453, 123, 21.25); cout> objectBrand: cout > objectModel: cout> objectConsumption: cout> objectKilometers: cout> objectAge: cout> objectPetrolPrice: myCar set(objectBrand, object Model objectConsumption, objectKilometers, objectAge, objectPetrolPrice): myCar.print(): NiceCar.print(); 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 3/3 Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started