Skip to content

Instantly share code, notes, and snippets.

@mojombo
Created July 17, 2008 20:37
Show Gist options
  • Save mojombo/15 to your computer and use it in GitHub Desktop.
Save mojombo/15 to your computer and use it in GitHub Desktop.

Revisions

  1. ivahorvat revised this gist Nov 14, 2010. 4 changed files with 242 additions and 28 deletions.
    126 changes: 126 additions & 0 deletions Glavni program
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,126 @@
    #include <iostream>
    using namespace std;

    #include "stog_pokazivaci.h"
    //#include "stog_polje.h"

    int kraj_rek;
    bool print;


    void unosi(stog *Stog_m) {
    elementtype dod;
    int n;

    cout<<"Koliko automobil zelite unesti?" <<endl;
    cin >> n;
    for (int i=0;i<n;i++){
    cout<<"Unesite serijski broj automobila: "<<endl;
    cin>>dod.serijski_broj;
    cout<<"Unesite proizvodaca automobila: "<<endl;
    cin>>dod.proizvodac;
    cout<<"Unesite model automobila: "<<endl;
    cin>>dod.model_automobila;
    do{
    cout<<"Unesite godinu proizvodnje automobila: "<<endl;
    cin>>dod.godina_proizvodnje;
    if (dod.godina_proizvodnje < 1995 || dod.godina_proizvodnje > 2010){
    cout << "Pogresan unos!" << endl;
    cout << "Godina mora biti u rasponu 1995-2010!" << endl;
    cout << "Molim vas ponovite!" << endl;}
    } while (dod.godina_proizvodnje < 1995 || dod.godina_proizvodnje > 2010);
    cout << "~~~~~~Uneseni automobil uspjesno je spremljen u skladiste!!~~~~~~" << endl;
    PushS(dod, Stog_m);
    }
    }



    void ispis1 (stog *Stog_m,stog *Stog_m_mov){
    cout << "--------------------Iskrcaj automobila--------------------"<<endl;
    cout << "----------------------------------------------------------"<< endl;
    cout << "Proizvodac" << "\t" << "Model automobila" << "\t" << "Godina proizvodnje" << "\t" << endl;
    cout <<"----------" << "\t" << "----------------" << "\t" << "------------------" << "\t" << endl;
    while ( IsEmptyS(Stog_m)==0 ){
    if (TopS(Stog_m).godina_proizvodnje>2006 && strcmp(TopS(Stog_m).proizvodac,"audi")){

    cout<< TopS(Stog_m).proizvodac<<"\t\t"<<TopS(Stog_m).model_automobila<<"\t\t\t"<<TopS(Stog_m).godina_proizvodnje<<"\t\t"<<endl;
    PopS(Stog_m); }
    else {
    PushS( TopS(Stog_m), Stog_m_mov);
    PopS(Stog_m);
    }
    };
    cout << "----------------------------------------------------------"<<endl;
    cout << endl;
    cout << "Automobili su uspjesno iskrcani!!" << endl;
    cout << endl;
    cout << endl;
    cout << "-------------------Preostali automobili-------------------"<< endl;
    cout << "----------------------------------------------------------"<<endl;
    cout << "Proizvodac" << "\t" << "Model automobila" << "\t" << "Godina proizvodnje" << "\t" << endl;
    cout <<"----------" << "\t" << "----------------" << "\t" << "------------------" << "\t" << endl;
    while ( IsEmptyS(Stog_m_mov)==0 ){
    PushS( TopS(Stog_m_mov), Stog_m);
    cout<<TopS(Stog_m).proizvodac<<"\t\t"<<TopS(Stog_m).model_automobila<<"\t\t\t"<<TopS(Stog_m).godina_proizvodnje<<"\t\t "<<endl;
    PopS(Stog_m_mov);
    }
    cout <<"----------------------------------------------------------" << endl;
    }


    int ispis2(stog *Stog_m){
    elementtype dod;
    dod=TopS(Stog_m);
    if (!strcmp(dod.proizvodac,"audi")) {
    cout << "-----------------------------------"<<endl;
    cout << "Iskrcaj automobila marke Audi: " << endl;
    cout << "Model: " <<dod.model_automobila << endl;
    cout << "Godina proizvodnje: " <<dod.godina_proizvodnje<<endl;
    cout<< "-----------------------------------" <<endl;}
    PopS(Stog_m);
    if (!IsEmptyS(Stog_m) || kraj_rek) ispis2 (Stog_m);

    kraj_rek = true;
    if (strcmp(dod.proizvodac,"audi")){
    PushS(dod, Stog_m);
    if (print==false){
    cout << endl;
    cout << "-------------------Preostali automobili-------------------"<< endl;
    cout << "----------------------------------------------------------"<<endl;
    cout << "Proizvodac" << "\t" << "Model automobila" << "\t" << "Godina proizvodnje" << "\t" << endl;
    print=true;
    };
    cout<<dod.proizvodac<<"\t\t"<<dod.model_automobila<<"\t\t\t"<<dod.godina_proizvodnje<<endl;
    }
    }
    int main(){
    int izbor;
    stog *Stog_m, *Stog_m_mov;
    Stog_m=InitS();
    Stog_m_mov=InitS();


    do{
    cout << "-------------------------------------------------" << endl;
    cout << "1. Dodavanje zapisa o automobilima" << endl;
    cout << "2. Ispis automobila marke!=Audi" << endl;
    cout << "3. Ispis automobila marke==Audi (rekruzije)" << endl;
    cout << "9. izlaz "<<endl;
    cout << "-------------------------------------------------" << endl;
    cout << "Vas izbor je: " << endl;
    cin>>izbor;
    cout << endl;

    switch(izbor){
    case 1: unosi(Stog_m);
    break;
    case 2: ispis1 (Stog_m,Stog_m_mov);
    break;
    case 3: ispis2 (Stog_m);
    break;
    }
    }while (izbor !=9);
    system("pause");
    return 1;
    }
    54 changes: 54 additions & 0 deletions Stog_pokazivac.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    struct auti {
    double serijski_broj;
    char proizvodac [20];
    char model_automobila[20];
    int godina_proizvodnje;
    };
    typedef auti elementtype;

    struct smth {
    elementtype vrijednosti[5000];
    int vrh;
    };

    typedef struct smth stog;


    void PushS(elementtype z, stog *L){
    if(L->vrh==-1){
    cout<<"Doslo je do pogreske!! Stog je pun!!"<<endl;
    exit(1);
    };
    L->vrijednosti[L->vrh]=z;
    L->vrh--;
    };

    elementtype TopS(stog *L){
    if(L->vrh==4999){
    cout<<"Doslo je do pogreske!! Stog je prazan!!"<<endl;
    exit(1);
    }
    return L->vrijednosti[L->vrh+1];
    };

    int IsEmptyS(stog *L){
    if(L->vrh==4999) return 1;
    else return 0;
    };


    void PopS(stog *L){
    if(L->vrh==4999){
    cout<<"Doslo je do pogreske!! Stog je prazan!!"<<endl;
    exit(1);
    };
    L->vrh++;
    };


    stog * InitS(void){
    stog *L;
    L=(stog *)malloc(sizeof(stog));
    L->vrh=4999;
    return L;
    };
    62 changes: 62 additions & 0 deletions Stog_polje.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    struct auti {
    double serijski_broj;
    char proizvodac [30];
    char model_automobila[30];
    int godina_proizvodnje;
    };
    typedef auti elementtype;

    struct smth{
    elementtype vrijednost;
    struct smth *slijedeci;
    };

    typedef struct smth stog;


    void PushS(elementtype z, stog *L){
    stog *novi;
    novi=(stog *)malloc(sizeof(stog));
    novi->vrijednost=z;
    novi->slijedeci=L->slijedeci;
    L->slijedeci=novi;
    };


    elementtype TopS(stog *L){
    stog *vrh;
    if(L->slijedeci==NULL){
    cout<<"Doslo je do pogreske!! Stog je prazan!!"<<endl;
    exit(1);
    };
    vrh=L->slijedeci;
    return vrh->vrijednost;
    };



    void PopS(stog *L){
    stog *pri;
    if(L->slijedeci==NULL){
    cout<<"Doslo je do pogreske!! Stog je prazan"<<endl;
    exit(1);
    };
    pri=L->slijedeci;
    L->slijedeci=pri->slijedeci;
    free(pri);
    };


    int IsEmptyS(stog *L){
    if(L->slijedeci==NULL) return 1;
    else return 0;
    };


    stog * InitS(void){
    stog *L;
    L=(stog *)malloc(sizeof(stog));
    // L->vrijednost=0;
    L->slijedeci=NULL;
    return L;
    };
    28 changes: 0 additions & 28 deletions bypass.rb
    Original file line number Diff line number Diff line change
    @@ -1,28 +0,0 @@
    # This allows you to be a good OOP citizen and honor encapsulation, but
    # still make calls to private methods (for testing) by doing
    #
    # obj.bypass.private_thingie(arg1, arg2)
    #
    # Which is easier on the eye than
    #
    # obj.send(:private_thingie, arg1, arg2)
    #
    class Object
    class Bypass
    instance_methods.each do |m|
    undef_method m unless m =~ /^__/
    end

    def initialize(ref)
    @ref = ref
    end

    def method_missing(sym, *args)
    @ref.__send__(sym, *args)
    end
    end

    def bypass
    Bypass.new(self)
    end
    end
  2. mojombo created this gist Jul 17, 2008.
    28 changes: 28 additions & 0 deletions bypass.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # This allows you to be a good OOP citizen and honor encapsulation, but
    # still make calls to private methods (for testing) by doing
    #
    # obj.bypass.private_thingie(arg1, arg2)
    #
    # Which is easier on the eye than
    #
    # obj.send(:private_thingie, arg1, arg2)
    #
    class Object
    class Bypass
    instance_methods.each do |m|
    undef_method m unless m =~ /^__/
    end

    def initialize(ref)
    @ref = ref
    end

    def method_missing(sym, *args)
    @ref.__send__(sym, *args)
    end
    end

    def bypass
    Bypass.new(self)
    end
    end