Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <string>
- #include <iomanip>
- class Vehicle {
- std::string manufacturer;
- std::string model;
- int horsePower;
- public:
- Vehicle(std::string manufacturer, std::string model, int horsePower) : manufacturer(manufacturer), model(model), horsePower(horsePower) {
- }
- virtual void printHeader(std::ostream& out) const {
- out << std::setw(13) << "Manufacturer"
- << std::setw(10) << "Model"
- << std::setw(4) << "HP";
- }
- virtual void print(std::ostream& out) const {
- out << std::setw(13) << manufacturer
- << std::setw(10) << model
- << std::setw(4) << horsePower;
- }
- friend std::ostream& operator<<(std::ostream& out, const Vehicle& v);
- };
- inline std::ostream& operator<<(std::ostream& o, const Vehicle& v) {
- v.print(o);
- return o;
- }
- #pragma once
- #include "Vehicle.h"
- #include <iostream>
- #include <string>
- class Car : public Vehicle {
- bool isElectric;
- public:
- Car(std::string manufacturer, std::string model, int horsePower, bool isElectric) : Vehicle(manufacturer, model, horsePower), isElectric(isElectric) {
- }
- virtual void printHeader(std::ostream& out) {
- Vehicle::printHeader(out);
- out << std::setw(10) << "Electric\n";
- }
- virtual void print(std::ostream& out) {
- Vehicle::print(out);
- out << std::setw(10) << isElectric;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement