Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ for beginners Define the class Car which has the following private members: brand: e.g, Toyota, Honda etc. . model: e.g. Camry, Civic, etc.

image text in transcribed
in c++ for beginners image text in transcribed
Define the class Car which has the following private members: brand: e.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 PerDay) which returns the average number of kilometers a car has traveled per day (kilometers / age) a function averageLisPerDay() which returns the daily average petrol consumption of a car in dirham (kilometers - consumption petrolPrice/age) a function prin) 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.h), the 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, objectModel; int objectConsumption, objectKilometers, objectAge: double objectPetrol Price: Car myCar: Car NiceCar("Honda", "Civie". 11.453, 123,21.25); cout > objectBrand: cout> objectModel: cout> objectConsumption: cout > objectKilometers cout> objectAge; cout> objectPetrol Price: myCar set(objcm consumption Create a project containing the class interface in a header file (car.h), the class implementation in a carlmp.cpp file and the main program in a car.epp file. The following driver produces the given sample of input/output: int main() 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> objectPetrolPrice; myCar.set(objectBrand, objectModel, objectConsumption, objectKilometers, objectAge, objectPetrolPrice); myCar.printo: 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

Describe womens potential anti-rape defenses.

Answered: 1 week ago

Question

=+Have you acquired the ability to read,

Answered: 1 week ago