Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Date { // Класата Date содржи три цели броеви (int year, month, day)
- private: // кои претставуваат датум.
- int year;
- int month;
- int day;
- public:
- Date(){} // предодреден (default) конструктор,
- Date (int year, int month, int day) { //конструктор со параметри
- this->year=year;
- this->month=month;
- this->day=day;
- }
- Date (const Date &d) { // и конструктор за копирање.
- this->year=d.year;
- this->month=d.month;
- this->day=d. day;
- }
- void print () { // За неа треба да се напише метод за печатење print(),
- cout<<year<<"."<<month<<"."<<day<<".";
- } //Методот за печатење кај класата Date изгледа вака: [year].[month].[day].
- };
- class Person { //Класата Person содржи име и презиме (низи од максимум 20 знаци,
- private:
- char ime [20];
- char prezime[20];
- public:
- Person (char *ime, char *prezime) { // конструктор со параметри
- strcpy(this->ime, ime);
- strcpy(this->prezime, prezime);
- }
- Person() { // предодреден конструктор,
- strcpy(this->ime, "not specified"); //со предодредени вредности not specified),
- strcpy(this->prezime, "not specified");
- }
- void print() {// и метод за печатење print().
- cout<<ime<<" "<<prezime;
- } //Методот за печатење кај класата Person изгледа вака: [name] [lastName].
- };
- class Car { // За еден автомобил (објект од класата Car) се чуваат следниве податоци:
- private:
- Person p; // сопственик (објект од класата Person)
- Date d;// датум на купување (објект од класата Date)
- float price; // цена (float price), предодредена вредност 0
- public:
- Car(){} //За класата Car потребно е да се напише метод за печатење print()
- Car(Person p, Date d, float price) {
- this->p=p;
- this->d=d;
- this->price=price;
- } //Методот за печатење кај класата Car изгледа вака:
- void print() { //owner.print(), date.print(), Price: [price]
- p.print();
- cout<<endl;
- d.print();
- cout<<endl<<"Price: "<<price<<endl;
- }
- float getPrice() { // и метод за добивање на цената getPrice().
- return price;
- }
- };
- void cheaperThan(Car* cars, int numCars, float price) { //Покрај тоа, потребно е да се напише метод
- for(int i=0; i<numCars; i++) { // cheaperThan(Car* cars, int numCars, float price)
- if (cars[i].getPrice() < price) //кој ќе ги испечати сите објекти Car од низата cars со
- cars[i].print();// големина numCars чија цена е помала од price.
- }
- }
- 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(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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement