Return to Snippet

Revision: 35905
at November 16, 2010 19:12 by maradic


Updated Code
struct auti {
       double ser_br;
       char proizvodac [20];
       char model[20];
       int god_pro;
       };
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;
};

Revision: 35904
at November 15, 2010 05:08 by maradic


Initial Code
#include <iostream>
using namespace std;
#include "stog_pokazivaci.h"
//#include "stog_polje.h"
int kraj;
bool print;
void unosi(stog *Stog_marinac) {
elementtype dodaj;
int a;
cout<<"Koliko automobil zelite unesti?" <<endl;
cin >> a;


for (int i=0;i<a;i++){
    cout<<"Unesite serijski broj automobila: "<<endl;
    cin>>dodaj.ser_br;
    cout<<"Unesite proizvodaca automobila: "<<endl;
    cin>>dodaj.proizvodac;
    cout<<"Unesite model automobila: "<<endl;
    cin>>dodaj.model;
    
    
do{
   cout<<"Unesite godinu proizvodnje automobila: "<<endl;
   cin>>dodaj.god_pro;
   if (dodaj.god_pro < 1995 || dodaj.god_pro > 2010){
      cout << "Pogresan unos!" << endl;
      cout << "Godina (1995-2010)!" << endl;
      cout << "Ponovite unos!" << endl;}
  }while (dodaj.god_pro < 1995 || dodaj.god_pro > 2010);
cout << "Uspjesno unesen zapis" << endl;
PushS(dodaj, Stog_marinac);
}
}



void ispis1 (stog *Stog_marinac,stog *Stog_marinac_m){
     cout<<"--------"<<endl;
     while ( IsEmptyS(Stog_marinac)==0 ){
           if (TopS(Stog_marinac).god_pro>2006 && strcmp(TopS(Stog_marinac).proizvodac,"audi")){
                                
                                cout<<"Proizvodac  "<< TopS(Stog_marinac).proizvodac<<endl;
                                cout<<"Model  "<< TopS(Stog_marinac).model<<endl;
                                cout<<"Godina proizvodnje  "<< TopS(Stog_marinac).god_pro<<endl;
                                PopS(Stog_marinac); }
           else {
           PushS( TopS(Stog_marinac), Stog_marinac_m);
           PopS(Stog_marinac);
           }
           };
     cout << "---------"<<endl;
     cout << endl;
     cout << "Uspjesno" << endl;
     cout << endl;
     cout << "Preostali automobili"<< endl;
     cout << "--------------------"<<endl;
while ( IsEmptyS(Stog_marinac_m)==0 ){
      PushS( TopS(Stog_marinac_m), Stog_marinac);
      cout<<"Proizvodac: "<<TopS(Stog_marinac).proizvodac<<endl;
      cout<<"Model: "<<TopS(Stog_marinac).model<<endl;
      cout<<"Godina proizvodnje  "<<TopS(Stog_marinac).god_pro<<endl;
      PopS(Stog_marinac_m);
}
cout <<"----------------------------" << endl;
}
    

int ispis2(stog *Stog_marinac){
    elementtype dodaj;
    dodaj=TopS(Stog_marinac);
    if (!strcmp(dodaj.proizvodac,"audi")) {
    cout << "------------"<<endl;
    cout << "Iskrcaj automobila Audi " << endl;
    cout << "Model: " <<dodaj.model << endl;
    cout << "Godina proizvodnje: " <<dodaj.god_pro<<endl;
    cout<< "-------------" <<endl;}
    PopS(Stog_marinac);
     if (!IsEmptyS(Stog_marinac) || kraj) ispis2 (Stog_marinac);
        
     kraj = true;
     if (strcmp(dodaj.proizvodac,"audi")){
          PushS(dodaj, Stog_marinac);
               if (print==false){
               cout << endl;
               cout << "-Preostali automobili-"<< endl;
               cout << "------------------"<<endl;
               print=true;
               };
               cout << "Proizvodac  " << dodaj.proizvodac<<endl;
               cout << "Model automobila  " <<dodaj.model<<endl;  
               cout<< "Godina proizvodnje  " <<dodaj.god_pro << endl;
              
}
}
int main(){
int izbor;
stog *Stog_marinac, *Stog_marinac_m;
Stog_marinac=InitS();
Stog_marinac_m=InitS();
do{
cout << "---------IZBORNIK------" << endl;
cout << "1. Dodaj zapis automobila" << endl;
cout << "2. Ispis automobila koji nisu audi" << endl;
cout << "3. Ispis automobila marke audi" << endl;
cout << "9. izlaz "<<endl;
cout << "-----------------------" << endl;
cout << "Unesite izbor koji zelite: " << endl;
cin>>izbor;
cout << endl;
switch(izbor){
case 1: unosi(Stog_marinac);
                 break;
case 2: ispis1 (Stog_marinac,Stog_marinac_m);
                 break;
case 3: ispis2 (Stog_marinac);
                 break;
     }
}while (izbor !=9);
system("pause");
return 1;
}

Initial URL

                                

Initial Description

                                

Initial Title
biblioteka stog_polje.h

Initial Tags

                                

Initial Language
C++