Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Vehicle {
- protected:
- string vehicle_type;
- Vehicle *next;
- public:
- Vehicle(): vehicle_type("N/A"), next(NULL) {}
- ~Vehicle() {}
- virtual void read() {
- cout << "Enter type: ";
- cin >> vehicle_type;
- }
- virtual bool isLarge() = 0;
- void setNext(Vehicle *P) {
- next = P;
- }
- Vehicle * getNext() {
- return next;
- }
- string getType() {
- return vehicle_type;
- }
- };
- class PassengerVehicle: public Vehicle {
- private:
- int passengerCapacity;
- public:
- PassengerVehicle(): passengerCapacity(0) {}
- ~PassengerVehicle() {}
- void read() {
- Vehicle :: read();
- cout << "Enter Passenger Capacity: " ;
- cin >> passengerCapacity;
- }
- bool isLarge() {
- return (passengerCapacity >= 40) ? true : false;
- }
- };
- class CargoVehicle: public Vehicle {
- private:
- float loadCapacity;
- public:
- CargoVehicle(): loadCapacity(0.0) {}
- ~CargoVehicle() {}
- void read() {
- Vehicle :: read();
- cout << "Enter Load Capacity: " ;
- cin >> loadCapacity;
- }
- bool isLarge() {
- return (loadCapacity >= 5.0) ? true : false;
- }
- };
- int main() {
- Vehicle *Head, *Current, *Last;
- unsigned short choice;
- bool first = true;
- cout << "Welcome!" << endl;
- while(true) {
- cout << "Press 1 for creating a Passenger, 2 for Cargo, 0 to stop" << endl;
- cin >> choice;
- if(choice == 1) {
- if(first) {
- first = false;
- Head = new PassengerVehicle();
- Current = Last = Head;
- }
- else {
- Current = new PassengerVehicle();
- Last -> setNext(Current);
- Last = Current;
- }
- Current -> read();
- }
- else if(choice == 2) {
- if(first) {
- first = false;
- Head = new CargoVehicle();
- Current = Last = Head;
- }
- else {
- Current = new CargoVehicle();
- Last -> setNext(Current);
- Last = Current;
- }
- Current -> read();
- }
- else if(choice == 0) break;
- }
- cout << "Printing Results ..." << endl;
- for(Current = Head; Current != NULL; Current = Current -> getNext()) {
- if(Current -> isLarge())
- cout << Current -> getType() << " is " << "LARGE." << endl;
- else
- cout << Current -> getType() << " is " << "NOT LARGE." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement