Object Oriented Design
Object Oriented Design CSE 687
Popular in Course
Popular in Computer Engineering
This 44 page Class Notes was uploaded by Amelie Murphy on Tuesday October 20, 2015. The Class Notes belongs to CSE 687 at Syracuse University taught by James Fawcett in Fall. Since its upload, it has received 53 views. For similar materials see /class/225562/cse-687-syracuse-university in Computer Engineering at Syracuse University.
Reviews for Object Oriented Design
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/20/15
Handouts CE6 81 Code Managedep RA II Resource Acquisition is Initialization RAII Purpose Illustrate how CCLI implements RAII Managed classes can simulate stackbased value types in that 1 Their syntax looks like allocation on the stack 2 Destructors are called when leaving the scope where defined which calls the class Dispose function if defined a This supponts scope based deallocation of unmanaged resources b Memory is still reclaimed by the garbage collector non deterministically These examples demonstrate syntax and semantics of managed CCLI Jim Fawcett CSE687 Object Oriented Design Spring 2008 Running Visual C Version 60 1 N 5 A 5391 N 9 3 Creating a new workspace and project 0 Click FileNewProject to get a tabbed dialog box with project tab selected 0 Enter a workspace location by typing or browsing if the path you type does not exist it will be created 0 Enter a name for your project will reside in a subdirectory in your workspace by default change by editing the location Check Create new workspace or you can add to current workspace1 if you have one open Select Win32 Console Application for projects not using windows GUI or COMZ Click OK Creating a new le 0 Click on FileNewFiles to get a tabbed dialog box with files tab selected 0 Check add to project 0 Enter a file name or browse 0 Select either C Source File or CC Header File Click OK 0 Enter source code in the window and click FileSave Adding an existing le to the project Click on ProjectAdd to ProjectFiles to get a file manager window Browse through directories until you find the file you want Select it and click OK Compiling and Linking 0 Click BuildBuild or hit F7 key 0 Warnings and errors are shown in the bottom window Figtlt these and rebuild 0 You can build and run by clicking on the l symbol on the build toolbar Running the result of a build 0 Click BuildEgtltecute or depress Ctrl F5 Enter command line parameters before running 0 Click ProjectSettings to get a tabbed dialog box 0 Click on Debug tab and enter Program arguments for the command line Click OK Enter de ne de nitions before running 0 Click ProjectSettings to get a tabbed dialog bogtlt Click on CC tab 0 Add to existing Preprocessor definitions by typing a comma and your definitions Click OK Debugging 0 Click on ToolsCustomize to get a tabbed dialog box Select toolbars and check Debug you should only need to do this once 0 Click on BuildStart Debugstep into or depress F11 0 Single step by over through or out of by clicking on buttons on the floating debug menu You can figure out what each of the icons means by letting the cursor rest for a moment on an icon A tool tip will pop up with a short description of the resulting action 0 Add watches by clicking on the eyeglasses icon 0 Add breakpoints by clicking on the hand icon on the floating debug menu Using Help 0 Click HelpSearch to get a tabbed dialog box accepting either a search string or a query 0 Help files are hypertext and you can usually find what you want with some link following 1 It can be very convenient to have several related projects in the same workspace allowing you to switch between projects quickly and view files from another project with a double click If you select an inappropriate project type eg Win32 Application instead of Win32 Console Application you will get a large stream of errors with messages that seem to make no sense Creating a MultiFile Project with Visual C 60 1 I Lu A 5391 N Creating a new workspace and project 0 Click FileNewProject to get a tabbed dialog box with project tab selected 0 Enter a workspace location by typing or browsing if the path you type does not exist it will be created 0 Enter a name for your project will reside in a subdirectory in your workspace by default change by editing the location 0 Check Create new workspace or you can add to current workspace3 if you have one open 0 Select Win32 Console Application for projects not using windows GUI or COM 0 Click OK Adding an existing module to be reused 0 Copy module s header and implementation files into the workspace directory On the Project menu click Add to Project Click Files on the submenu In the file dialog that pops up select the module header and implementation files Click OK and note that the files show up in project files in the project tree view Run its test stub by compiling with Degtltistingmodulename and execute code to make sure that it is operating as normal Creating a new module Click on FileNewFiles to get a tabbed dialog box with files tab selected Check add to project Enter a file name or browse Select CC Header File Click OK Enter source code in the window and click FileSave Select C Source File and click OK Enter source code in the window and click FileSave Creating an EYecutive Module Click on FileNewFiles to get a tabbed dialog box with files tab selected Check add to project Enter a file name or browse Select CC Source File Click OK Enter source code including the program s main function in the window and click FileSave Building and Running Program 0 If you need command line arguments click on ProjectSettingsDebug and enter arguments with space separators in the Program Arguments edit box 0 If you need to linkto a nonstandard library click on ProjectSettingslink and enter the library name in ObjectLibrary modules edit box 0 If you need to set one or more preprocessor definitions click on ProjectSettingsCC and select General in the Category combo box and enter in the Preprocessor definitions edit box any strings you need in the preprocessor s symbol table To build the project use the key F7 To run use the key combination Ctr F5 Debugging Program additional comments 0 You can single step through your program using the F10 and F11 keys F10 will immediately execute any function at the cursor F11 will step into the function and allow you to single step there as well 0 Right clicking with the mouse cursor on the left border of the edit window will bring up a context menu that will allow you to create a break point for the line to the right of the cursor You can jump to the next break point by using the F5 key 0 You can enter variables to watch in the watch window Whenever they are in scope you will see their values in the watch window Con guring the Integrated Development Environment IDE 0 If you place the mouse cursor in an empty area of the topmost toolbar and right click you will get a context menu that provides checkbogtltes for various windows you may need For example if you don t see a watch window in the IDE when debugging right click on the top toolbar and select Watch 3 It can be very convenient to have several related projects in the same workspace allowing you to switch between projects quickly and view files from another project with a double click If you select an inappropriate project type eg Win32 Application instead of Win32 Console Application you will get a large stream of errors with messages that seem to make no sense CSE687 Visual Studio Help Session Jim Fawcett With the help of Ghanashyam Namboodirapad Saurav Sen and Murat Gungor 01 February 2005 800 PM MadLab 010 Link Hall Visual Studio Help Session Spring 2004 codel hep2004 Visual Studio Help Session Spring 2004 lcade lhelp2004 met We Yemv ates men may Pmyetts B snksa utmn El V sua x Pmyects we 1 a El V sua 0 Pvmects El Setup and Dev awwent Pmyects E Othev Pvmects Q V sua Studm Summaer Name he pz m Lacatmn c susEsa7ade v an52 F 9 n r gasesammn Sumter Wm be vested at c SUSE587adehev2um Visual Studio Help Session Spring 2004 codel hep2004 39 Mir msn Devzlupmenl nvimmmm design 7 sum Page Ede gum Mew 2mm any 1 w E mung Pmyect mung Pmyect Emm Web Add New Item uazuua Visual Studio Help Session Spring 2004 lcade lhelp2004 Add New Prnjecl men was Ismv ates a 0 Pmyects Setup and Dewavment mm om mm ehev2 4DemaF e m Heb Visual Studio Help Session Spring 2004 lcade lhelp2004 Add New Prnjecl met We w 55 Pvmects El V sua x Pmyects V sua 1 wave Q szuaKPmyect5 m 52 g SetupandDeD anenthmects assUhYaW 7 a El orhev Pvmects vCansa e Apphtatmn NU Custam MEN 5 us m amsz waved that uses Managed Extensmns fay c Name Damman Laaauan susisa7cadehep2um a anse Pmyect Wm be vested at c SUCSE6E7adehep2 4DemaF e ma Hap Visual Studio Help Session Spring 2004 codel hep2004 3 www2cssyre u r IlauIvymailmandnquotlsSE657Icndel lelnlnl r Mmusun Imame xplmar He 555 yaw Favantes Van s 55 in i1 wmmmmy Bxkv k jig hi135am ikhwma yuua y fgag Hg ii E a a 5 c I V Ga Lm Wehasg ant v 7N wwwecssyredu quot 39 w Mquot 39 A IdSEGsu m r p a ltuauu ltuouy 1W aaruraay January 2 um 25 3 555 an 2255 analdac H E 5 y February 25 255 335 an 5 1 5aruruay January 25 2553 555 an 51551va rm Ve Saturday January 25 2553 555 pm Open 5arurua Janu 25 2553 555 an ovemnNewwmaw La Sacu uay y 3 PnntTavqet H A Saturday January 25 2553 cm aw Shavttut paazr Add ta Favantes Pmpemes will M m 035 1E aul mjwi 11555555155 Visual Studio Help Session Spring 2004 codel hep2004 mmmluuulcstssnmlu lalnlnl r Mkrnsn Imamu xplurer J V a gar a a 53pm cum 6 g i E a 3 an n i gt9 V aa ma 5 Wauaaaawe wwwecssyredu quot 39 quot 39 7SE68quot 39 quot quot Ta paranr Dlreccur Saturday January 25 2mm 39Ta ta 1m EI am oaua m FILEINFOvcyr01 pm 4553 ms mama Saturday January 25 2mm la mfcolmg IF File Duwnlnad SEWquot ammo Pmem WWW ars 5w edu thmated me an mm m nsray vat39e US i DemaF es Manama man up w MW y Visual Studio Help Session Spring 2004 codel hep2004 T39 DEmnFiles r Mir quotIsaquot Visual cu design 7 Start Page Debug v w aqueqatmn v R 11 a 51 v E 5 Summary he vzum 1 watt Q U Prwizdg i U lmzkzsnumzs MxPrnlll M W Rgbudd a 2n anExislIn m m 1 deal pmeaow gt xlzuzum xlzuzum uazuua wageran m wgh Refevence 1 Adages Seussgmppmed 59 Addgesauvce Debug gt iave DemaFdes mug X3 Rename ca PLavemes Tln r K23 u aw 1m 9mm 11M mmm mm Wifa f mm mhtm l i p rm 39 v Sa utmn EXD mev E055 mew mm a om as and 5th new m Index new rm Salaam damsmw WWW Fm v Read Visual Studio Help Session Spring 2004 lcade lhelp2004 Add Existing Item 7 DemuFiles mm a DemaF es v c v x a My 1 n WES D7 We szua C H25 quot t quot W quot xx quot cc quot th quot t h quot h V ancd w Netwmk mates Visual Studio Help Session codel hep2004 Amaaw w aqueqatmn lo seE ileO lt Eihdcloseghehdle gt rrlt test stub gt77 1fdef TESTiFILEINE O mm mewmwwmm mm an quvatmn Manaqu WWlt function object which detects date order gt77 earller lt Dehuqqmq c publlc bool ret ampfil cone filelnfo ampf12 operatorconst urn fll earller f12 functlon object whlch smaller lt publlc bool operatoro Const fileInfo ampf11 const return filsmallerfi2i Em Custam amh Slap Web Dewavment 3 ogmermD test entry polnt merhuhr erge char argv lt cout ltlt quotn Testing Eileinfo objects ltlt quotn n typedef setlt nlelhfo lessltfllelnfogt gt setNames typedef multlsetlt fileInny rller gt setDates typedef multisetlt fileInfo smaller gt setsizes fileInfo f rum 1 Succeeded u falled u errppee Visual Studio Help Session Spring 2004 lcade lhelp2004 nemnnles pmpeny Page gannqmemn Actwewehuq v E atfmm nememnaz v gn quvatmnManaqev an quvatmanpemeA run w mu rzsunmm Geneva anmestandavdlndudePa Na Dehuqqmq Genevate Pvepmtessed F e Na a um Keep amments Na neve Ovtvwzatmn vevmcessm deGenevata uaqe Pvemmv ed H OlDutF es Bmwse New Advanced ammandune Dun y Bmwse Infmmatmn me Events 7 um umstep 7 PrDrn2 nrD Inns Wehoep wmem Sven esanemmmeDvevmcessmde nes Dmacm gt Ban22 He v Visual Studio Help Session Spring 2004 codel hep2004 EH2 mz Mew Emyect gum thuq 1am Mndaw dew 39 Debug g aqueqatmn a g a 8 3 v com ltlt quotn Testln quot ltlt quotn nquot typedef setlt flleInny typedef multlsetlt flle typedef multlsetlt flleInny smaller gt lessltfllelnfogt gt setNames names are unlque Info earller gt setDates dates may not be set51zes Sizes may not be f 1fargc gt 1 fsetPathargvl ut ltlt quot path quot ltlt fgetPath ltlt endh t ltlt quot n Elle 1n FlndNextFlle ordernquot sm ss1nsertf fshowDatacout cout ltlt quotn Elle ordered alphabetlcallynquot s snend nt 1es ordered by datenquot quot1terator dec fordet sdbegln dec 1 sdend de OK It Works u u We could walkithmugh this code with the debugger to help us 39see how it functions alCude gn ma Debug Inst y n E is r Mew was 3 t Visual Studio Help Session Spring 2004 codel hep2004 w Mndaw dew Deng v w amen i a Q 93 a V Ohyez Gaha We same hrquotan ram 5 l man ltapux m jvold nain int arge com ltlt quotn ltlt quotn typedef setlt typedef multisetlt f1 typedef multisetlt fileinfo fileinfo f 1fargc gt 1 fsetPathargvl lt quot path quotn 1flff1rStElle quotfquot t re urn sninser r 5d insert f ssinsert f fsnowDatacout while fnextFlle 0 lt 511 inser r 5d insert f ssinser f t fsnowDatacout cout ltlt quotn Files ordered a1phabetica11ynquot s tN m iterator fnit forntt snbegin fnit snend nttJ fnitagtsnownata Gout cout ltlt quotn Files ordered by oat setDate iterator fdit fordet sdbegin det sdend fdit i gr I char argv Testing Fileinfo objects fileInfo 1essltfi1e1nfogt 1 o earlier gt gt setNames names are unique Pmletton y r eInf setDates dates may not be snaiier gt setsizes sizes may no MN n W gt quot ltlt fgetPath ltlt Elles in FlndNextE lle ordernquot nquot ma Befevence Add Web Refevence 5her Item Set as stgvtup iject a in as endl a Add esauvte plunging mmaaa tep a WExmt yeg a lt x x gt a 5mm EXD mev 395 555 Wew Visual Studio Help Session Spring 2004 lcade lhelp2004 Add New Item 7 DemnFiles DemaFdes cw mm 1 Wm 1 KWesa7meme pmmmemm m Heb Visual Studio Help Session Spring 2004 codel hep2004 DemnFiles r Micmsu Visual c design 7 ruequot cpp mew dew 39 2 m Mew Eiayect Eu d Debug 1am E 543 oetuq quotwaqueqatmn BQ9 a v quot Ohyezt mwsev StavtPaqe merrer Fde nram newts rm a gt x Lia utiniExp meeremaFdes n x a 3 three 3 v r 3 g E Sa utmn he DZUm 1 pmyert X pubhc W 5 bool operatoro const filelnfo sfil const fileInfo ampfi2 H gment return f11earllerf12 F eanaEW gt g DemaF es rep dev Hes F eana h D Resauvce H25 rlt function object which detects size order gt E L jcleee smaller i publlc39 bool oper return gt atorU const flleInfo ampf11 const flleInfo ampf12 f11smallerf127 E1rrrrlt test entry pomt gt rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr W L e m wragm a a tax W WE tamm imm J W are ch Emma warm Euxld 1 surreeeee u falled u skrppee mm a om as Fm 5th new m We new rm teem rte stem WWW rm a Wm We Ease mew m m an M Visual Studio Help Session Spring 2004 codel hep2004 PP Em Mew Emyect Md Debug Ian s Mndaw He v 154M meme HEX Wm hm swam Qau u e kettet vj eomem DemoFllescpp e executlve for help demo 1nclude ltlostreamgt lteetgt ude quotfllelnfo 1 hquot slng namespace std 1fdef Tsswinamonms F rah Resume H25 3 Mtteueneaumwes m set jvoid mainint argc char gt6th cout ltlt quotn Testlng u ltlt quotn typedef eetlt fileInfo gt flleInfo f Stan quvatmanpemes Plevvacesste mtwns w ifargc gt 1 Geneva anmgstandavdlydudePath Na fsetPathargvl Genevate Evvatessed He cout ltlt quot path quot lt Keevtamments Na D com ltlt quot n mlee 1n FlndN e Ordernquot setNames 5n mutatetmle f n return sn1nsertf f showData Gout whilefnext ile lt nenmunns sn1nsertf Wehoep wment 39 mma Dvevmcessmde nes fshowDatacout m 39 n e gt fcloeemle Du UDDwaUDD Pour ltlt quotn UK Dan21 AWN He p wmee ordered ewnh v gt Rsa uhanExp hdex gr mpemes Va ue awe W 7 1 Dem es exe memgntaz an e t C uxutatum DemaF es exe mamCRYStavtuDO unesz ux19 meta ijand e lt gt lt gt mm Sites mimics t i Il mg Ema admka l a Ka m 11m DE mm teamein Visual Studio Help Session Spring 2004 lcade lhelp2004 DemnFiles Prnperly Page ganhqmamn ncwemehuq v E atfmm rtweWn32 v gn quvatmnManaqev 5 an quvatmn Pmpemes Geneva WamrquwectaW Unk V Attach mm mm mm mm Custamaumstep Dehuqqev er hula We WWWquot SQL Dehuqqmq Na H quotmm Enusz nnectmn Lam nmmand Aramm Yhe mmmand hne avquments m D555 m the apphcahan cm W Heb I Visual Studio Help Session Spring 2004 codel hep2004 ual co bleak Dem EH2 mz yew Evmett gum thuq 1am Mndaw dew W Debug v w aqueqatmn a g 3 3 a v 7mm erg 1 1 4 39gt X Salytianfivlaze Mafia JAE Meme 1 pm A E DemoFllescpp t executlve for help demo 1nclude lt1ostreamgt 1nc1ude ltsetgt 1nclude quotf11e1nfohquot h uslng namespace std F em n yte H25 H25 Lanesau a M mw 1fdef TESTiDEMOFILES msa a 5mm jvoid mainint argc char argv lt cout ltlt quotn Testlng Ellelnfo objects quot ltlt quotn nquot typedef setlt flleInfo gt setNames names are unlque flleInfo f luath gt 1 fsetPathargvl cout ltlt quot path quot ltlt fgetPath ltlt endl D cout ltlt quotn Elle 1n FlndNextE lle Ordernquot setNames 5n sn1nsert f fshowDatacoutF gt fcloseFlle 0 mea umntxp man g pmpemg u S cements exe me numaz em 2 they aqu uxutatam me 2n Demames exe maxnCRYStavluDO ane 259 uxw nm 94 etltmexnr Elm E1 Lam s wmm Eteuszetk W Eveakpmnts Ha ammandwwdaw E Output HZ Yaskust VReadv h H iL39J 453m Visual Studio Help Session Spring 2004 codel hep2004 ual co bleak Dem EH2 mz yew mm mm thuq 1am Mndaw dew oetug v gamequ aggaz gv HEXW39 wig 1 tttet l 1 eOMam DemoFllescpp e executlve for help demo 1nclude lt1ostreamgt 1nc1ude ltsetgt 1nclude quotf11e1nfohquot uslng namespace std F em n yte H25 H25 L39JResau a M mw 1fdef TESTiDEMOFILES msa emw jvoid mainint argc char argv lt cout ltlt quotn Testlng Ellelnfo objects quot ltlt quotn nquot typedef eetlt flleInfo gt eetNemee names are unlque flleInfo f 1fargc gt 1 fsetPathargvl cout ltlt quot path quot ltlt fgetPath ltlt endl D cout ltlt quotn Elle 1n FlndNextE lle Ordernquot setNames 5n L39 Watches 39ajnV Vai i bl eiin scigpe 39 oteath at39 w ef are selec In g sn1nsertf fshowDetacout x gt fcloseFlle 0 mea umntxp man g pmpemg u they 7 DeraF es exe mawn7nt325 qt2 they eygveuxutatammezu EIXEIEIEIEIEIEIEIEI ADDL DYDqD they DemaF es exe mamCRYStaVluDO Une 259ux19 2 E Ca Stack W Eveakvmnts Hzl ammand Wwdaw a Output HZ Yask m x h H Visual Studio Help Session Spring 2004 codel hep2004 at gm yew Emyect gum thug mt mm x w aqueqatmn g g m 3 g gt u I 2 A 3 36 X r gt E Mum j perm S D gt A g a a a as m return searchPath 3 ERESWES E WEEKm Q Sauvce H25 9 new tn 3 aalt set current d1 rectory gtee DemaF es tap L adevF es hm n Evold flleInfo eetpathconat strlng amps gamma 3 Q stceHaneaus H25 a ham searchPath s a set a Xmemaw Elt flnd flrst flle gt77 quotW L f1r5tF11econst strlng ampf11ePattern jbool flleInfo trlng path searchPath 1fpathpathslzeil 1 3939 path 3939 path filePattern n E lndE lrstE lle pathc75tr tdata return ihandle 1 NVALIDJANDLLVALUE gt aaelt find next flle gtee L 1 Ebool flleInfonextFlle lt 39 1f7handle ruvnnuinmmaivms t I I e return false f netlon f I gt return mndNextmleLhandletdata TRUE 3H7 rlt close search for current flle gt7 void fileInfoHclo seE lleO lt Eindcloseghandle gt v chJsEk asuunnrxu Max vapemes a x 3 Ems Va ue Type aquU aqu2 ant p E esexe elnfu setPatMstd nanrgmnqqnansm rnaygyazsqnawam aHatataK r evmv derm ev aqu nut tr scape DemaF es exc mawumaz ant a 2 Chev aqu a uxutatam me 2n um M25 evmv derm ev avqt nut tr scape DemaF es exe mamCRYStavtuDO mm uxw 5T E tau Stack W Bveakvmnts Hzl Cammand Wmdaw 7 3 x a output H2 Yaskust u m m DH M Ema a net wutm Ready Visual Studio Help Session Spring 2004 codel hep2004 w WW mgagaa 5am Manaqev ma amment Web Page vests gum uslng namespace DatEuscatm ammumw Edman mm mm hate Tam 1fdef TEST OLEOMOhyectMewer mamunc my com ltlt quotn Reqxstevtantm ltlt quotn unReqxstevCantm ixmma Van s typedef setlt o f ifargc gt 1 f setPath argvl com ltlt quot path quot ltlt fgetPath ltlt endl D cout ltlt quotn Elles 1n FlndNextE lle Ordernquot setNames 5n 1flff1rst 11equotfquot return 5 ordered alphabetlcally nquot It in snbegln ntt snend ntt ntt7gtshowDatacout setNa for ntt e owe my imamsxsueuasgmamammmb all m Symbnls loaded m Symbols loaded 23mm m 10 a m Symbols loaded 22 Visual Studio Help Session Spring 2004 lcade lhelp2004 Cuslnm e We mm 1 m add a mmmand m a tummy 52bit a alean and may the mmmand m D the new m m a tummy memes cammangs F e A e 5 Set Next statement 4 M m a cu m oeeeeemw j 5M2 Se ected mmmand Desmmmn gem Visual Studio Help Session Spring 2004 codel hep2004 w aggyagam QQ 5 StathlthautDehugqmq mm Emcesses Elam cumulus Stan m m am am anhiHFs 1fdef TEST main int arng Fllelnfo objects w mm was pawl com ltlt quotn ltlt quotn typedef gt setNames names are uni Tasddammmandtaataa hah 52bitacateqmvanddvaqihe mmmand m D m mang m m 3 mm ategavlesl cammangs F e A Step Ovev Step 0 z ltlt fgetPath ltlt endl SetNextStatement J M m a can mama j 1n FlndNextE lle Ordernquot mend Desmgtmn mamsalaman Wm alphabetlcally nquot snend ntt lt ntt 7b7735c561SCHeEISSillsd7AAmmscoxlxb dU Ila 5mm loaded Loaded m symbols loaded Loaded Defaulcbomaxn Loaded Ila Symbols loaded Visual Studio Help Session Spring 2004 codel hep2004 During this help session we have 1 Created an empty solution wmynweww Added an empty project Downloaded files from the handoutscse687codefileInfo folder Added them to our project Tested them needed to de ne TESTFILEINFO Added a new file demoFilescpp to the project Tested it needed to define TESTDEMOFILES Used the debugger with F10 step over and F11 step into looked at local variables watches and the call stack Demonstrated how to add a debugger command to the debug menu using toolscustomize 25 H N STL Containers Supplementary Notes Jim Fawcett CSE 687 Spring 2002 Every container allocates and manages its own storage Type de nitions common to all containers valuetype type of values held in container reference valuetypeamp constreference iterator constiterator reverseiterator constreverseiterator differencetype sizetype difference between iterators size of container Member functions common to all containers 00 Cc C c2c1 C cbegin cend crbegin crend c1 c2 c1 c2 csize c maxsize cempty c1 lt c2 c1 gt c2 c1 lt c2 c1 gt c2 c1 c2 clswapc2 default constructor copy constructor destructor returns an iterator to first element returns an iterator after last element returns a reverse iterator to last elem returns a reverse iterator before first elem equality comparison for same type cont returns number of elements in cont returns size of largest number of elements returns true if cont is empty lexicographic comparison assignment operation swaps two containers P 0 Sequence containers vector simulates an expandable array occupying contiguous memory list based on doubly linked list deque a double ended queue which uses a directory managing blocks of contiguousmemory Member functions common to all sequence containers Cnt Citer l iterZ Cinsertitert cinsertiternt cinsertiter l iterZ iter3 ceraseiter ceraseiter l iterZ constructs a sequence of 11 copies of t constructs a sequence equal to the range iterliter2 inserts a copy of t before iter Returns an iter to t inserts 11 copies of t before iter inserts the sequence iter2iter3 before iterl erases the element pointed to by iter erases elements in range iterliter2 Invalidation of iterators Invalidation of iterators into vectors insertion in a vector invalidates iterators from the point of insertion to the end ofthe vector if insertion causes reallocation to provide more memory then all iterators become invalid erase invalidates all iterators at and past the point of erasure a safe strategy is to assume that any iterator into a vector becomes invalid after either insertion or erasure Invalidation of iterators into deques insertion and erasure in the interior invalidates all iterators Invalidation of iterators into lists list insertions never invalidate iterators and erase invalidates only iterators pointing to the erased items Use of invalid iterators The only safe things you can do with an invalid iterator is to reinitialize it by assigning a new iterator value to it or destroy it Sorted associative containers all are based on balanced redblack tree set set of elements sorted by value with no duplicates multi set set of elements sorted by value with duplicates map set of ltkeyvaluegt pairs sorted on key with no duplicates multi map set of ltkeyvaluegt pairs sorted on key with duplicates Types common to all sorted associative containers Ckeytype type of keys used to instantiate C Ckeycompare type of the comparison type used to instantiate C Cvaluecompare type for comparing objects of Cvaluetype Invalidation of iterators with associative containers insertion does not invalidate any iterators referring to container elements erasure invalidates only iterators pointing to erased elements Member functions common to all sorted associative containers C Ccomp Citer1iter21 Citer1iter2comp ckeycomp Cvaluecomp cinsertt cinsertitert cinsertiter1iter2 cerasekl ceraseiter ceraseiter1iter2 cfindk1 ccountkl clowerboundkl cupperboundkl cequalrangekl void constructor constructs empty container using comp for comparisons constructs empty container and inserts elements from iter1iter2 into it same as above except that comp is used for comparisons returns c s key comparison object returns c s value comparison object for sets and maps inserts t if and only if there is no equivalent key stored returns pairltiteratorboolgt The bool indicates if insertion succeeded and iterator points to the element equivalent to t for multi sets and multi maps inserts t and returns an iterator pointing to the inserted t same as above except that iter is a hint about where to start search inserts elements from the sequence iter1iter2 erases all elements in the container with key equal to kl Returns the number of elements erased erases the element pointed to erases all elements in the range iter1iter2 returns an iterator pointing to an element with key equal to k1 or to cend if no such element is found returns the number of elements with key equivalent to k1 returns an iterator pointing to first element with key not less than k1 returns an iterator pointing to first element with key greater than kl returns a pair of iterators with first lowerbound and second upperbound S TL I tera tors ll Iterators extend the functionality of native pointers Any container c defines valid iterators pointing to the first element returned by cbegin and one past the last element returned by cend an iterator range is a pair of iterators that serve as the beginning and end markers of some operation on container values Range iter1 iterZ includes the values pointed to by iterl through the value pointed to by the predecessor of iterZ iterators can be dereferenced eg if iter is an iterator for some container c iter returns valuetype whenever it is in the range cbegin cend if iter is in the range cbegin cend then either iter stays in the range or is equivalent to cend iterators can be mutable or constant depending on whether the result of operatorquot acts like a reference or a reference to a const 12 Input iterator requirements Ii copy constructor i j returns true if iterator i is equivalent to iteratorj i j returns true if and only ifi j returns false i returns valuetype if dereferenceable Ifi j then it must be true that i j Note don t attempt to write to i as it may not be an l value i gtm equivalent to im i returns an iterator pointing to the successor element to i or to cend i returns i then points to the successor of i or to cend Algorithms that use input iterators should be single pass 13 Output iterator requirements Ii copy constructor i t tis assigned through the iterator i returns an iterator pointing to the successor element to i or to cend i returns i then points to the successor of i or to cend The only valid use of i is on the left of an assignement Algorithms that use output iterators should be single pass 14 15 IO 11 ij ij ij 1 Forward iterator requirements void constructor result may be a singular value result must satisfyi Ii true ifi is equivalent to j true if ij is false result must satisfy i j returns valuetype if dereferenceable If i j then i j must be true Ifi is mutable then i t is valid equivalent to im returns an iterator pointing to the successor element to i or to cend i j and i dereferenceable implies that i j returns i then points to the successor of i or to cend Bidirectional iterator requirements meets all requirements of Forward iterators 1 Assume that there is a j such that j i Then i refers to the same element asj It must be true that i i and if i j then i j returns i then points to the predecessor of i 16 Random access iterator requirements 1n in 1n i n 1j in iltj igtj meets the requirements for a bidirectional iterator the result must be equivalent to incrementing i n times returns an iterator equivalent to i n the result must be equivalent to decrementing i n times returns an iterator equivalent to i 11 returns a value of type distance Ifi n j thenj 1 11 equivalent to i 11 must be a total order relationship returning bool must be a total order relationship returning true wheneveri lt j i j is false must be a total order relationship equivalent to i gt j must be a total order relationship equivalent to i lt j 139 Algorithms Non modifying Prata C Primer Plus Third Edition Waite Group foreach Applies a non modifying function object to each element in a range find Finds the first occurrence of a value in a range findif finds the first value satisfying a predicate test criterion in a range findend finds the last occurrence of a subsequence whose values match the values of a second sequence Matching may be by equality or by applying a binary predicate findfirstof Finds the first occurrence of any element of a second sequence that matches a value in the first sequence Matching may be by equality or be evaluated with a binary predicate adj acentfind Finds the first element that matches the element immediately following it Matching may be by equality or evaluated with a binary predicate count Returns the number of times a given value occurs in a range countif Returns the number of times a given value matches values in a range with a match determined by using a binary predicate mismatch Finds the first element in one range that does not match the corresponding element in a second range and returns iterators to both Matching may be by equality or be evaluated with a binary predicate Equal Returns true if each element in one range matches the corresponding element in a second range Matching may be by equality or evaluated with a binary predicate search Finds the first occurrence of a subsequence whose values match the values of a second sequence Matching may be by equality or by applying a binary predicate searchn Finds the first subsequence of n elements that each match a given value Matching may be by equality or applying a binary predicate Example template ltclass Tgt class Sum Sum sumi0 l void operatorTamp t sumi t result return sumi private T sumi stdlistltintgt li push on some elements foreach is the only algorithm that returns its operation eg Sum int sum foreachlibeginliendSumresult 18 Algorithms Modifying Prata C Primer Plus Third Edition Waite Group COPY Copies elements from a range to a location identified by an iterator copybackward Copies elements from a range to a location identified by an iterator Copying begins at the end of the range and proceeds backwards Swap Exchanges two values stored at locations specified by references Swapranges Exchanges corresponding values in two ranges iterswap Exchanges two values stored at locations specified by iterators transform Applies a function object to each element in a range or to each pair of elements in a pair of ranges copying the return value to the corresponding location of another range replace Replaces each occurrence of a value in a range with another value replaceif Replaces each occurrence of a value in a range with another value if a predicate function object applied to the original value returns true replacecopy Copies one range to another replacing each value for which a predicate function object is true with an indicated value fill Sets each value in a range to an indicated value filln Sets 11 consecutive elements to a value generate Sets each value in a range to the return value of a generator which is a function object that takes no arguments generaten Sets the first 11 values in a range to the return value of a generator which is a function object that takes no arguments remove Removes all occurrences of a value from a range and returns a past the end iterator for the resulting range removeif Removes all occurrences of values for which a predicate object returns true from a range and returns a past the end iterator for the resulting range removecopy Copies elements from one range to another omitting elements that equal a specified value removecopyif Copies elements from one range to another omitting elements for which a predicate function object returns true unique Reduces each sequence of two or more equivalent elements in a range to a single element uniquecopy Copies elements from one range to another reducing each sequence of two or more equivalent elements to one reverse Reverses the elements in a range reversecopy Copies a range in reverse order to a second range Rotate Treats a range as a circular ordering and rotates the elements left Rotatecopy Copies one range to another in a rotated order Randomshuf e Randomly rearranges the elements in a range partition Places all the elements that satisfy a predicate function object before all elements that don t Stable partition Places all the elements that satisfy a predicate function object before all elements that don t The relative order of elements in each group is preserved 19 Sorting 8 Related Operations Prata C Primer Plus Third Edition Waite Group sort Sorts a range stablesort Sorts a range preserving the relative order of equivalent elements partialsort Partially sorts a range providing the first 11 elements of a full sort partialsortcopy Copies a partially sorted range to another range nthelement Given an iterator into a range finds the element that would be there if the range were sorted and places that element there lowerbound Given a value finds the first position in a sorted range before which the value can be inserted while maintaining the ordering upperbound Given a value finds the last position in a sorted range before which the value can be inserted while maintaining the ordering equalrange Given a value finds the largest subrange of a sorted range such that the Vlue can be inserted before any element in the subrange without violating the ordering binarysearch Returns true if a sorted range contains a value equivalent to a given value and false otherwise merge Merges two sorted ranges into a third range in placemerge Merges two consecutive sorted ranges in place includes Returns true if every element in one set also is found in another set setunion Constructs the union of two sets which is a set containing all elements present in either set setintersection Constructs the intersection of two sets which is a set containing only those elements found in both sets setdifference Constructs the difference of two sets which is a set containing only those elements found in the first set but not the second setsymmetricdifference Constructs a set consisting of elements found in one set or the other but not both makeheap Converts a range to heap pushheap Adds an element to a heap popheap Removes the largest element from a heap sortheap Sorts a heap min Returns the lesser of two values max Returns the greater of two values minelement Finds the first occurrence of the smallest value in a range maxelement Finds the first occurrence of the largest value in a range lexicographiccompare Compares two sequences lexicographically returning true if the first sequence is lexicographically less than the second and false otherwise next permutation Generates the next permutation in a sequence previous permutation Generates the preceding permutation in a sequence 20 Predefined Function Objects Iosuttis C Standard Library AddisonWesley Effect Example stdlistltintgt ii push on some elements stdlistltintgtiterator itPos find first positive element in list itPos findiiflibeginliendbindangreaterltintgtO
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'