Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <algorithm>
- #define _VEC(name,type,array) vector<type> name(array,array+sizeof(array)/sizeof(array[0]))
- #define _foreach(var,container) for(unsigned var=0;var<container.size();var++)
- using namespace std;
- //========================================================
- int ID = 0;
- //--------------------------------------------------------
- class itemInfo
- {
- public:
- unsigned marka,model,wlasciciel,data,kontakt,komentarz;
- itemInfo()
- {
- marka=model=wlasciciel=data=kontakt=komentarz=-1;
- }
- };
- class baseFramework
- {
- public:
- string marka, model, wlasciciel, data, kontakt,komentarz;
- int _ID;
- baseFramework()
- {
- marka=model=wlasciciel=data=kontakt=komentarz=" ";
- _ID = ID++;
- }
- itemInfo returnLen()
- {
- itemInfo ii;
- ii.marka=marka.size();
- ii.model=model.size();
- ii.wlasciciel=wlasciciel.size();
- ii.data==data.size();
- ii.kontakt==kontakt.size();
- ii.komentarz==komentarz.size();
- return ii;
- }
- };
- //--------------------------------------------------------------------------------
- static const string _cmdlist[] = {"/help","/edit","/add","/sort","/exit","/dump","/load"};
- _VEC(cmdlist,string,_cmdlist); //vec w cmdlist
- vector<baseFramework> database; //database
- itemInfo maxValues;
- //------------------------------------------------
- void parseInput(string &);
- void write(string);
- void exit();
- void help();
- void add();
- void _sort();
- void print();
- void edit();
- void dump();
- void load();
- bool idComparator(baseFramework,baseFramework);
- //==================================================================
- int main()
- {
- help();
- string n;
- for(;;)
- {
- getline(cin,n);
- parseInput(n);
- if(n=="/exit")break;
- }
- return 0;
- }
- //==================================================================
- void write(string in)
- {cout<<"> "<<in;}
- void help(){
- write("Dostepne komendy: \n");
- write("");
- _foreach(i,cmdlist)
- cout<<cmdlist[i]<<" ";
- cout<<endl;
- write("");
- }
- void add()
- {
- string in="";
- char choice;
- baseFramework bf;
- write("Podaj marke samochodu: ");
- getline(cin,in);
- bf.marka = in;
- write("Podaj model samochodu: ");
- getline(cin,in);
- bf.model = in;
- write("Podaj wlasciciela: ");
- getline(cin,in);
- bf.wlasciciel = in;
- write("Podaj date kradziezy: ");
- getline(cin,in);
- bf.data = in;
- write("Podaj kontakt do wlasciciela: ");
- getline(cin,in);
- bf.data = in;
- write("Dodatkowe komentarze: ");
- getline(cin,in);
- bf.komentarz = in;
- write("Chcesz dodac rekord na poczatku [B], koncu[E], czy na podanej pozycji[A]?");
- cin>>choice;
- if(choice == 'e' || choice == 'E')
- {
- database.push_back(bf);
- }
- else
- if(choice=='B'||choice=='b')
- {
- database.insert(database.begin(),bf);
- }
- else
- if(choice=='A'||choice=='a')
- {
- write("Podaj pozycje na jakiej chcesz umiescic rekord: ");
- int n;
- cin>>n;
- database.insert(database.begin()+n-1,bf);
- }
- itemInfo ii;
- ii = bf.returnLen();
- maxValues.data = max(maxValues.data,ii.data);
- maxValues.model = max(maxValues.model,ii.model);
- maxValues.marka = max(maxValues.marka,ii.marka);
- maxValues.wlasciciel = max(maxValues.wlasciciel,ii.wlasciciel);
- maxValues.kontakt = max(maxValues.kontakt,ii.kontakt);
- maxValues.komentarz = max(maxValues.komentarz,ii.komentarz);
- }
- void _sort()
- {
- write("Wedlug ktorej tabeli chcesz posortowac baze danych?\n");
- write("__________________________________________________________________\n");
- write("| Marka | Model | Data | Wlasciciel | Kontakt | Komentarz | ID |\n");
- write("| 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n");
- write("");
- int n;
- cin>>n;
- switch(n)
- {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- sort(database.begin(),database.end(),&idComparator);
- break;
- }
- write("Podaj spoosob sortowania bazy danych: a-z [AZ] | z-a [ZA]: ");
- string tmp;
- cin>>tmp;
- if(tmp=="AZ"||tmp=="az")
- write("Gotowe!\n");
- else if(tmp=="ZA"||tmp=="za")
- {
- reverse(database.begin(),database.end());
- write("Gotowe!\n");
- }
- else write("Baza danych zostala posortowana domyslnie [a-z]\n");
- }
- void print()
- {
- }
- void dump()
- {
- }
- void load()
- {
- }
- void exit()
- {
- dump();
- write("Dziekuje za prace");
- }
- void edit()
- {
- write("Czy chcesz wyswietlic baze? [t/n] \n");
- write("");
- char choice;
- if(choice == 't')
- print();
- write("Podaj ID wpisu, ktory chcesz edytowac: ");
- int n;
- cin>>n;
- }
- bool idComparator(baseFramework left, baseFramework right)
- {
- return left._ID>right._ID;
- }
- void parseInput(string &in){
- (in=="/exit"?exit():(in=="/help"?help():(in=="/add"?add():(in=="/sort"?_sort():(in=="/print"?print():(in=="/dump"?dump():(in=="/load"?load():(in=="/edit"?edit():write("Unknown command!\n"))))))))); //not complete
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement