Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. class BenzinesAuto {
  8.  
  9. public:
  10.     BenzinesAuto(string tipus, int uzemanyag, float fogyasztas) {
  11.         this->tipus = tipus;
  12.         this->uzemanyag = uzemanyag;
  13.         this->fogyasztas = fogyasztas;
  14.     }
  15.  
  16.     BenzinesAuto() {
  17.         cin >> tipus >> uzemanyag >> fogyasztas;
  18.     }
  19.  
  20.     BenzinesAuto(string arg0) {
  21.         ifstream file(arg0);
  22.         file >> tipus >> uzemanyag >> fogyasztas;
  23.         file.close();
  24.     }
  25.  
  26.     virtual float hatotav() {
  27.         return 100 / fogyasztas * uzemanyag;
  28.     }
  29.  
  30.     void kiir() {
  31.         cout << tipus << " " << uzemanyag << " " << fogyasztas << "\n";
  32.     }
  33.  
  34.     void ment() {
  35.         ofstream fileout("ki.txt");
  36.         fileout << tipus << endl;
  37.         fileout << uzemanyag << endl;
  38.         fileout << fogyasztas << endl;
  39.         fileout.close();
  40.     }
  41.  
  42. protected:
  43.     string tipus;
  44.     int uzemanyag;
  45.     float fogyasztas;
  46. };
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. class HibridAuto : public BenzinesAuto {
  55. private:
  56.     bool onvezeto;
  57.     int elektromosHatotav;
  58.  
  59. public:
  60.     HibridAuto(string tipus, int uzemanyag, float fogyasztas, int elektromosHatotav, bool onvezeto) : BenzinesAuto(tipus, uzemanyag, fogyasztas) {
  61.         this->tipus = tipus;
  62.         this->uzemanyag = uzemanyag;
  63.         this->fogyasztas = fogyasztas;
  64.         this->elektromosHatotav = elektromosHatotav;
  65.         this->onvezeto = onvezeto;
  66.     }
  67.  
  68.     float hatotav() override {
  69.         return 100 / fogyasztas * uzemanyag + elektromosHatotav;
  70.     }
  71. };
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. class AutoKolcsonzo {
  81.  
  82. public:
  83.     HibridAuto *autok;
  84.     int kapacitas;
  85.  
  86.     // HibridAuto a = new HibridAuto(b)
  87.     AutoKolcsonzo(int kapacitas) {
  88.     this -> kapacitas = kapacitas;
  89.     this -> autok = new HibridAuto[kapacitas];
  90.     }
  91.  
  92.     /*AutoKolcsonzo(AutoKolcsonzo zs) {
  93.         this -> kapacitas = zs -> kapacitas;
  94.         this -> autok = zs -> autok; // ha nem akk for ciklus
  95.         //HibridAuto a = new HibridAuto(this -> autok[0]);
  96.     }*/
  97.  
  98.     ~AutoKolcsonzo() {
  99.         delete(this -> autok[0]);
  100.     }
  101.  
  102. };
  103.  
  104.  
  105.  
  106. void operator += (HibridAuto a) {
  107.     for(int i = 0; i < this -> kapacitas; i++) {
  108.  
  109.     }
  110. }
  111.  
  112. void operator [] (int a) {
  113.     return this -> autok[a];
  114. }
  115.  
  116.  
  117.  
  118.  
  119. int main() {
  120.  
  121.     AutoKolcsonzo autokolcsonzo = new AutoKolcsonzo(5);
  122.     BenzinesAuto a1("a1", 800, 5.5f);
  123.     BenzinesAuto a2("a2", 700, 5.1f);
  124.     HibridAuto a3("a3", 600, 5.2f);
  125.  
  126.     autokolcsonzo += a1;
  127.     autokolcsonzo += a2;
  128.     autokolcsonzo += a3;
  129.  
  130.  
  131.  
  132.  
  133.  
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement