Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h> // srand, rand
  4. #include <time.h>   // time
  5.  
  6. using namespace std;
  7.  
  8. class Car {
  9. string mark;
  10. string model;
  11. unsigned int price;
  12.  
  13. unsigned int getPrice() {
  14. srand(time(NULL));
  15. return rand() % 5000 + 145000;
  16. }
  17.  
  18. public:
  19. Car(string new_mark = "Volvo", string new_model = "s80") {
  20. price = getPrice();
  21. mark = new_mark;
  22. model = new_model;
  23. }
  24.  
  25. Car(const Car& Car_pattern) {
  26. // TODO
  27. }
  28.  
  29. string getModel() {
  30. return model;
  31. }
  32.  
  33. void setModel(string new_model) {
  34. model = new_model;
  35. }
  36.  
  37. string getMark() {
  38. return mark;
  39. }
  40.  
  41. void setMark(string new_mark) {
  42. mark = new_mark;
  43. }
  44.  
  45. ~Car() {
  46. cout << "I'm a destructor of car, bye, bye." << endl;
  47. }
  48. };
  49.  
  50. void fillArrayOfCars(Car *car_arr, int size) {
  51. for (int i = 0; i < size; i++) {
  52. Car TempCar;
  53. car_arr[i] = TempCar;
  54. }
  55. }
  56.  
  57. class CarOwner {
  58. int car_owner_id;
  59. static int recent_id;
  60.  
  61. static unsigned int car_counter;
  62. static const unsigned int car_limit;
  63. Car *car_owned = nullptr;
  64.  
  65. void copyCartable(Car car_ovned_tab) {
  66. if (car_owned != nullptr) {
  67.  
  68. }
  69. }
  70. public:
  71. CarOwner():
  72. car_owner_id(recent_id++)
  73. {
  74. cout << "Konstruktor domyslny." << endl;
  75. car_owner_id++;
  76. }
  77.  
  78. CarOwner( Car *car_owned ) {
  79. cout << "Konstruktor sparametryzowany." << endl;
  80. }
  81.  
  82. CarOwner(const CarOwner& car_owner_pattern) {
  83. cout << "Konstruktor kopiujÄ…cy." << endl;
  84. car_owned = car_owner_pattern.car_owned == nullptr
  85. ? nullptr
  86. : new Car[car_limit];
  87. }
  88.  
  89. void getCarOwned() {
  90.  
  91. }
  92.  
  93. void getCarCounter() {
  94.  
  95. }
  96.  
  97. void getCarOwnerId() {
  98.  
  99. }
  100.  
  101. ~CarOwner () {
  102. cout << "I'm a destructor of car owner, bye, bye." << endl;
  103. }
  104. };
  105.  
  106. int CarOwner::recent_id = 1;
  107. unsigned int CarOwner::car_counter = 0;
  108. const unsigned int CarOwner::car_limit = 3;
  109. Car CarOwner::*car_owned = NULL;
  110.  
  111. int main() {
  112. // 1.
  113. Car MyVolvo();
  114.  
  115. // 2.
  116. Car *volvo_array = new Car[10];
  117. fillArrayOfCars(volvo_array, 10);
  118.  
  119. // 3.
  120. Car Kupiec_1();
  121. Car Kupiec_2();
  122. Car Kupiec_3();
  123.  
  124. system("pause");
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement