Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- void copy_string(char*, const char*, const int);
- class Automobile {
- char* marka;
- int registracija[5];
- int maksimalna_brzina;
- public:
- Automobile() {
- marka = 0;
- for(int i = 0; i < 5; ++i) registracija[i] = 0;
- maksimalna_brzina = 0;
- }
- Automobile(const char* _marka, const int* _registracija, const int _maksimalna_brzina) {
- marka = new char[strlen(_marka)+1];
- copy_string(marka, _marka, strlen(_marka));
- for(int i = 0; i < 5; ++i) registracija[i] = _registracija[i];
- maksimalna_brzina = _maksimalna_brzina;
- }
- Automobile(const Automobile& obj) {
- marka = new char[strlen(obj.marka)+1];
- copy_string(marka, obj.marka, strlen(obj.marka));
- for(int i = 0; i < 5; ++i) registracija[i] = obj.registracija[i];
- maksimalna_brzina = obj.maksimalna_brzina;
- }
- Automobile& operator=(const Automobile& obj) {
- if(this != &obj) {
- delete [] marka;
- marka = new char[strlen(obj.marka)+1];
- copy_string(marka, obj.marka, strlen(obj.marka));
- for(int i = 0; i < 5; ++i) registracija[i] = obj.registracija[i];
- maksimalna_brzina = obj.maksimalna_brzina;
- }
- return *this;
- }
- bool operator==(const Automobile& obj) {
- int c = 0;
- for(int i = 0; i < 5; ++i) if(registracija[i] == obj.registracija[i]) c++;
- return c == 5 ? true : false;
- }
- // Marka:име Registracija:[x y z k l]
- friend ostream& operator<<(ostream& o, const Automobile& obj) {
- o<<"Marka\t"<<obj.marka<<"\tRegistracija[ ";
- for(int i = 0; i < 5; ++i) {
- o<<obj.registracija[i];
- if(i < 4) o << " ";
- }
- o << " ]" << endl;
- return o;
- }
- // getters
- char* get_marka() {
- return marka;
- }
- int* get_registracija() {
- return registracija;
- }
- int get_maks_brzina() {
- return maksimalna_brzina;
- }
- // setters
- void set_marka(const char* _marka) {
- marka = new char[strlen(_marka)+1];
- copy_string(marka, _marka, strlen(_marka));
- }
- void set_registracija(const int _registracija[5]) {
- for(int i = 0; i < 5; ++i) registracija[i] = _registracija[i];
- }
- void set_maks_brzina(const int brzina) {
- maksimalna_brzina = brzina;
- }
- ~Automobile() {
- delete [] marka;
- }
- };
- class RentACar {
- char ime[100];
- Automobile* avtomobili;
- int broj_na_avtomobili;
- public:
- RentACar(const char* _ime = "") {
- strcpy(ime, _ime);
- broj_na_avtomobili = 0;
- }
- RentACar(const RentACar& obj) {
- strcpy(ime, obj.ime);
- broj_na_avtomobili = obj.broj_na_avtomobili;
- avtomobili = new Automobile[broj_na_avtomobili];
- for(int i = 0; i < broj_na_avtomobili; ++i) {
- avtomobili[i] = obj.avtomobili[i];
- }
- }
- RentACar& operator=(const RentACar& obj) {
- if(this != &obj) {
- strcpy(ime, obj.ime);
- broj_na_avtomobili = obj.broj_na_avtomobili;
- delete [] avtomobili;
- avtomobili = new Automobile[broj_na_avtomobili];
- for(int i = 0; i < broj_na_avtomobili; ++i) {
- avtomobili[i] = obj.avtomobili[i];
- }
- }
- return *this;
- }
- RentACar& operator+=(Automobile& obj) {
- Automobile* temp = new Automobile[broj_na_avtomobili+1];
- for(int i = 0; i < broj_na_avtomobili; ++i) {
- temp[i] = avtomobili[i];
- }
- if(broj_na_avtomobili != 0) delete [] avtomobili;
- temp[broj_na_avtomobili++] = obj;
- avtomobili = temp;
- return *this;
- }
- RentACar& operator-=(Automobile& obj) {
- Automobile* temp = new Automobile[broj_na_avtomobili];
- int j = 0;
- for(int i = 0; i < broj_na_avtomobili; ++i) {
- if(!(avtomobili[i] == obj))
- temp[j++] = avtomobili[i];
- }
- broj_na_avtomobili = j + 1;
- delete [] avtomobili;
- avtomobili = temp;
- return *this;
- }
- void pecatiNadBrzina(int brzina) {
- cout << ime << endl;
- for(int i = 0; i < broj_na_avtomobili; ++i) {
- if(avtomobili[i].get_maks_brzina() > brzina)
- cout << avtomobili[i];
- }
- }
- ~RentACar() {
- delete [] avtomobili;
- }
- };
- void copy_string(char* dest, const char* source, const int length) {
- strncpy(dest, source, length);
- dest[length] = 0;
- }
- int main() {
- RentACar agencija("FINKI-Car");
- int n;
- cin>>n;
- for (int i=0; i<n; i++) {
- char marka[100];
- int regisracija[5];
- int maximumBrzina;
- cin>>marka;
- for (int i=0; i<5; i++) {
- cin>>regisracija[i];
- }
- cin>>maximumBrzina;
- Automobile nov=Automobile(marka,regisracija,maximumBrzina);
- //dodavanje na avtomobil
- agencija+=nov;
- }
- //se cita grehsniot avtmobil, za koj shto avtmobilot so ista registracija treba da se izbrishe
- char marka[100];
- int regisracija[5];
- int maximumBrzina;
- cin>>marka;
- for (int i=0; i<5; i++)
- cin>>regisracija[i];
- cin>>maximumBrzina;
- Automobile greshka=Automobile(marka,regisracija,maximumBrzina);
- //brishenje na avtomobil
- agencija-=greshka;
- agencija.pecatiNadBrzina(150);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement