//Készítette: Berezvai Dániel //Dátum: 2012.03.07. //EHA kód: BEDTACI.ELTE //e-mail: 3ice@3ice.hu //Csoport: 11.csoport //Feladat: 0.beadandó/9.feladat // Igaz-e, hogy mindig növekedtek az értékek? /* Includes.h */ #include #include #include #include #include #include /* menu.h */ void menu(std::vector &v); bool submenu(std::vector &v); bool ask_again(); /* fill_file.h */ namespace fill_file{ void fill_flat(std::string s, std::vector &v); void fill_formatted(std::string s, std::vector &v); } /* fill_keyboard.h */ namespace fill_keyboard{ void fill(std::vector &v); } /* read.h */ bool nat(int n); int read_int(const std::string &msg, const std::string &err, bool check(int)); double read_elem(int i, const std::string &err, bool check(int)); std::string read_str(const std::string &msg, const std::string &err, bool check(std::string)); /* increasing.h */ bool increasing(std::vector &v); /* output.h */ void output(bool result, std::vector &v); void output_v(std::vector &v); /* main.cpp */ using namespace std; int main(int argc, char *argv[]){ vector v; if(argc>1){ fill_file::fill_flat(argv[1],v); }else{ menu(v); } return 0; } /* menu.cpp */ bool c123(int n){return n==1 || n==2 || n==3;} bool c12(int n){return n==1 || n==2;} bool testcase(string s){ return s=="a1i" || s=="a1ii" || s=="a2" || s=="a3" || s=="a4" || s=="a5" || s=="a6" || s=="a7" || s=="a8" || s=="a9" || s=="a10" || s=="b1" || s=="b2" || s=="b3" || s=="b4" || s=="b5" || s=="d1" || s=="d2" || s=="d3" || s=="d4" || s=="d5" || s=="d6" || s=="d7" || s=="stress-test-false" || s=="stress-test-true" || s=="stress-test-1m-false" || s=="stress-test-1m-true"; } void menu(vector &v){ bool loop; do{ loop=true; cout<<"\n1 - Read from file\n"; cout<<"2 - Read from keyboard\n"; cout<<"3 - Exit\n"; int input=read_int("Choose: ","Valid choices are: 1, 2 or 3",c123); switch(input){//Read from file case 1:{ loop=submenu(v); break; } case 2:{//Read from keyboard fill_keyboard::fill(v); loop=ask_again(); break; } case 3:{//Exit loop=false; break; } default:{ loop=false; break; } } }while(loop); cout<<"Goodbye!"; } bool submenu(vector &v){ cout<<"\n1 - Read from formatted file\n"; cout<<"2 - Read from flat file\n"; cout<<"3 - Testcases\n"; cout<<"4 - Cancel reading from file\n"; int input=read_int("Choose: ","Valid choices are: 1, 2 or 3",c123); switch(input){ case 1:{//Read from formatted file fill_file::fill_formatted("formatted",v); return ask_again(); } case 2:{//Read from flat file fill_file::fill_flat("flat",v); return ask_again(); } case 3:{//Specify flat file name fill_file::fill_flat(read_str("Select testcase: ","Please enter a testcase! (a1i, a1ii, a2, a3, a4, a5, a6, a7, a8, a9, a10, b1, b2, b3, b4, b5, d1, d2, d3, d4, d5, d6, d7, stress-test-false, stress-test-true, stress-test-1m-false, or stress-test-true)",testcase),v); return ask_again(); } case 4:{//Cancel reading from file return true; } default:{ return false; } } } bool ask_again(){ cout<<"1 - Back to menu\n"; cout<<"2 - Quit\n"; int input=read_int("Again? ","Valid choices are: 1 or 2",c12); switch(input){ case 1:{//Back to menu return true; } case 2:{//Quit return false; } default:{ return false; } } } /* fill_file.cpp */ namespace fill_file{ void fill_flat(string s, vector &v){ stringstream ss; ss<<"input/"<>tmp; if(tmp!=""){ v.push_back(1); v[i]=atoi(tmp.c_str()); i++; } } bool result=increasing(v); output(result,v); } } void fill_formatted(string s, vector &v){ stringstream ss; ss<<"input/"<>n; v.resize(n); string tmp; for(int i=0;i>tmp; v[i]=atoi(tmp.c_str()); } bool result=increasing(v); output(result,v); } } } /* fill_keyboard */ namespace fill_keyboard{ bool all(int n){return true;/*The following statement gets rid of the "Unused parameter" warning:*/n=0/*(At no file size cost!)*/;} void fill(vector &v){ int n=read_int("\nNumber of elements: ","I require a natural number!",nat); v.resize(n); for(int i=0;i=0;}//natural int read_int(const string &msg, const string &err, bool check(int)){ int n; bool loop=false; string devnull; do{ cout<>n; loop=cin.fail() || !check(n); if(loop){ cout<>s; loop=cin.fail() || !check(s); if(loop){ cout<>r; loop=cin.fail() || !check(r); if(loop){ cout< &v){ int end=v.size(); for(int i=1;i=v[i]){ //cout<="< &v){ if(result){ cout<<"Yes, the entire series is monotonically increasing."; }else{ cout<<"No, the series is not monotonically increasing."; } output_v(v); } void output_v(vector &v){ cout<<" ( Your input was: "; cout<<"["; int end=v.size()-1; if(end<=10){ for(int i=0;i10){ for(int i=0;i<7;i++){ cout<=0){ cout<