Create a class called CarPark that has the members CarRegnno(int), ChargePerHour(int) and
ParkingDuration(float). Set the data and show the charges and parked hours of a car based on
CarRegnNo. Make two member functions for setting and showing the data. Member function should
be called from other functions.
#include <iostream>
using namespace std;
class CarPark
{
private:
//Create a class called CarPark that has the members CarRegnno(int), ChargePerHour(int) and ParkingDuration(float).
int CarRegnno;
int ChargePerHour;
float ParkingDuration;
public:
//Set the data and show the charges and parked hours of a car based on CarRegnNo.
//Make two member functions for setting and showing the data.
void setData(){
cout<<"Ente car regn. no: ";
cin>>CarRegnno;
cout<<"Ente car charge per hour: ";
cin>>ChargePerHour;
cout<<"Ente parking duration (hours): ";
cin>>ParkingDuration;
}
void sho2Data(){
cout<<"Car regn. no: "<<CarRegnno<<"\n";
cout<<"Car charge per hour: "<<ChargePerHour<<"\n";
cout<<"Parking duration (hours): "<<ParkingDuration<<"\n";
cout<<"The charges: "<<calculateCharges()<<"\n";
}
//Member function should be called from other functions.
float calculateCharges(){
return ChargePerHour*ParkingDuration;
}
};
int main ()
{
CarPark carPark;
carPark.setData();
carPark.sho2Data();
system("pause");
return 0;
}
Comments
Sir, Why it is not answered
Leave a comment