Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Person{
- private:
- char name[20];
- char lastname[20];
- public:
- Person(){
- strcpy(this->name,"not specified");
- strcpy(this->lastname,"not specified");
- };
- Person(const char *x,const char *y){
- strcpy(this->name,x);
- strcpy(this->lastname,y);
- }
- void print(){
- std :: cout << this->name <<" " << this->lastname << std :: endl;
- }
- ~Person(){}
- };
- class Date{
- private:
- int year;
- int month;
- int day;
- public:
- Date(){};
- Date(int x,int y,int z){
- this->year=x;
- this->month=y;
- this->day=z;
- }
- Date(const Date &d) {
- year = d.year;
- month = d.month;
- day = d.day;
- }
- void print(){
- std::cout<<this->year<<"."<<this->month<<"."<<this->day<< std::endl;
- }
- ~Date(){}
- };
- class Car{
- private:
- Person owner;
- Date date;
- float price;
- public:
- Car(){ price = 0.0;}
- Car(Person p,Date d,float x){
- price=x;
- owner=p;
- date=d;
- }
- float getPrice()
- {
- return price;
- }
- void print()
- {
- owner.print();
- date.print();
- std::cout<<"Price: "<<price;
- }
- ~Car(){}
- };
- 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(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