Answer to Question #269308 in C++ for Bonakele

Question #269308

Write the class definition for a Car class. Provide the following data members:



 A C-string called make of size 20 to store the car manufactures name, e.g. Ford, Toyota,



….;



 In integer called year to hold the year of first registration of the vehicle;



 A floating point called km to contain the number of kilometers traveled for the trip;



 A floating point called liter to contain the liters used to cover the distance;



 A floating point called consumption is the calculated value of liter per km.



 Class-wide floating point called expense, for the cost per kilometer, which should be



initialized to R7.55.



The class also contains the following methods:



 A default constructor that will set the data members to appropriate default values if



nothing is sent to it, and set them to the values sent as parameters if parameters are



received.




1
Expert's answer
2021-11-21T17:34:01-0500
#include<iostream>
#include<string>
using namespace std;




class Car{
	//A C-string called make of size 20 to store the car manufactures name, e.g. Ford, Toyota,
	char manufacturesName[20];
	//In integer called year to hold the year of first registration of the vehicle;
	int year;
	//A floating point called km to contain the number of kilometers traveled for the trip;
	float km;
	// floating point called liter to contain the liters used to cover the distance;
	float liter;
	// A floating point called consumption is the calculated value of liter per km.
	float consumption;
	// Class-wide floating point called expense, for the cost per kilometer, which should be initialized to R7.55.
	float expense;
	//The class also contains the following methods:
	//A default constructor that will set the data members to appropriate default values if
	//nothing is sent to it, and set them to the values sent as parameters if parameters are received.
	Car(char manufacturesName[20],int year,float km,float liter,float consumption){
		strcpy(this->manufacturesName,manufacturesName);
		this->year=year;
		this->km=km;
		this->liter=liter;
		this->consumption=consumption;
		this->expense=7.55;
	}
	
};






int main(){
	
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS