Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Exception {
- public:
- void showMessage() {
- cout<<"Incorrect registration!"<<endl;
- }
- };
- class AlkoholException {
- public:
- void showMessage() {
- cout<<"Incorrect alcohol percentage!"<<endl;
- }
- };
- class ImaMasa {
- public:
- virtual double vratiMasa()=0;
- virtual void pecati () = 0 ;
- };
- class PaketPijalok {
- protected:
- double volumenEden;
- int kolicina;
- static double density;
- static double mass;
- public:
- PaketPijalok(double volumenEden=0.0 , int kolicina=0) {
- this->volumenEden=volumenEden;
- this->kolicina=kolicina;
- }
- PaketPijalok(const PaketPijalok &p) {
- this->volumenEden=p.volumenEden;
- this->kolicina=p.kolicina;
- }
- double vratiMasa() {
- return kolicina*(volumenEden *density+mass);
- }
- void pecati() {
- cout<<"quantity "<<kolicina;
- }
- int getKolicina() {
- return this->kolicina;
- }
- };
- double PaketPijalok::density=0.8;
- double PaketPijalok::mass=0.2;
- class PaketSok :public ImaMasa,PaketPijalok {
- private:
- bool daliGaziran;
- public:
- PaketSok(double volumenEden=0.0 , int kolicina=0,bool daliGaziran=true)
- :PaketPijalok(volumenEden,kolicina) {
- this->daliGaziran=daliGaziran;
- }
- PaketSok(const PaketSok &p) {
- this->daliGaziran=p.daliGaziran;
- }
- double vratiMasa() {
- if(!daliGaziran) {
- return PaketPijalok::vratiMasa()+(0.1 * kolicina);
- } else return PaketPijalok::vratiMasa();
- }
- void pecati() {
- cout<<"PaketSok"<<endl;
- cout<<"quantity "<<getKolicina()<<", each of "<<volumenEden*density<<" l(dm3)"<<endl;
- }
- };
- class PaketVino : public ImaMasa,PaketPijalok {
- private:
- double ProcentAlkohol;
- public:
- PaketVino(double volumenEden=0.0 , int kolicina=0,double ProcentAlkohol=0.0)
- :PaketPijalok(volumenEden,kolicina) {
- this->ProcentAlkohol=ProcentAlkohol;
- try {
- if(ProcentAlkohol<0 || ProcentAlkohol>1) {
- throw AlkoholException();
- }
- } catch (AlkoholException &e) {
- this->ProcentAlkohol=0;
- e.showMessage();
- }
- }
- PaketVino(const PaketVino &p) {
- this->ProcentAlkohol=p.ProcentAlkohol;
- }
- double getProcentAlokohol() {
- return this->ProcentAlkohol;
- }
- double vratiMasa() {
- double sum=(0.9+ProcentAlkohol);
- return PaketPijalok::vratiMasa()*sum;
- }
- void pecati() {
- cout<<"PaketVino"<<endl;
- cout<<"quantity "<<getKolicina()<<", "<<ProcentAlkohol*100<<"% alcohol each of "<<volumenEden*density<<" l(dm3)"<<endl;
- }
- };
- class Kamion {
- private:
- char registration [25];
- char driver[20];
- int n;
- ImaMasa**im;
- public:
- Kamion (char*registration = "", char *driver="") {
- if(!(isalpha (registration[0])&& isalpha(registration[6])&&isalpha(registration[7]))) {
- throw Exception();
- } else {
- strcpy(this->registration,registration);
- strcpy(this->driver,driver);
- im=new ImaMasa*[0];
- n=0;
- }
- }
- void dodadiElement(ImaMasa*m) {
- ImaMasa**tmp=new ImaMasa *[n+1];
- for(int i = 0 ; i < n ; i++) {
- tmp[i]=im[i];
- }
- tmp[n]=m;
- n++;
- delete[]im;
- im=tmp;
- }
- double vratiVkupnaMasa() {
- double sum=0.0;
- for(int i = 0 ; i < n ; i++) {
- sum+=im[i]->vratiMasa();
- }
- return sum;
- }
- void pecati() {
- cout<<"Truck with registration "<<registration<<" and driver "<<driver<<" transports: "<<endl;
- for(int i=0; i<n; i++) {
- im[i]->pecati();
- }
- }
- Kamion pretovar(char *reg, char *ime) {
- strcpy(registration,reg);
- strcpy(driver,ime);
- double maxMasa=0;
- int index=-1;
- for(int i=0; i<n; i++) {
- if(im[i]->vratiMasa() > maxMasa) {
- maxMasa=im[i]->vratiMasa();
- index=i;
- }
- }
- ImaMasa *p = im[index];
- ImaMasa **tmp=new ImaMasa*[n-1];
- int j=-1;
- for(int i=0; i<n; i++) {
- if(im[i] != p ) {
- j++;
- tmp[j]=im[i];
- }
- }
- delete [] im;
- im=tmp;
- this->n--;
- return *this;
- }
- };
- int main() {
- char ime[20], reg[9];
- double vol;
- int kol;
- bool g;
- double proc;
- try {
- cin>>reg;
- cin>>ime;
- Kamion A(reg, ime);
- ImaMasa **d = new ImaMasa*[5];
- cin>>vol>>kol;
- cin>>g;
- d[0] = new PaketSok(vol, kol, g);
- cin>>vol>>kol;
- cin>>proc;
- d[1] = new PaketVino(vol, kol, proc);
- cin>>vol>>kol;
- cin>>proc;
- d[2] = new PaketVino(vol, kol, proc);
- cin>>vol>>kol;
- cin>>g;
- d[3] = new PaketSok(vol, kol, g);
- cin>>vol>>kol;
- cin>>proc;
- d[4] = new PaketVino(vol, kol, proc);
- A.dodadiElement(d[0]);
- A.dodadiElement(d[1]);
- A.dodadiElement(d[2]);
- A.dodadiElement(d[3]);
- A.dodadiElement(d[4]);
- A.pecati();
- cout<<"Total mass: "<<A.vratiVkupnaMasa()<<endl;
- cin>>reg;
- cin>>ime;
- Kamion B = A.pretovar(reg, ime);
- B.pecati();
- cout<<"Total mass: "<<B.vratiVkupnaMasa()<<endl;
- } catch (Exception &e) {
- e.showMessage();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement