Skip to content

Instantly share code, notes, and snippets.

@johndel
Last active June 28, 2023 09:38
Show Gist options
  • Save johndel/765cfc69fdc56eaaca8a9b46135381ee to your computer and use it in GitHub Desktop.
Save johndel/765cfc69fdc56eaaca8a9b46135381ee to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstring>
class Vehicle {
protected:
char number[7];
char type[10];
float daycharge;
public:
Vehicle() {
strcpy(number, "000000");
strcpy(type, "unknown");
daycharge = 0.0;
}
void read() {
std::cout << "Enter vehicle number: ";
std::cin >> number;
std::cout << "Enter vehicle type: ";
std::cin >> type;
std::cout << "Enter daily charge: ";
std::cin >> daycharge;
}
void display() {
std::cout << "Vehicle number: " << number << std::endl;
std::cout << "Vehicle type: " << type << std::endl;
std::cout << "Daily charge: " << daycharge << std::endl;
}
};
class Hire : public Vehicle {
private:
int id;
char name[20];
int days;
public:
Hire() : Vehicle() {
id = 0;
strcpy(name, "unknown");
days = 0;
}
void read() {
Vehicle::read();
std::cout << "Enter hire ID: ";
std::cin >> id;
std::cout << "Enter name: ";
std::cin >> name;
std::cout << "Enter number of days: ";
std::cin >> days;
}
void display() {
Vehicle::display();
std::cout << "Hire ID: " << id << std::endl;
std::cout << "Name: " << name << std::endl;
std::cout << "Number of days: " << days << std::endl;
}
float calculateCharge() {
return daycharge * days;
}
};
int main() {
Hire hire;
hire.read();
hire.display();
std::cout << "Total charge: " << hire.calculateCharge() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment