c++ please
CIS25–SPRING2020 DUE3/26 Markovchainpt1 CreateaclasscalledMarkovWordwithtwoprivatemembervariables: string word; string *successors; TheconstructorforMarkovWordshouldcreateastringarrayontheheapthatcaninitially contain8strings,andsetthesuccessorspointertopointtothisarray.Shouldyourunout ofspacetostorewordsinthisarray,doubleitssize.Yourcodeisexpectedtoneitherleak memorynoraccessunallocatedmemory. CreateaclasscalledMarkovGeneratorthatcontainsthefollowinginstancevariable: MarkovWord *foundWords; MarkovGeneratorshouldcontainthefollowingfunction: void readFile(ifstream &file); Thisfunctionshoulddothefollowingforeachwordinthefile: -CheckifthecurrentwordisalreadyinthefoundWordsarray. Ifit'snot,createanewMarkovWordandaddittothefoundWordsarray. SetthewordmembervariableintheMarkovWordtobetheword. AddthewordfollowingthecurrentwordtotheMarkovWord'ssuccessors array IfitisinfoundWords,addthewordfollowingthecurrentwordtothat MarkovWord'ssuccessorsarray,butdon'taddanotherMarkovWord. Note:itisperfectlyreasonabletohavemultiplecopiesofthesamewordinagiven MarkovWord'ssuccessorarray. Whenyoureachthelastwordinthefile,considerthefirstwordasthatword'ssuccessor. TheconstructorforMarkovWordshouldcreateanarraystoringMarkovWordsonthe heap.Theinitialsizeforthisarrayshouldbe512.Ifyourunoutofspace,doubleitssize. Yourcodeisexpectedtoneitherleakmemorynoraccessunallocatedmemory. Yourmain()functionshouldcreateaMarkovGeneratorobject,createanifstream,opena file,thencalltheMarkovGenerator'sreadFile()functionwiththeifstreamastheargument. Forexample,ifyourfileconsistedofthestring"one fish two fish red fish blue fish",yourfoundWordsarraywouldholdfiveitems: word successors one [fish] two [fish] red [fish] blue [fish] fish [two, red, blue, one] Markovchainpt2 OnceyougettheMarkovGeneratorandMarkovWordsclassesfromthepreviousquestion workingcorrectly,it'stimetoactuallyusethemtogeneratenewtext. WriteanewfunctionfortheMarkovGeneratorclass stringgenerateText(intnumberOfWords) thatstartsoffbyreadingthefirstMarkovWordfromthefoundWordsarray.Writethat wordtoastring. PickonewordatrandomfromthatMarkovWord'ssuccessorarray.Addthiswordtothe string.ThenpickoneMarkovWordatrandomfromthisword'ssuccessorarray. Notethatifasuccessorwordoftenappearsafteraword,thatsuccessorwordwillbeinthe successorsarraymultipletimes.Thismeansthatyourprogramismorelikelytochoose thatwordwhengeneratingthenextword. RepeatthisprocessuntilyouhavegeneratedanumberofwordsequaltonumberOfWords. USETHEFILEemma.txtONCANVASASYOURINPUTFILEFORTESTING. Onceyouknowit'sworkingwell,tryitonatextfileofyourchoice.Uploadyourfavorite versionoftheresultstocanvas,withthefilenamemarkov.txt Markovchainpt3 Forlongerinputfilesyoucangetbetterresultsbyconsideringmultiplewordsthatappear sidebyside,thenfindingthewordthat'smostlikelytoappearafterthosewordsinorder. WriteanewversionofMarkovWordthatstores: *anarrayofnwords,representingthewindow. *asuccessorarrayofwordsthatappearafterthosewordswhenthosewordsappearin order. IrecommendgivingyournewversionofMarkovWordthefollowingprivatemember variables: string *word; string *successors; Ifourwindowwere2wordslongandourtesttextwere: It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, Oursetsofwordsandsuccessorswouldstartasfollows: [it, was] [the, the, the, the, the, the] [was, the] [best, worst, age, age, epoch, epoch] [the, best] [of] [best, of] [times] (andsoforth…) Usethisnewversiontogeneratetext,asinthepreviousversion.Ileavethe implementationdetailsforthisonetoyou. Testthisonwhateverfileyou'dlike.UploadtocanvasafilecalledbetterMarkov.txtwith yourfavoriteautogeneratedtexts.