Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <random>
- #include <sstream>
- #include <vector>
- class Car {
- friend class Customer;
- public:
- std::string brand = "Fiat";
- std::string model = "126P";
- double price;
- std::random_device random;
- Car() {
- std::uniform_real_distribution<double> dist(5000, 150000);
- price = dist(random);
- };
- std::string getBrand() {
- return brand;
- };
- std::string getModel() {
- return model;
- };
- double getPrice() {
- return price;
- };
- };
- class Customer {
- private:
- static int counter;
- public:
- int ID;
- const short limit = 3;
- Car* cars = nullptr;
- Customer(Car* cars) {
- ID = counter;
- counter++;
- std::cout << "\nWywolano konstruktor sparametryzowany\n";
- std::cout << "Customer ID: " << ID << std::endl;
- this->cars = new Car[limit];
- for (int i = 0; i < limit; i++) {
- this->cars[i].brand = cars[i].brand;
- this->cars[i].model = cars[i].model;
- this->cars[i].price = cars[i].price;
- };
- };
- Customer() {
- ID = counter;
- counter++;
- std::cout << "\nWywolano konstruktor domyslny\n";
- std::cout << "Customer ID: " << ID << std::endl;
- };
- Customer(const Customer &customer) {
- ID = counter;
- counter++;
- std::cout << "\nWywolano konstruktor kopiujacy\n";
- std::cout << "Customer ID: " << ID << std::endl;
- cars = customer.cars;
- }
- int getId() {
- return ID;
- };
- void coutAllInfo() {
- std::cout << "Customer ID: " << ID << std::endl;
- }
- void coutCars() {
- for (int i = 0; i < limit; i++) {
- std::cout << "Brand: " << cars[i].getBrand() << " Model: " << cars[i].getModel() << " price: " << cars[1].getPrice() << "$" << std::endl;
- };
- };
- };
- int Customer::counter = 1;
- int main() {
- int test;
- Car cars[10];
- Customer customer1;
- Customer customer2(cars);
- Customer customer3 = customer2;
- customer2.coutCars();
- std::cin >> test;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement