CSCE 2100: Computing Foundations 1 Intro to Advanced C++ Ian Parberry Summer 2013
Some Advanced C++ Topics Templates Example: Templated stack Operator overloading Example: Complex numbers Copy constructors Example: Multidimensional vectors More examples CImageFileNameList Arbitrary precision integers
Templates
What We Can Do Already: A Stack of ints class StackClass{ private: int *value; //data in stack int count; //number of elements int size; //maximum number of elements allowed public: StackClass(int s); //constructor StackClass(); //destructor void reset(); //clear the stack void push(int v); //push v onto stack int pop(); //delete and return top }; //StackClass
Stack of ints StackClass::StackClass(int s){ value = new int[s]; size = s; count = 0; } //constructor StackClass::~StackClass(){ delete [] value; } //destructor void StackClass::reset(){ count = 0; } //reset
Stack of ints void StackClass::push(int v){ if(count < size) value[count++] = v; } //push int StackClass::pop(){ if(count > 0) return(value[--count]); else return 0; } //pop
Multiple Types of Stack But what if I also want a stack of floats, or a stack of strings? Do I really want to make three different stack classes? Tedious to build, difficult to maintain. All we want to do is change the red ints. Answer: Templates.
Stack of <stackelement>s template <class stackelement> class StackClass{ private: stackelement *value; //data in stack int count; //number of elements int size; //maximum number of elements allowed public: StackClass(int s); //constructor StackClass(); //destructor void reset(); //clear the stack void push(stackelement v); //push v onto stack stackelement pop(); //delete & return top }; //StackClass
Stack of <stackelement>s template<class stackelement> StackClass<stackelement>::StackClass(int s){ value = new stackelement[s]; size = s; count = 0; } //constructor template<class stackelement> StackClass<stackelement>::StackClass::~StackClass(){ delete [] value; } //destructor template<class stackelement> void StackClass<stackelement>::reset(){ count = 0; } //reset
Stack of <stackelement>s template<class stackelement> void StackClass<stackelement>::push(stackelement v){ if(count<size) value[count++] = v; } //push template<class stackelement> stackelement StackClass<stackelement>::pop(){ if(count>0) return(value[--count]); else return 0; } //pop
Declaration of Templated Stack const int STACKSIZE = 42; StackClass<double> stack0(STACKSIZE); StackClass<float> stack1(STACKSIZE); StackClass<int> stack2(STACKSIZE); StackClass<char> stack3(STACKSIZE); class longint{ //my own long integer class … }; StackClass<longint> stack4(STACKSIZE);
Operator Overloading
Operator Overloading C++ gives you the power to define operators such as * and + on your own classes. This is called operator overloading. class complex{ //complex number private: double imaginary, real; public: complex(double r=0.0, double i=0.0); friend complex operator+(complex, complex); friend complex& operator+=(complex&, complex); friend ostream& operator<<(ostream&,complex x); }; //complex
Complex Numbers complex::complex(double r, double i){ imaginary = i; real = r; } //constructor complex operator+(complex first, complex second){ return complex(first.real + second.real, first.imaginary + second.imaginary); } //overloaded +
Complex Numbers complex& operator+=(complex& x, complex y){ x.imaginary += y.imaginary; x.real += y.real; return x; } //overloaded += ostream& operator<<(ostream& output_stream, complex x){ output_stream << "(" << x.real << "," << x.imaginary << ")"; return output_stream; } //overloaded output
Complex Numbers int main(){ complex a(1,2), b(3,4), c; c = a + b; cout << c; //outputs (4,6) c += a; cout << c; //outputs (5,8) return 0; } //main
Copy Constructors
A Vector Class New New Not just friends any more. const int VECSIZE = 4; //vector dimension class vector{ private: int *data; public: vector(); //constructor ~vector(); //destructor vector(vector&); //copy constructor friend ostream& operator<<(ostream&, vector); friend istream& operator>>(istream&, vector&); vector operator=(const vector&); vector operator+=(vector); friend vector operator+(vector, vector); }; //vector New New Not just friends any more.
Vector Constructor and Destructor vector::vector(){ //constructor data = new int[VECSIZE]; for(int i=0; i<VECSIZE; i++) data[i] = 0; } //constructor vector::~vector(){ //destructor delete [] data; } //destructor
Remember This?
Remember This?
Remember This?
Copy Constructor for Vectors vector::vector(vector& v){ data = new int[VECSIZE]; for(int i=0; i<VECSIZE; i++) data[i] = v.data[i]; } //copy constructor
Overloaded Assignment for Vectors vector vector::operator=(const vector& v){ if(this != &v) for(int i=0; i<VECSIZE; i++) data[i] = v.data[i]; return *this; } //operator=
Overloaded Addition for Vectors vector operator+(vector x, vector y){ //addition vector result=x; result += y; return result; } // operator+ vector vector::operator+=(vector v){ //overloaded += for(int i=0; i<VECSIZE; i++) data[i] += v.data[i]; return *this; } //operator+=
Overloaded I/O for Vectors ostream& operator<<(ostream& output_stream, vector v){ output_stream<<'('; for(int i=0; i<VECSIZE-1; i++) output_stream << v.data[i] << ','; output_stream << v.data[VECSIZE-1] << ')'; return output_stream; } //overloaded output istream& operator>>(istream& input_stream, vector &v){ for(int i=0; i<VECSIZE; i++) input_stream>>v.data[i]; return input_stream; } //overloaded input
How to Use Our Vector Class int main(){ vector a, b, c; cout << "> "; cin >> a; //overloaded input cin >> b; //overloaded input c = a + b; //overloaded operator+ cout << "a+b= " << c << endl; //overloaded output return 0; } //main
More Examples
CImageFileNameList class CImageFileNameList{ private: char** m_lplpImageFileName; int m_nImageFileCount; public: CImageFileNameList(void); ~CImageFileNameList(void); void GetImageFileNames(); char* operator[](const int); }; //CImageFileNameList
CImageFileNameList CImageFileNameList::CImageFileNameList(void){ m_lplpImageFileName = NULL; m_nImageFileCount = 0; } //constructor CImageFileNameList::~CImageFileNameList(void){ for(int i=0; i<m_nImageFileCount; i++) delete [] m_lplpImageFileName[i]; delete [] m_lplpImageFileName; } //destructor
CImageFileNameList //safe index into name list char* CImageFileNameList::operator[](const int ix){ if(ix >= 0 && ix < m_nImageFileCount) return m_lplpImageFileName[ix]; else return "NotAValidFileName.bmp"; } //operator[]
Long Integers Note multiple constructors class longint{ //long integer class private: unsigned int* data; unsigned int size; void loadstring(const char* string); void reallocate(int s); void grow(int s); public: longint(); //constructor longint(unsigned int); //constructor longint(char*); //constructor longint(const longint&); //copy constructor ~longint(); //destructor Note multiple constructors
Long Integers Note multiple assignment ops friend ostream& operator<<(ostream&, longint); friend istream& operator>>(istream&, longint&); longint& operator=(const longint&); longint& operator=(const int); longint& operator=(const char*); longint& operator+=(const longint&); friend longint operator+(longint, longint); }; //longint Note multiple assignment ops
Long Integers //overloaded assignment operators longint& longint::operator=(const longint& l){ if(this != &l){ //protect against self assignment reallocate(l.size); //grab enough space for(int i=0; i<size; i++) data[i] = l.data[i]; } return *this; longint& longint::operator=(const int i){ reallocate(1); *data = i;
Long Integers longint& longint::operator=(const char* string){ int digitcount = strlen(string); int s = digitcount/HalfBytesInWord + (digitcount%HalfBytesInWord>0?1:0); reallocate(s); loadstring(string); return *this; }
Using the Long Integer Class The Windows calculator can’t calculate 52! without resorting to scientific notation.
TexCalc, the Texas Sized Calculator Just for fun, I decided to code a calculator that can handle not just long integers, but loooooo-ooooooong integers.
TexCalc, the Texas Sized Calculator
Computes 52! Without Scientific Notation
They Get Approximately the Same Answer
52! is a 226-bit Number
That’s 44 Digits in Texadecimal
It Can Handle 256! (507 Digits)
It Can Handle 8,192! (28,504 Digits)
1275885799409419815176389340348054196668320439883274267104984309726364695366800625932789430266971962258096637731548083886134457833955792825263151020621499199077785797150012740951006035996069516686653916832686149064081447562067844912699042004605583859910583296526857941105757626504018649128339148781194823339323446481117083293322698067026547918281513676316849030469366358516642559454823133638035539339277605039058137318445884778383248100692858253951525535431177679794667731674606463624871887231518684464404163970971822558414524607892908917116740084380573995913114165073622734448672756630909954470045527006362682704457726927914042831632473785205962326314270800197350057192072334860166813211090642759139657591123513053633013019050874806782142381066122687154337628678149950053517612361297235626360023284985722765105881216269396733199978279401874340290393832923077840258405285186298086705099172100948409667749101426181244416493079764363660288272168346175441618616005764029300263591697625406763232697474120529751695729845039729330986795021901008610499702709097286855283354040157412549946699213963009684426437638063843671173964064453506427617835442591534065707280238153034608846152432785637962403671827103046196652042993193432863214212046900463123364149990958121529989325494510937123730152385394566187426663925032019240432575556330272120749361174991009878433340108948845583731878654485743324488564205907342954461828360174792926088732523607096331481587717276243952653325670766880860376325605394934631702583689889298289632246956207188299180026358280791537116503257969307596835068383742502738885110518288023514971014952953529865638670726527121857717773860139632192808259958953493423527284720471908058039732584338769964819223011274606781443793493806295410084755965525439086191006966680177530836503541792126399947271806778069228704182873969940137774678399889522367823868576645180941564558843594941606523143512392053694980245972735226404463109362064378058180630075266282546876280288995362948272594918640726761103356690354332123112342122545716957845546277875280787209352089821284105860046258900695917762086843633199396098073134480894627159408367507414210652796123336800012835121898867454955375941849880533111669667533217036539544685862755353211147942498666163403857801049340898797330480979426586412089701562593749490294276579228545975622966397277107045538578932452115408916267681453558043967127592741958652387982752857712992457251201099705937548295650520733236810082144492570986848058212578409746285245558613896567620752493771105755934176551914234311892713667283474402716479922415958362475766742616388549432880923529509722513341689697661606806469217988792828784302769889314351196039349699000532987431736124056426740257346795358047033837608091410427091156598776350774291226047522300885259712919555028760765200980874705442321342226017792464887597921764077377691605309332580483763766246856480064951575914843201323820088963367368175936286732294067743124961245327527247781824438638187611811053775025668262176029484627870928565020205450518688930967635850951132279320717541123033033217686059400127385870296857911639330087028468583913588797975224982043375639049209672787228013178897226042944975375567897222548172127100560479411246606471250470353411140011724318254899998025924647837316037002389173809581539143187223553639155626981362433079641765334091620821230847880504255869962286944370662849519620704423145946798150245837561073226635725301472938875508172214109724625507317567070804136636523185136177695016562383925595189806768844523889734008247243713848027604020385682660055174622081716282538204123374967124087991619808212209058723771457658476744916129120442153246407596777055329433175145533609497882202505601248934317533823008666974842077080634037898339059987633363867160912042186188908689444206698359084944721103131532441479849119427426297305968254064898116538064026592939424627446551311318129721671355625633306509290146158899233351448044420564898837053074774241602546975932912398477513830822011730904563518812762155683893500484347183801572610530419993067609988479433017161115148500750095460223885652961609645800119587337293917531057500133790042303738019283922444944634016971767072860681179498912823019491272093249033713380673492981421257011537831440170010155872576097625220285532134916984496471390045939744412194652330779655728280706965515032865961004675100799160318457277535853430545639844888398194947821751266954767459349068848002438845694135943881686740888547644634531161360051492168605712736387476728687164663015101644534534512097826151150130544924145497294562570285055676215864470126564072011885686076723618348574942888777441403423638197979389038571998001686921640628579912908795530607419979967977632636736810637187603580265637771157889987188931679121803962343282382976278180598631717056126524024673915991516442616765486290324168760579945377706014881772561412146206100899417568423191857167648943162040849927816706172378353514104118238044463530513017738830265847294040674017127237437449891785105199058047587711589411420962750083127681768057078670805025629319178970228089157751646515776909079841904111955896055590520804044689823344929130065299117107704173606524226381916799070677205628423085667667705505734407277329272136948611244172316421499890431696839045830010375498847237717756014662324863794633756698770086226366252217131090390171001698565924598611292869807850745167323520199614049453696610113882772575158176706782826456479188852647195070769652216300639603786869493708106206265310804917519626692780564897794361575663673807543412579779818669603335491125766871242423103855722071245498401511565469426353755360199472581508034278697015549821769533123979018971471313906782143250182634405754257952919547417646875508060219037372835441406282985483322599115842097638572085584649342132013965128695194247321269717614767917967096309657431697338164513961049570790993256751838349201349990143235099755347297630846747868811551084465676756787319134600969294725611512881722220381163321131348371389583484263707529779469777538338879489955134798643965920898468221165349637080419074019753767684497116305040153375368936074004080786072447875453978755726301817095569631504620935975188994639046054862103725592650290359402406618440074047041613997734172598002849118065516494070541486656852964600802805551488236373071165786195470615392312388895894959588843131078058836675093616982031867287827601664602617450241943588033248201014834317630433027951508555841899360815566242550211746915328839070780432789249027888906151757030431832018284654619562117397563667825396395225297639428643890998808945230423709862984623795819392146398023996552833817308646070464332608480885415039991468671435142470709237232500629705952432780271472325046016960643475747756291625284881238963850469126244739978789937516768209981508781422507759668328452735827588142734300273725376435238667532489930299149561851705893594169237757047448510521613136064951104453175037290439169718059659752226340729291232069942238176119417030878990173905794965194125186268882361242077938319567879789550227745834101616076477015895509726974713117918225963922060982975968284530089484585468977970278131558963691156308646881742357924256083271995441109822475146727883638558308579402969315054142813596553831822039378990401809299703725917775527973235663231707895686629473659771109813926178904452180393307918338989009013615487330810903098306538025364739320816017733066961509886288558989076509471829555786069822941502748701351451376049784036255279254639460489687884920552455246057158802704201124674260964360925536056912100072064599386856601630481476368426183743833269880225681056640539099315760808184070816901153399579477279292377901882589594406671022219033755762674453916395059623897867278155816099793782345249385270982133564357803353216071872364541146155918040066241561580407139590535462218741000322228381181701578604660530714490454538095473768445341932389116307273622400674780226502367308332018237611982098070885034522931492962280965270529755804249287861905417806429019917008771545656705309410452801543394320934647328372901214752520951460877341593196578671327175477041689948696136781749710013053275154044660632522628089306504094218350071195286108570658713999549372771865721933302234255248057465741686467112328363437134069539641415782590309464623636956814456674003056761473626140440103509875055302677497987690268706618760755848596291074878092587383954456277883568359603310991825589665205931351879930817832491167144075352771427025277651516029942458628118850114296388843497421506015923622541248877138198797396552789380154871041759860278205166763705936618536904708363033799032652872666460187239763674514688223593383878101647655324444764532177055452366509520945546757547351281973660069120483345249094816349543368992616740911769149819299528905193908338726382654706787638711251893119756422060500317331232844998449024592925628035961575607857795646109606784876305007545753462607697121712479191710665691650630402104267973795844385417520054343344973750542767562402432422023387122826195897460998314569939096619909376612437332022273795751366334446785785649844174521740797420747384589963657378383539770856215696532008978023299286892786709819732025154994598156688899616926478813140884127250139499788082763256777895874453911899264208627098016186851025554589918812060841385865735467434495301274794168785903037734637677782596030322160296999859331939517153718647745064033121346598314242964493708509402289159803878543229458122072814500045017527685746851393875852173525171862429341468536435483823052975748703123264329170875225878775170528700953725128334441443911639397522689179222729223845574217923992484832433017515913123661362661823725582800487181126362210796548865684394840196440825978767630228532931448522226456316676414363245043246273959892478142972178197232890560670736227501832494405283826272851035504236956824903897920150156167894049803753085413045353277103334774146452024383813736096175847765925614653732869993368614818736555043415061457343012428741489268560858491065407984811337034572760952748880368243816875137045638487065436195626391614802194921508344858440191740558702057534525685993306014179349589530160235578073308122181584997397558349794186609326565418846317167178752342513640799680255725231942182084216984413044051617066361548510089499443460999091991795183575860654670411107867872957166149535648767921629265081045023330780532853313936682286551201161349568682113952206620466250339390593966316740523652372507528975839226570397381569597238738159867264733801433063890773344439976065630712443629389711761396815297849454155865675840119382331602572136843970642179510340627752557346394246558685924881787296592190772243883764054855579096784597050238568643819143029430317519140455742014231605706112810190553697170848330898443329622712050685149000785515787965688908410394086750487194623479292436599248709628554126373609459095750042138194732981970646088806247952345860357915852431314453598194676409105219811579988394926525319346186140635396725596004826668542810216913742754669490405000268571941196465328595521005442734930924674225697329792885159230038405653780187251222870353399835252324568803317722925303038233241161217558412470154411686518259491030314054034294749315907587085560985966605168272440016513242159641248134698193441621418334772426117959249094406900037774355080869069633855950343403477365082695227669204659547597053283883312073243352215949375757191834365944216898370268352009211624295845001387998966326749301768808477100031379156934704899606160673484619498145670440103015196463119768713407535452061521565403321072083206457016926118625677512587705974001660189449380114344182675268110432838385498052420144700629711646596581576582618408582431084001259174315350836428831111948426606388439832841675601612864695141746484152719160478563633895492713183175787855814405045628013762387204515917417572804137589429741392316371799128181869701606041831834200372052822322978876373058092710652041965258548092966266235607498669691066925841905981270043345053175671021265125306077002725318493086268572318999038104954101082909547800539456243710135080350875848736603413718154409511958055031059488388530779451132065425685521154063502318302958261682979026103956782462705120635438029347859034406079897036511629623480192795040945293217330788118723808000212868816751337554300910972233185901799621529359700182027703014503054063143975748214795743989832891242731651219987182274616948423483014633445324570807603876473310555926253909827941063541655190059417481610050109561527299708062068758922420648085570562569096078357675381550173352588842462100236659296968610458825720876004543550404855018806336841577685446850725880633808997090055603296193428864575643027529698515900449213828178271076807124864263186931906148404297455714216271823802251631458300920343908143625736739701852367423233984729408495779006479699252291829794241795312745984739070330718613831890537151567497011212025556094850660745164580021644334202854961474355335029762115434587446587195483196187457681204817985188709190315756838744470098254965356680388029625697448251642512377523691345729942878891683189259790500459241602955472692868645194091644968377804090056724182393874253814526698622713957826222318130255151917588678276738366531160358161873244409482554725046472486383817309941244504080519685063259345235697994770980835311187911765988431377137442088988277089934114458983604582551947129598755207647883963761543298308824835383002877396443676121794657229639825761052771836294016563441393059706761714690911459093464864559075651221899447340830513624313806605651859629745808975720402473968038738857187289043997387862968613010894915530786149966566559776411675652026419578372509255032368700756593443541331028640558514962596402617876208408793571702003182962028035079780211812953417884556959277479813906663873036252023368108724559922233255456530017810787992749254106350552489471045833883969598470371117693469625945997848069037947482648977258043359663704903294665785792269936514962753009485640631673302100427218635500259293291607391034460239309292583775672702699025074145030717901333759545238159246294634657629073713771881857119374772217590415684363545278035485442562350862319933726536560664225368860023990302008291524449059582469796655159763283523564827990638116564582587695960461715711969579089384919447721469433259990257298270339206516390195551263194391393462363454302502284150481760103575321226851963706949231959944507673346072283077112941531831360163568592707745798020211304892816321550611528917050709952113155562805248263403674556878563809992709627289586464167003224929307238955060889415607729741281463786549766145644788820571348184267444543050024513521464948445766881922503705957350921309406724594393309843928821895486559956621191965696838181200332649054754575946641826293503081662856442592096763228930157681633272720627371912867816501323599273764463933721275822221124292231567356297730740477189901565949830867379002923747837020659415372128697842928394350373073564159424105901003973313946817034035577215333015656511341466717864407510823023200951601633612759724112051217796986595495697729850202995561304989286063087533015420538111656218759248470481588416661002685369568886920144467453809525747437640979275215419421392485458850988155475452123873216748490175512115659001185984705726707841033148113845170273410729846639092260738374778811349211599705372401168479557851911126656048600211761962313842644037879419903138931207533419600810928391061547638242363212016800519721803578551298466800984828291325259518859235251968677432970397847169282840825938551675222800777509174630393707017465989667475020561945043545589427164804502670925233883503760478112510502693535023226118101137094282035159588288197436944818636494022244395070153371027882423869549194054176789086719940333490776317052862604951005336184719363494110147880245421041806226821889817410164445834355932544019653661520618438067333206068711148797049977505474329879511112681006788831288305550217818033563537844770727044029691879574678872570665782486035527240272278640697040172676966268451215852324582101194742061525557812564453387714406069446568557296833891922333917973171781712398231444765017569786138204626428686475512081008869161356663835907376813620623094726423534934115338637680370196566363898565440916420378417101222533507481022009813965870308509434605572523305680664828681425636234207807582559504733600503843338669076167921857317688305509489155913077216813311538580953001082599237651699121046326764631381417938087830320500185359480714988505328255100734630064237751772721041377755755758383728606726177445658155753749546827828367693983626464120663268900779889011610977485795045454249188894632682998277800095777729909490506987330274655022172974270055617103171381531308634336085677697835661682929287159838789826930383315674460217354705705234187446810381730464144769127502716306117568896352494264872646928422909047811947459414307831780911896463140669176040839893502623072113013035804566351744823914338429994828350540337164330704588816917776621293915283699491415184011061291945677340143774758101744007984265329760224133355471830730432064418860606881165959939461489696048304165989853911016737835942965761258765956694645210261790635052850844049367423694786457242319223876105320215233590183209380979382157793309702396739168657114368745946841839046206961645429805778334063190389942334020411178682896069243807140681786973729641180611085156753661027633511055611147902653691005486364739144770418115605566603040818894100496165095761549293775405038363974675765612428223961167095350394284144798049066930390943784355748334751120666403798040675804319883909238989350808136234325508394865404400385449556666435422897368208799128314496998148096024015846046500201025684250911796445322403586476627494547243797457382130680469946455654395608807410688279411668833442359334188983019671463135763717460382558293393419395286276453124219823687723382959007218768708887571803724567085232942403781418773919587182564580188663946234725642165270088914107552017294247820742960894868135180233075178437704862253792421058681137337857704094916539627784506331191336270494117004459646827163273707499551661503016540277401244532340339070015314519372532924425555358290125862503440779017980396625693802402822409153201651439676459682161780197709418946939598030795783707096370404661445866130990432632842137057431365530638735240902637787254233791746536659271762081384241956701624616899894977073709318764568923603982528175269388490053945486114311532520281093103528814299216517745344242288346124303508663835748798288807350450775755140096342378163202533874873763807978963119537550679931777141388973135823812988473301700201745385807863649515296692795624248531731908034620699532486876799669950549424570907390181507153335471587933472446616419340922483929351763543609651165500079565951112158564861195932666467768922371943385930573088509605045609698617292035168782151463948247477864458624213351011609132904061103927386683994594029692839452814741913098822705817920022685744156774029816070052613199686338067501951059646567037859621798086391773941058258891159469702634830348329457457523254404980917073571970900248181103603185669296070980842920880411198777911735258716800250052843919146250818454526213522114083435724878153835459203125371245922379104203574592149796878158713419246502318256091007870208552443225934537396798500700603619080298158835351246441842194201216731570728547961113587726583650929323633587069111109904346659939189856186633203817348222708462294883469455343624547846732869247932344015216320688267793910071151481399883449453759825144220806257772738183442688813932035064058294919506294602275218499276543341350642484228940953995208659689884242762028844713291217540233946714880731304107645730276732292082055509244817103459155475998694402045247884791684982856513954092180380170652958861718633781792476268057023805292758209008374468275566307072939050558948717859727184492921702041808989375284891262284983109715099203273200620451274307036926173049912738517689647659819578061835277276561966212910704166864162787294058326983391148612146176296683888715745808302532741931288862682872211773890233595608531455373198575513778258901513815106889159613523025843451155988334893642554129230492988196839904166354811080340327555712138220793006730910426051924446729399954873625137237986784388240679203683646697036933493576957975653262844332446974125320378849584931681066747900951780077100344459702646274204911595198675989697793730909896754973129094145113367616079389806506082437730145102322130950526183858783187191471720968143572395267568632673013390548570624845829475660989692432248206439773609473412090220926862756023362974468300396846647433715615916817673545697127837241811198923647140957523608720177948740415485189152229881616293016316175964908860145219544738332852979736595788880616196742924866073386368303717501056745336121074315911513019780083004360513453608072733708165243657459283518791942503607678615337770685032195012615535667863226570418368483713612269226578891145635941648037579957791692984722753611080790907712229776359266336063289604586695427664400730509526007595810168713320970758293207196692041459186562259221539157244454155656263461530168497212485237814146262631502965478752267468291191528961274678748991301558633862878494529857201420407690120255736339677623989747924070268263569284421089933429207258059918777490463403533120004212719392185136210246951479292772299038695188533081321618830234639170305700269522932436020836928784419993367780343281000178426455626670425272528509496237312584423458490319688367311485970569447668025104476374013837852732518335677767793355956082627747893042117165911044023182622470947848376480916118320636046950350909699092280407053420254593372378116327111844433022139883092542287770259946182556214004216576226039482041432600344217297861608082718335173850291958345753722187350740732001568720763497493660780764138107479679218580396298127564602051377622956602429556250304225829658673994148068559711600788050171764531212720591775419513980003681124515379406522318857992332752196253322252030136434992980485710086205830115567320837101156414344069433817541894237182744102018319124686129508674885457992647188716606533775802155767379602045986210947466843269716204266879184609490366261634245095300812167071830328516112053061196552213402799243246223900949170378051255937366824943122060031856719390274529314108289980909943805837441073913943352584517054724849147001514242412999081259145342201617095501379555549791409563350780270782690381946653705593649719540671156120218781623357125571033316519173635278664999519516954814010437794476324795225159759705849145892124975064363627096135493118122440974411562344924560745721149076938166426109461127341532381435314244343067501125527077231057781941946368864818217455796942781870918567337709959928704640567600182950077548660390836086961656072145567754367797664918221229055103315672010022815551890639186469138594154521934265065335153728498160610463592683475680228189214662533735490400149302515892831435508828023231436241661422620307074772831906366008284601281815142513716192523910657717224855559122990365764385537855435576105237560814400427693543529418696040949477587654940202184883880519288559351637588358665010382560510610617417354499342971121443835096825661005550454809771768043888171883173394098683773990111566190722591749887397996479637647682332087204172883633058502169128245004275471207390056989616025741866155102541729513167353166651081419375357526898276713443162905826835500476224908530101813339330460888525764260187306897565437871248379947368335027824552228595662594684738186554824891293358677999322540548963825761631118185209153879513334177062289200542650449873559077496969466640028703879191661910344875833981643922741918023653205495738036842080708187186460561110993757125864051101555871042160247243512760351078068739408349282303879571340322544299545666819604081861563195090210359965797887774344224361814197785496318708071204666550643048777079121403932120385334478403426675625328950706803093483061745456969217987923246592328162656751543124101239004102895270236605403870069091865989413570937888309218293970382331215816899893547512791656883317208603151434691361606111739052142832747067036637430039426609838091217728178579896531465962161084550767677085615309478348118637478047755295931651039119889493508795747317406979670587259832201654473495940431724339240762165198104350625102075193326277040840171471607315116960550790398856043422973078377476853300181186006962138937260231310200339827783120591228165231643267242958991717931821770408451400213315077346179854657451669813273886620166175335244162479909804325365498962101407148649912979281505319070633151151057525903136649504688088972419743000140479625825793819069447626320028710485203299377197002274362545911505349222041537000367226646399731115916049376551469987938247648785075655327056207048565783932280361256443699422190995523484655327669645749900543816165432344433997137647645175066777972331350365559226886101449782325416368815592441546550676597228959842740107778780309939454436053535838849947022138540471117014879023064718728331883511648716946803329160213890145325134087046421584109724182531114847451462953524494293656213219435764990190830880622768671023487594864245374873911042687144522999491511042003077695967606169114533860189654449616153731121908286313924822349768127366130956052073399799835532841888434857658959239759625424610039118241624102374732611920277196731944828790289483356997953951270076650250593451036056646424571312174343423403735620899283958502615941939892113278156333589834052729591523600962369545619375162365528352809533235358095912456035447363910551121759516167924838997279788187215677729738292100573085389538415317842470633698921326112479347855070802733049416230720948347891140455120648782464541253791088782843816026197471253896590841122380514344613348787641843979221357700980550895909124556685250791144766812666458000883861534573057357702819511001264398713814196420694356692785479304183907407126372154585874654929359813404006673675221793246681752529031178811899714770479684691012180528804825838402225051749406675501537889273298912170953570904947758851887810439990026410811620055073035489032328576099566664663495349200483194330858176097548800900256917286395749739485281065381824297890946542437301054067936208535597702357992562204772336462534177113546759730553019468654431603783803859144026663667062280218659513150230872026394980970529513709896464144380383575253908000495124254709256133974729130990130248250615893371945633581300296113764448101874763955144534667568586588158389432595406009546476984729600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Programming with Overloaded Operators longint g_lngResult, g_lngOperand; ⋮ switch(g_eOperator){ case ADD_OP: g_lngResult += g_lngOperand; break; case MULTIPLY_OP: g_lngResult *= g_lngOperand; How many overloaded operators are used here?
Programming with Overloaded Operators case SUBTRACT_OP: g_lngResult = g_lngOperand - g_lngResult; break; case DIVIDE_OP: g_lngResult = g_lngOperand / g_lngResult; case MOD_OP: g_lngResult = g_lngOperand % g_lngResult; case EXP_OP: g_lngResult = g_lngOperand ^ g_lngResult; How many overloaded operators are used here?
Programming with Overloaded Operators longint temp, result; ⋮ case FACTORIAL_OP: result = 1; temp = g_lngResult; while(temp > 1){ result *= temp; temp -= 1; } g_lngResult = result; break; How many overloaded operators are used here?