// Code derived from Stroustrup's PPP2 book// § 9.5 Enumerations// -and beginning on p 318#include<iostream>#include<stdexcept>usingnamespacestd;voiderror(constchar*s){throwruntime_error(s);}enumclassMonth{jan=1,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec};enumclassDay{monday,tuesday,wednesday,thursday,friday,saturday,sunday};Monthint_to_month(intx){if(x<int(Month::jan)||int(Month::dec)<x)error("bad month");returnMonth{x};}voidf(intm){[[maybe_unused]]Monthmm=int_to_month(m);// ...}intmain()try{[[maybe_unused]]Monthm=Month::feb;// Month m2 = feb; // error: feb is not in scope// m = 7; // error: can’t assign an int to a Month// int n = m; // error: can’t assign a Month to an int[[maybe_unused]]Monthmm=Month(7);// convert int to Month (unchecked)// Month bad = 9999; // error: can’t convert an int to a Monthf(4);f(99);// run-time error: bad month}catch(exception&e){cerr<<"error: "<<e.what()<<'\n';return1;}catch(...){cerr<<"Oops: unknown exception!\n";return2;}