Advertisement
Guest User

lab6

a guest
Dec 11th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <clocale>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. class Engine
  11. {
  12.     float eng_volume;
  13.     int power;
  14. public:
  15.     Engine(float vol, int pow) : eng_volume(vol), power(pow) {}
  16.     void printEng() { cout << "Объём " << eng_volume << "л, мощность " << power << "л.с." << endl; }
  17. };
  18.  
  19. class Body
  20. {
  21.  
  22.     int door_cnt;
  23.     string type;
  24.  
  25. public:
  26.     Body(int cnt, string tpe) : door_cnt(cnt), type(tpe) {}
  27.     int getDoorCnt() {
  28.         return door_cnt;
  29.     }
  30.  
  31.     string getType() {
  32.         return type;
  33.     }
  34. };
  35.  
  36. class Color
  37. {
  38.     string color;
  39. public:
  40.    
  41.     Color(string c) : color(c) {}
  42.     string getColor() {
  43.         return color;
  44.     }
  45.  
  46. };
  47.  
  48. class Car :
  49.     private Engine, private Body, private Color
  50. {
  51.     string make;
  52.  
  53. public:
  54.     Car(string _make, string color, string type, int door_cnt, int power, double eng_vol) :
  55.         Color(color), Engine(eng_vol, power), Body(door_cnt, type), make(_make) {}
  56.  
  57.     void printInfo() {
  58.         cout << "Автомобиль " << make
  59.             << ", цвет " << getColor() << " "
  60.             << getDoorCnt() << "-дверный " << getType()
  61.             << endl << "Двигатель: " << endl;
  62.         printEng();
  63.     }
  64.  
  65. };
  66.  
  67.  
  68. int main()
  69. {
  70.  
  71.     setlocale(LC_ALL, "Russian");
  72.    
  73.     Car myCar("Ваз 2107", "вишнёвый", "седан", 4, 72, 1.6);
  74.  
  75.     myCar.printInfo();
  76.    
  77.     system("pause>>void");
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement