Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <iomanip>
  6.  
  7. class Vehicle {
  8.     std::string manufacturer;
  9.     std::string model;
  10.     int horsePower;
  11.  
  12. public:
  13.     Vehicle(std::string manufacturer, std::string model, int horsePower) : manufacturer(manufacturer), model(model), horsePower(horsePower) {
  14.  
  15.     }
  16.  
  17.     virtual void printHeader(std::ostream& out) const {
  18.         out << std::setw(13) << "Manufacturer"
  19.             << std::setw(10) << "Model"
  20.             << std::setw(4)  << "HP";
  21.     }
  22.  
  23.     virtual void print(std::ostream& out) const {
  24.         out << std::setw(13) << manufacturer
  25.             << std::setw(10) << model
  26.             << std::setw(4)  << horsePower;
  27.     }
  28.  
  29.     friend std::ostream& operator<<(std::ostream& out, const Vehicle& v);
  30. };
  31.  
  32. inline std::ostream& operator<<(std::ostream& o, const Vehicle& v) {
  33.     v.print(o);
  34.     return o;
  35. }
  36.  
  37.  
  38. #pragma once
  39.  
  40. #include "Vehicle.h"
  41.  
  42. #include <iostream>
  43. #include <string>
  44.  
  45. class Car : public Vehicle {
  46.     bool isElectric;
  47.  
  48. public:
  49.     Car(std::string manufacturer, std::string model, int horsePower, bool isElectric) : Vehicle(manufacturer, model, horsePower), isElectric(isElectric) {
  50.  
  51.     }
  52.  
  53.     virtual void printHeader(std::ostream& out) {
  54.         Vehicle::printHeader(out);
  55.         out << std::setw(10) << "Electric\n";
  56.     }
  57.  
  58.     virtual void print(std::ostream& out) {
  59.         Vehicle::print(out);
  60.         out << std::setw(10) << isElectric;
  61.     }
  62. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement