Gromov

Untitled

Sep 22nd, 2020
915
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /******************************************************************************
  2.  
  3.                               Online C++ Compiler.
  4.                Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. class Auto
  15. {
  16. private:
  17.  
  18.   float vidBenzinaPaterins; // uz 100 km
  19.  
  20.   unsigned gads;
  21.  
  22.   string marka;
  23.  
  24.   string modelis;
  25.  
  26.  
  27.  
  28. public:
  29.  
  30. //Konstruktori
  31.  
  32. Auto()
  33. {
  34.     marka = "McLaren";
  35.     modelis = "720s";
  36.     vidBenzinaPaterins = 21;
  37. }
  38.  
  39. Auto(float vid)
  40. {
  41.     marka = "McLaren";
  42.     modelis = "720s";
  43.     this->vidBenzinaPaterins = 21;
  44. }
  45.  
  46. //Destruktori
  47.  
  48. ~Auto(){
  49.    
  50.     cin.get()
  51. }
  52.  
  53.   //set metodes
  54.  
  55.    void setMarka(string marka)
  56.    {
  57.        this->marka = marka;
  58.    }
  59.    
  60.    void setGads(unsigned gads)
  61.    {
  62.        this->gads = gads;
  63.    }
  64.    
  65.    void setVidBenzinaPaterins(float vidBenzinaPaterins)
  66.    {
  67.        this->vidBenzinaPaterins = vidBenzinaPaterins;
  68.    }
  69.    
  70.    void setModelis(string modelis)
  71.    {
  72.        this->modelis = modelis;
  73.    }
  74.    
  75.   //get metodes
  76.  
  77.     string getMarka() const
  78.   {
  79.     return marka;
  80.   }
  81.  
  82.   string getModelis() const
  83.   {
  84.     return modelis;
  85.   }
  86.  
  87.   unsigned getGads() const
  88.   {
  89.     return gads;
  90.   }
  91.  
  92.    float getVidBenzinaPaterins() const
  93.   {
  94.     return vidBenzinaPaterins;
  95.   }
  96.  
  97.   void printAutoData() const;
  98.  
  99.   float getCelaBenzins(float km) const;
  100.  
  101.  
  102. };
  103.  
  104. void Auto::printAutoData() const {
  105.    cout<< "\nAuto " << marka << " " << modelis << " kas tika izlaista " << gads << " gada. Benzina paterins ir " << vidBenzinaPaterins << " l/100km.";
  106. }
  107.  
  108. float Auto::getCelaBenzins(float km) const {
  109.      return  vidBenzinaPaterins / 100 * km;
  110. }
  111.  
  112. Auto mansAuto;
  113. Auto *skolasAuto;
  114.  
  115. int main()
  116. {
  117.     float trip;
  118.    
  119.     skolasAuto = new Auto;
  120.    
  121.     mansAuto.setModelis("Huracan");
  122.     mansAuto.setMarka("Lamborghini");
  123.     mansAuto.setGads(2020);
  124.     mansAuto.setVidBenzinaPaterins(25);
  125.    
  126.     skolasAuto->setModelis("Accord");
  127.     skolasAuto->setMarka("Honda");
  128.     skolasAuto->setGads(2002);
  129.     skolasAuto->setVidBenzinaPaterins(7);
  130.    
  131.     cout<< mansAuto.getMarka() << char(32) << mansAuto.getModelis() << ", " << mansAuto.getGads()
  132.     << " year, spends " << mansAuto.getVidBenzinaPaterins() << " l/100km " << endl;
  133.    
  134.     cout << "Enter full trip distance: ";
  135.    
  136.     cin >> trip ;
  137.    
  138.     cout << "Trip fuel consumption: " << mansAuto.getCelaBenzins(trip) << endl << endl;
  139.    
  140.     cout<< skolasAuto->getMarka() << char(32) << skolasAuto->getModelis() << ", " << skolasAuto->getGads()
  141.     << " year, spends " << skolasAuto->getVidBenzinaPaterins() << " l/100km ";
  142.    
  143.     cout << "\nEnter full trip distance: ";
  144.    
  145.     cin >> trip ;
  146.    
  147.     cout << "Trip fuel consumption: " << skolasAuto->getCelaBenzins(trip) << endl;
  148.      
  149.      mansAuto.printAutoData();
  150.      
  151.      skolasAuto->printAutoData();
  152.  
  153.     delete skolasAuto;
  154.     return 0;
  155. }
  156.  
  157.  
  158.  
RAW Paste Data