Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Automobile {
- private:
- char *brand;
- int *regNum;
- int maxSpeed;
- void intcpy(int dest[], const int source[], const int len){
- for(int i = 0; i < len; i++){
- dest[i] = source[i];
- }
- }
- public:
- Automobile(){ brand = NULL; regNum = NULL; }
- ~Automobile(){ delete [] brand; delete [] regNum; }
- Automobile(const Automobile &a){
- //delete [] brand; delete [] regNum;
- brand = new char[strlen(a.brand)+1];
- strcpy(brand, a.brand);
- regNum = new int[5];
- intcpy(regNum, a.regNum, 5);
- maxSpeed = a.maxSpeed;
- }
- Automobile(char *b, int *r, int m){
- //delete [] brand; delete [] regNum;
- brand = new char[strlen(b)+1];
- strcpy(brand, b);
- regNum = new int[5];
- intcpy(regNum, r, 5);
- maxSpeed = m;
- }
- Automobile &operator = (const Automobile &a){
- if(this == &a) {return *this;}
- delete [] brand; delete [] regNum;
- brand = new char[strlen(a.brand)+1];
- strcpy(brand, a.brand);
- regNum = new int[5];
- intcpy(regNum, a.regNum, 5);
- maxSpeed = a.maxSpeed;
- return *this;
- }
- bool operator == (const Automobile &rhs){
- for(int i = 0; i < 5; ++i){
- if(regNum[i] != rhs.regNum[i]){ return false; }
- }
- return true;
- }
- friend ostream & operator << (ostream &out, const Automobile &a){
- out << "Marka\t" << a.brand << "\t" << "Registracija[ ";
- for (int i = 0; i < 5; ++i) {
- out << a.regNum[i] << " ";
- } out << "]" << endl;
- return out;
- }
- const int getMaxSpeed(){ return maxSpeed; }
- };
- class RentACar{
- private:
- char name[100];
- Automobile *autos;
- int len;
- void autocpy(Automobile dest[], const Automobile source[], int len){
- for(int i = 0; i < len; i++){
- dest[i] = source[i];
- }
- }
- public:
- RentACar() { autos = NULL; }
- ~RentACar() { delete [] autos; }
- RentACar(const char *n) {
- strcpy(name, n);
- autos = NULL;
- len = 0;
- }
- RentACar(const RentACar &r){
- //delete [] autos;
- strcpy(name, r.name);
- autos = new Automobile[r.len + 1];
- autocpy(autos, r.autos, r.len);
- len = r.len;
- }
- RentACar &operator = (const RentACar &r){
- if(this == &r) { return *this; }
- delete [] autos;
- strcpy(name, r.name);
- autos = new Automobile[r.len + 1];
- autocpy(autos, r.autos, r.len);
- len = r.len;
- return *this;
- }
- RentACar & operator += (const Automobile &a){
- Automobile *old = autos;
- autos = new Automobile[len+1];
- autocpy(autos, old, len);
- autos[len++] = a;
- delete [] old;
- return *this;
- }
- RentACar & operator -= (const Automobile &a){
- for(int i = 0; i < len; i++){
- if(autos[i] == a){
- Automobile *old = autos;
- autos = new Automobile[len-1];
- for(int j = 0, k = 0; j < len; j++){
- if(!(old[j] == a)){
- autos[k++] = old[j];
- }
- }
- delete [] old;
- break;
- }
- }
- return *this;
- }
- void printWithSpeedOver(int max) {
- cout << name << endl;
- for (int i = 0; i < len; i++) {
- if (autos[i].getMaxSpeed() > max) {
- cout << autos[i];
- }
- }
- }
- };
- 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.printWithSpeedOver(150);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement