P1ayer4312

Лаб. Автомобил

Apr 3rd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.19 KB | None | 0 0
  1. // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. class Date {
  9. protected:
  10.     int year, month, day;
  11. public:
  12.     Date() {
  13.         this->year = 1999;
  14.         this->month = 1;
  15.         this->day = 1;
  16.     }
  17.     Date(int _year, int _month = 1, int _day = 1) {
  18.         this->year = _year;
  19.         this->month = _month;
  20.         this->day = _day;
  21.     }
  22.     Date(Date &r) {
  23.         this->year = r.year;
  24.         this->month = r.month;
  25.         this->day = r.day;
  26.     }
  27.  
  28.     void print() {
  29.         cout << this->year << '.' << this->month << '.' << this->day << endl;
  30.     }
  31. };
  32.  
  33. class Person {
  34. protected:
  35.     char *ime, *prezime;
  36. public:
  37.     Person() {
  38.         this->ime = new char[20];
  39.         this->prezime = new char[20];
  40.         strcpy(this->ime, "not specified");
  41.         strcpy(this->prezime, "not specified");
  42.     }
  43.     Person(char* _ime, char* _prezime) {
  44.         this->ime = new char[20];
  45.         this->prezime = new char[20];
  46.         strcpy(this->ime, _ime);
  47.         strcpy(this->prezime, _prezime);
  48.     }
  49.  
  50.     void print() {
  51.         cout << this->ime << " " << this->prezime << endl;
  52.     }
  53.  
  54. };
  55.  
  56. class Car {
  57. protected:
  58.     Person owner;
  59.     Date date;
  60.     float price;
  61. public:
  62.     Car() {}
  63.     Car(Person _owner, Date _date , float _price) {
  64.         this->owner = _owner;
  65.         this->date = _date;
  66.         this->price = _price;
  67.     }
  68.  
  69.     void print() {
  70.         owner.print();
  71.         date.print();
  72.         cout << "Price: " << this->price;
  73.     }
  74.  
  75.     float getPrice() {
  76.         return this->price;
  77.     }
  78. };
  79.  
  80. void cheaperThan(Car* cars, int numCars, float price) {
  81.     for (int i = 0; i < numCars; i++) {
  82.         if (cars[i].getPrice() < price) {
  83.             cars[i].print();
  84.         }
  85.     }
  86.  
  87.  
  88.  
  89. }
  90.  
  91. int main() {
  92.     char name[20];
  93.     char lastName[20];
  94.     int year;
  95.     int month;
  96.     int day;
  97.     float price;
  98.  
  99.     int testCase;
  100.     cin >> testCase;
  101.  
  102.     if (testCase == 1) {
  103.         cin >> name;
  104.         cin >> lastName;
  105.         Person lik(name, lastName);
  106.  
  107.         cin >> year;
  108.         cin >> month;
  109.         cin >> day;
  110.         Date date(year, month, day);
  111.  
  112.         cin >> price;
  113.         Car car(lik, date, price);
  114.  
  115.         car.print();
  116.     }
  117.     else if (testCase == 2) {
  118.         cin >> name;
  119.         cin >> lastName;
  120.         Person lik(name, lastName);
  121.  
  122.         cin >> year;
  123.         cin >> month;
  124.         cin >> day;
  125.         Date date(year, month, day);
  126.  
  127.         cin >> price;
  128.         Car car(lik, date, price);
  129.         car.print();
  130.     }
  131.     else {
  132.         int numCars;
  133.         cin >> numCars;
  134.  
  135.         Car cars[10];
  136.         for (int i = 0; i < numCars; i++) {
  137.             cin >> name;
  138.             cin >> lastName;
  139.             Person lik(name, lastName);
  140.  
  141.             cin >> year;
  142.             cin >> month;
  143.             cin >> day;
  144.             Date date(year, month, day);
  145.  
  146.             cin >> price;
  147.             cars[i] = Car(lik, date, price);
  148.         }
  149.         float priceLimit;
  150.         cin >> priceLimit;
  151.         cheaperThan(cars, numCars, priceLimit);
  152.     }
  153.  
  154.  
  155.     return 0;
  156. }
Add Comment
Please, Sign In to add comment