Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Матрица
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Matrica {
- private:
- int brojNaElementi;
- float arr[10][10];
- public:
- Matrica() {
- brojNaElementi = 10;
- for(int i=0; i<brojNaElementi; i++)
- for(int j=0; j<brojNaElementi; j++)
- arr[i][j] = 0;
- }
- Matrica(int brojNaElementi, float *arr[]) {
- this->brojNaElementi = brojNaElementi;
- for(int i=0; i<brojNaElementi; i++)
- for(int j=0; j<brojNaElementi; j++)
- this->arr[i][j] = arr[i][j];
- }
- Matrica& operator+(const int n) {
- for(int i=0; i < brojNaElementi; i++)
- for(int j=0; j < brojNaElementi; j++)
- arr[i][j] += n;
- return *this;
- }
- Matrica& operator-(const Matrica& m) {
- for(int i=0; i < brojNaElementi; i++)
- for(int j=0; j < brojNaElementi; j++)
- arr[i][j] -= m.arr[i][j];
- return *this;
- }
- Matrica operator*(const Matrica& m) {
- Matrica temp;
- for(int i=0; i < brojNaElementi; i++)
- for(int j=0; j < brojNaElementi; j++) {
- for(int l=0; l < brojNaElementi; l++)
- temp.arr[i][j] += arr[i][l] * m.arr[l][j];
- }
- return temp;
- }
- friend ostream& operator<<(ostream &screamAndShout, const Matrica &m) {
- for(int i=0; i < m.brojNaElementi; i++) {
- for(int j=0; j < m.brojNaElementi; j++)
- screamAndShout << m.arr[i][j] << " ";
- screamAndShout << endl;
- }
- return screamAndShout;
- }
- friend istream& operator>>(istream&, Matrica&);
- };
- istream& operator>>(istream &takeItIn, Matrica &m) {
- takeItIn >> m.brojNaElementi >> m.brojNaElementi;
- for(int i=0; i < m.brojNaElementi; i++)
- for(int j=0; j < m.brojNaElementi; j++)
- takeItIn >> m.arr[i][j];
- return takeItIn;
- }
- int main()
- {
- Matrica A, B, C;
- cin >> A >> B >> C;
- Matrica D = B * C;
- Matrica R = A - D + 2;
- cout << R;
- }
- 2. Планинарско друштво
- #include <iostream>
- #include <cstring>
- using namespace std;
- class PlDrustvo
- {
- private:
- char *name;
- int toursPassed, members;
- public:
- PlDrustvo(const char *name="", const int toursPassed=0, const int members=0)
- {
- this->name=new char[strlen(name)+1];
- strcpy(this->name, name);
- this->toursPassed=toursPassed;
- this->members=members;
- }
- PlDrustvo(const PlDrustvo &r)
- {
- name=new char[strlen(r.name)+1];
- strcpy(name, r.name);
- toursPassed=r.toursPassed;
- members=r.members;
- }
- PlDrustvo &operator=(const PlDrustvo &r)
- {
- if(this!=&r)
- {
- delete [] name;
- name=new char[strlen(r.name)+1];
- strcpy(name, r.name);
- toursPassed=r.toursPassed;
- members=r.members;
- }
- return *this;
- }
- ~PlDrustvo()
- {
- delete [] name;
- }
- friend ostream &operator<<(ostream &out, const PlDrustvo &o)
- {
- return out<<"Ime: "<<o.name<<" Turi: "<<o.toursPassed<<" Clenovi: "<<o.members<<endl;
- }
- PlDrustvo operator+(const PlDrustvo &r)
- {
- PlDrustvo newDrustvo;
- newDrustvo.members=members+r.members;
- delete [] newDrustvo.name;
- if(members>r.members)
- {
- newDrustvo.name=new char[strlen(name)+1];
- strcpy(newDrustvo.name, name);
- newDrustvo.toursPassed=toursPassed;
- }
- else
- {
- newDrustvo.name=new char[strlen(r.name)+1];
- strcpy(newDrustvo.name, r.name);
- newDrustvo.toursPassed=r.toursPassed;
- }
- return newDrustvo;
- }
- bool operator>(const PlDrustvo &r) { return members>r.members; }
- bool operator<(const PlDrustvo &r) { return members<r.members; }
- };
- void najmnoguClenovi(PlDrustvo *dr, int n)
- {
- PlDrustvo tmp=dr[0];
- for(int i=1; i<n; i++)
- {
- if(dr[i]>tmp)
- {
- tmp=dr[i];
- }
- }
- cout<<"Najmnogu clenovi ima planinarskoto drustvo: "<<tmp;
- }
- int main()
- {
- PlDrustvo drustva[3];
- PlDrustvo pl;
- for (int i=0;i<3;i++)
- {
- char ime[100];
- int brTuri;
- int brClenovi;
- cin>>ime;
- cin>>brTuri;
- cin>>brClenovi;
- PlDrustvo p(ime,brTuri,brClenovi);
- drustva[i] = p;
- }
- pl = drustva[0] + drustva[1];
- cout<<pl;
- najmnoguClenovi(drustva, 3);
- return 0;
- }
- 3. Автомобил
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Automobile{
- char *marka;
- int *registracija;
- int maxSpeed;
- public:
- Automobile(){marka=0;registracija=0;}
- Automobile(char *marka,int *registracija,int maxSpeed)
- {
- this->marka = new char[strlen(marka)+1];
- strcpy(this->marka,marka);
- this->registracija = new int[5];
- for(int i=0;i<5;i++)
- {
- this->registracija[i]=registracija[i];
- }
- this->maxSpeed=maxSpeed;
- }
- Automobile(const Automobile &a)
- {
- marka = new char[strlen(a.marka)+1];
- strcpy(marka,a.marka);
- registracija = new int[5];
- for(int i=0;i<5;i++)
- {
- registracija[i]=a.registracija[i];
- }
- maxSpeed=a.maxSpeed;
- }
- Automobile & operator =(const Automobile &a)
- {
- if(this!=&a)
- {
- marka = new char[strlen(a.marka)+1];
- strcpy(marka,a.marka);
- registracija = new int[5];
- for(int i=0;i<5;i++)
- {
- registracija[i]=a.registracija[i];
- }
- maxSpeed=a.maxSpeed;
- }
- return *this;
- }
- int getMax()
- {
- return maxSpeed;
- }
- ~Automobile(){
- delete [] marka;
- delete [] registracija;
- }
- bool operator ==(const Automobile &a)
- {
- for(int i=0;i<5;i++)
- {
- if(registracija[i]!=a.registracija[i])
- return false;
- }
- return true;
- }
- friend ostream & operator <<(ostream &out,const Automobile &a)
- {
- out<<"Marka\t"<<a.marka<<"\tRegistracija[ ";
- for(int i=0;i<5;i++)
- {
- out<<a.registracija[i]<<" ";
- }
- out<<"]";
- return out;
- }
- };
- class RentACar{
- char ime[100];
- Automobile *cars;
- int broj;
- public:
- RentACar(){cars=0;broj=0;}
- RentACar(const char *ime)
- {
- strcpy(this->ime,ime);
- broj=0;
- }
- RentACar(const RentACar &r)
- {
- strcpy(ime,r.ime);
- cars = new Automobile[r.broj];
- for(int i=0;i<r.broj;i++)
- {
- cars[i]=r.cars[i];
- }
- broj = r.broj;
- }
- ~RentACar(){delete [] cars;}
- RentACar & operator +=(const Automobile &a)
- {
- Automobile *temp = cars;
- cars = new Automobile[broj+1];
- for(int i=0;i<broj;i++)
- {
- cars[i]=temp[i];
- }
- cars[broj]=a;
- broj++;
- return *this;
- }
- RentACar & operator -=(const Automobile &a)
- {
- for(int i=0;i<broj;i++)
- {
- if(cars[i]==a)
- {
- for(int j=i;j<broj-1;j++)
- {
- cars[j]=cars[j+1];
- }
- broj--;
- }
- }
- return *this;
- }
- void pecatiNadBrzina(int max)
- {
- cout<<ime<<endl;
- for(int i=0;i<broj;i++)
- {
- if(cars[i].getMax()>max)
- cout<<cars[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.pecatiNadBrzina(150);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement