//Alex Tuddenham - Vector Sort.//plan: //I want to get()a char. for each loop. //I want to then insert char into vector. //I want to then sort vector. //then i want to pop out from the vector until vector is empty/ all integers. //printing to Cout.
#include <cmath>#include <cstdio>#include <vector>#include <iostream>#include <algorithm>#include <stdexcept>
using namespace std;
int N;int number_in; int main() { cin >> N; // reads input of integer number - N try{ if ((N>10000)|(N<1)){throw out_of_range("input range exceeded");} //checking range parameters if((N%1) != 0 ){throw invalid_argument("non-integer detected");} //checking input integer number is an int and not a float. if(cin.fail()){throw runtime_error("read in failed, check input");} } catch(out_of_range &oorarg) {cout<<oorarg.what();} //reporting out of range via output catch(invalid_argument &iearg){cout<< iearg.what();} //reporting and handling if non-integer detected catch(runtime_error &re){cout << re.what();} //runtime error reading Cin to int N catch(...) { cout<<"Unknown error detected"; // generic error handling. } vector<int>v; // Creates vector of integers of 0 size.vector while(cin>>number_in){ v.push_back(number_in); } //reads each number into vector and push_back dynamically resizes vector as more integers added. try{ for(int i =0; i>N;i++){ if((v[i]>100000000)|(v[i]<1)){throw out_of_range("Vector range exceeded");} //checks that vector values are not outside of constraints if((v[i]%1) != 0 ){throw invalid_argument("non-integer detected");}} //checks that values are still integers when placed in vector } catch(out_of_range &oorarg){cout<<oorarg.what();} catch(invalid_argument &iearg){cout<< iearg.what();} catch(...){cout<<"Unknown Exception";} sort(v.begin(),v.end()); // sort the vector from front to end via size. try { if (v.back()<v.front()) {throw runtime_error("sort operation failed!");} } //error thrown if sort function has not placed largest at back of vector. catch (runtime_error &rtarg) {cout<<rtarg.what();} catch(...){cout<<"Unknown Exception";} for(int i=0; i<N;i++){ cout<<v[i]<< " "; } // outputs the vector, space deliminated return 0;}