Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class ImaMasa{
- public:
- virtual double VratiMasa()=0;
- virtual void pecati()=0;
- virtual ~ImaMasa() {
- }
- };
- class PaketPijalok:public ImaMasa{
- private:
- double volumenEden;
- int Kolicina;
- public:
- static double gustina;
- static double volumen;
- static double masa;
- PaketPijalok(){}
- PaketPijalok(double v, int k){
- volumenEden=v;
- Kolicina=k;
- }
- ~PaketPijalok(){}
- double VratiMasa()override{
- return gustina*volumen*masa;
- }
- void pecati()override
- {
- }
- int getKolicina(){
- return Kolicina;
- }
- };
- double PaketPijalok::gustina = 0.8;
- double PaketPijalok::masa = 0.2;
- double PaketPijalok::volumen = 1;
- class PaketSok: public ImaMasa{
- private:
- double volumenEden;
- int Kolicina;
- bool daliGaziran;
- public:
- PaketSok() {
- }
- PaketSok(int v, int k, bool g){
- volumenEden = v;
- Kolicina = k;
- daliGaziran = g;
- }
- double VratiMasa()override{
- return 0;
- }
- void pecati()override;
- };
- class PaketVino: public ImaMasa{
- private:
- double VolumenEden;
- int Kolicina;
- double procentAlkohol;
- public:
- PaketVino(int v, int k, double p) {
- VolumenEden = v;
- Kolicina = k;
- procentAlkohol = p;
- }
- double VratiMasa()override{
- return 0.9+procentAlkohol;
- }
- void pecati()override;
- double getProcentAlkohol() {
- return procentAlkohol;
- }
- };
- class Kamion{
- private:
- char* registracija;
- char* vozac;
- ImaMasa** elementi;
- int golemina=0;
- public:
- Kamion(){
- elementi = new ImaMasa*[1001];
- golemina = 0;
- }
- Kamion(char* r,char *v){
- elementi = new ImaMasa*[1001];
- vozac=new char[strlen(v)];
- strcpy(vozac,v);
- registracija=new char[strlen(r)];
- strcpy(registracija,r);
- try{
- if (strlen(registracija)!=8)
- {
- throw "Pogresno vnesena registracija!";
- }
- if(isalpha(registracija[0])&&isalpha(registracija[1])&&isalpha(registracija[6])&&isalpha(registracija[6])){
- }
- else{
- throw "Pogresno vnesena registracija!";
- }
- }
- catch(const char* c){
- cout<<c<<endl;
- }
- }
- void registriraj(char*){
- }
- void dodadiElement(ImaMasa* k){
- elementi[golemina] = k;
- golemina++;
- }
- double vratiVkupnaMasa() {
- double masa = 0;
- for(int i=0;i<golemina;i++){
- masa+= elementi[i]->VratiMasa();
- }
- return masa;
- }
- void pecati(){
- for(int i=0;i<golemina;i++){
- elementi[i]->pecati();
- }
- }
- Kamion pretovar(char* r, char*v ) {
- Kamion k(r,v);
- ImaMasa** niza = new ImaMasa*[1001];
- int maxx=0;
- for(int i=0;i<golemina;i++){
- if(maxx<elementi[i]->VratiMasa()){
- maxx=elementi[i]->VratiMasa();
- }
- }
- int golemina_2=0;
- for(int i=0;i<golemina;i++){
- if(maxx==elementi[i]->VratiMasa()){
- }
- else{
- niza[golemina_2] = elementi[i];
- golemina_2++;
- }
- }
- k.golemina=golemina_2;
- for(int i = 0; i < golemina_2; i++) {
- k.elementi[i] = niza[i];
- }
- return k;
- }
- };
- int main()
- {
- char ime[20], reg[9];
- double vol;
- int kol;
- bool g;
- double proc;
- 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<<"Vkupna masa: "<<A.vratiVkupnaMasa()<<endl;
- cin>>reg;
- cin>>ime;
- Kamion B = A.pretovar(reg, ime);
- B.pecati();
- cout<<"Vkupna masa: "<<B.vratiVkupnaMasa()<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement