Josif_tepe

Untitled

Sep 12th, 2026
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Car {
  6. private:
  7.     int year;
  8.     string make, model;
  9.     double consumption;
  10.    
  11. public:
  12.     Car() {
  13.         // default (empty) constructor
  14.     }
  15.    
  16.     Car(int _year, string make, string model, double consumption)  { // constructor with parameters
  17.         year = _year;
  18.         this->make = make;
  19.         this->model = model;
  20.         this->consumption = consumption;
  21.     }
  22.    
  23.     Car(const Car & tmp) {
  24.         this->year = tmp.year;
  25.         this->make = tmp.make;
  26.         this->model = tmp.model;
  27.         this->consumption = tmp.consumption;
  28.     }
  29.    
  30.     Car & operator = (const Car & tmp) { // operator = za dodeluvanje
  31.         this->year = tmp.year;
  32.         this->make = tmp.make;
  33.         this->model = tmp.model;
  34.         this->consumption = tmp.consumption;
  35.        
  36.         return *this;
  37.     }
  38.    
  39.     ~Car() {}
  40.    
  41.     int get_year() {
  42.         return year;
  43.     }
  44.    
  45.     string get_make() {
  46.         return make;
  47.     }
  48.    
  49.     string get_model() {
  50.         return model;
  51.     }
  52.    
  53.     double get_consumption() {
  54.         return consumption;
  55.     }
  56.    
  57.    
  58.     void set_year(int _year) {
  59.         this->year = _year;
  60.     }
  61.     void set_make(string _make) {
  62.         this->make = _make;
  63.     }
  64.     void set_model(string _model) {
  65.         this->model = _model;
  66.     }
  67.     void set_consumtion(double _consumption) {
  68.         this->consumption = _consumption;
  69.     }
  70.    
  71.  
  72.  
  73. };
  74.  
  75. int main() {
  76.    
  77.     Car c(2025, "mercedes", "S", 15);
  78.    
  79.     Car c2(c);
  80.    
  81.    
  82.    
  83.    
  84.    
  85.    
  86.    
  87.    
  88.  
  89.     return 0;
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment