Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <random>
  5. #include <sstream>
  6. #include <vector>
  7.  
  8. class Car {
  9.     friend class Customer;
  10.  
  11.     public:
  12.         std::string brand = "Fiat";
  13.         std::string model = "126P";
  14.         double price;
  15.  
  16.         std::random_device random;
  17.  
  18.         Car() {
  19.             std::uniform_real_distribution<double> dist(5000, 150000);
  20.  
  21.             price = dist(random);
  22.         };
  23.        
  24.         std::string getBrand() {
  25.             return brand;
  26.         };
  27.  
  28.         std::string getModel() {
  29.             return model;
  30.         };
  31.  
  32.         double getPrice() {
  33.             return price;
  34.         };
  35. };
  36.  
  37. class Customer {
  38.     private:
  39.         static int counter;
  40.     public:
  41.         int ID;
  42.         const short limit = 3;
  43.         Car* cars = nullptr;
  44.  
  45.         Customer(Car* cars) {
  46.             ID = counter;
  47.             counter++;
  48.             std::cout << "\nWywolano konstruktor sparametryzowany\n";
  49.             std::cout << "Customer ID: " << ID << std::endl;
  50.             this->cars = new Car[limit];
  51.  
  52.             for (int i = 0; i < limit; i++) {
  53.                 this->cars[i].brand = cars[i].brand;
  54.                 this->cars[i].model = cars[i].model;
  55.                 this->cars[i].price = cars[i].price;
  56.             };
  57.         };
  58.  
  59.         Customer() {
  60.             ID = counter;
  61.             counter++;
  62.             std::cout << "\nWywolano konstruktor domyslny\n";
  63.             std::cout << "Customer ID: " << ID << std::endl;
  64.         };
  65.  
  66.         Customer(const Customer &customer) {
  67.             ID = counter;
  68.             counter++;
  69.             std::cout << "\nWywolano konstruktor kopiujacy\n";
  70.             std::cout << "Customer ID: " << ID << std::endl;
  71.             cars = customer.cars;
  72.         }
  73.  
  74.         int getId() {
  75.             return ID;
  76.         };
  77.  
  78.         void coutAllInfo() {
  79.             std::cout << "Customer ID: " << ID << std::endl;
  80.         }
  81.  
  82.         void coutCars() {
  83.             for (int i = 0; i < limit; i++) {
  84.                 std::cout << "Brand: " << cars[i].getBrand() << " Model: " << cars[i].getModel() << " price: " << cars[1].getPrice() << "$" << std::endl;
  85.             };
  86.         };
  87. };
  88.  
  89. int Customer::counter = 1;
  90.  
  91. int main() {
  92.  
  93.  
  94.     int test;
  95.     Car cars[10];
  96.     Customer customer1;
  97.     Customer customer2(cars);
  98.     Customer customer3 = customer2;
  99.  
  100.     customer2.coutCars();
  101.  
  102.  
  103.     std::cin >> test;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement