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 {
public:
void set(int rent_no, int charge, float duration) {
car_rent_no_ = rent_no;
charge_pre_hour_ = charge;
park_duration_ = duration;
}
void show() {
std::cout << "Rent No: " << car_rent_no_ << '\n'
<< "Charge per hour: " << charge_pre_hour_ << '\n'
<< "Duration: " << park_duration_ << '\n';
}
private:
int car_rent_no_;
int charge_pre_hour_;
float park_duration_;
};
int main() {
CarPark park;
park.set(1, 10, 180.f);
park.show();
return 0;
}
Comments
Leave a comment