Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Date {
- protected:
- int year, month, day;
- public:
- Date() {
- this->year = 1999;
- this->month = 1;
- this->day = 1;
- }
- Date(int _year, int _month = 1, int _day = 1) {
- this->year = _year;
- this->month = _month;
- this->day = _day;
- }
- Date(Date &r) {
- this->year = r.year;
- this->month = r.month;
- this->day = r.day;
- }
- void print() {
- cout << this->year << '.' << this->month << '.' << this->day << endl;
- }
- };
- class Person {
- protected:
- char *ime, *prezime;
- public:
- Person() {
- this->ime = new char[20];
- this->prezime = new char[20];
- strcpy(this->ime, "not specified");
- strcpy(this->prezime, "not specified");
- }
- Person(char* _ime, char* _prezime) {
- this->ime = new char[20];
- this->prezime = new char[20];
- strcpy(this->ime, _ime);
- strcpy(this->prezime, _prezime);
- }
- void print() {
- cout << this->ime << " " << this->prezime << endl;
- }
- };
- class Car {
- protected:
- Person owner;
- Date date;
- float price;
- public:
- Car() {}
- Car(Person _owner, Date _date , float _price) {
- this->owner = _owner;
- this->date = _date;
- this->price = _price;
- }
- void print() {
- owner.print();
- date.print();
- cout << "Price: " << this->price;
- }
- float getPrice() {
- return this->price;
- }
- };
- void cheaperThan(Car* cars, int numCars, float price) {
- for (int i = 0; i < numCars; i++) {
- if (cars[i].getPrice() < price) {
- cars[i].print();
- }
- }
- }
- int main() {
- char name[20];
- char lastName[20];
- int year;
- int month;
- int day;
- float price;
- int testCase;
- cin >> testCase;
- if (testCase == 1) {
- cin >> name;
- cin >> lastName;
- Person lik(name, lastName);
- cin >> year;
- cin >> month;
- cin >> day;
- Date date(year, month, day);
- cin >> price;
- Car car(lik, date, price);
- car.print();
- }
- else if (testCase == 2) {
- cin >> name;
- cin >> lastName;
- Person lik(name, lastName);
- cin >> year;
- cin >> month;
- cin >> day;
- Date date(year, month, day);
- cin >> price;
- Car car(lik, date, price);
- car.print();
- }
- else {
- int numCars;
- cin >> numCars;
- Car cars[10];
- for (int i = 0; i < numCars; i++) {
- cin >> name;
- cin >> lastName;
- Person lik(name, lastName);
- cin >> year;
- cin >> month;
- cin >> day;
- Date date(year, month, day);
- cin >> price;
- cars[i] = Car(lik, date, price);
- }
- float priceLimit;
- cin >> priceLimit;
- cheaperThan(cars, numCars, priceLimit);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment