Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the code for the left side, but need some adjust to meet the requirements for the right side. #include #include #include #include #include

I have the code for the left side, but need some adjust to meet the requirements for the right side.

image text in transcribed

#include #include #include #include #include #include

using namespace std;

string alphabetizeAndCapitalize(const string& input); void initCounts(unsigned int counters[], unsigned int n); void countWord(const string& word, unsigned int counters[], unsigned int n, unsigned int& counterForLonger); void countSpecialWord(const string& word, const string specialWords[], unsigned int counters[], unsigned int n); void printLengthStats(const unsigned int counters[], unsigned int n, unsigned int counterForLonger, unsigned int total); void printSpecialWordsStats(const string specialWords[], const unsigned int counters[], unsigned int n, unsigned int total);

int main(int argc, char* argv[]) { const unsigned int MAXIMAL_LENGTH_TO_COUNT = 12; unsigned int counters[MAXIMAL_LENGTH_TO_COUNT]; unsigned int counterForLonger = 0; unsigned int totalWords = 0; const string GOD_WORDS[] = {"GOD", "JESUS", "CHRIST", "HOLY", "SPIRIT" }; const unsigned int GOD_WORDS_COUNT = sizeof(GOD_WORDS) / sizeof(string); unsigned int countersForGodWords[GOD_WORDS_COUNT];

const string ARTICLE_WORDS[] = {"A", "AN", "THE"}; const unsigned int ARTICLE_WORDS_COUNT = sizeof(ARTICLE_WORDS) / sizeof(string); unsigned int countersForArticleWords[ARTICLE_WORDS_COUNT];

// Ask user for file name, try to open it. string fileName; cout > fileName; ifstream inputFile(fileName.c_str()); if (!inputFile) { cout

// Initialize arrays of counters initCounts(counters, MAXIMAL_LENGTH_TO_COUNT); initCounts(countersForGodWords, GOD_WORDS_COUNT); initCounts(countersForArticleWords, ARTICLE_WORDS_COUNT);

// Read and count words string input; while (inputFile >> input) { string word = alphabetizeAndCapitalize(input); if (word.length() > 0) { totalWords++; countWord(word, counters, MAXIMAL_LENGTH_TO_COUNT, counterForLonger); countSpecialWord(word, GOD_WORDS, countersForGodWords, GOD_WORDS_COUNT); countSpecialWord(word, ARTICLE_WORDS, countersForArticleWords, ARTICLE_WORDS_COUNT); } } inputFile.close();

// Print stats printLengthStats(counters, MAXIMAL_LENGTH_TO_COUNT, counterForLonger, totalWords); cout

return 0; }

string alphabetizeAndCapitalize(const string& input) { string output = "";

for (unsigned int i = 0; i (input[i]); if (isalpha(c)) { output += static_cast(toupper(c)); } }

return output; }

void initCounts(unsigned int counters[], unsigned int n) { for (int i = 0; i

void countWord(const string& word, unsigned int counters[], unsigned int n, unsigned int& counterForLonger) { if (word.length() > n) { counterForLonger++; } else { counters[word.length() - 1]++; } }

void countSpecialWord(const string& word, const string specialWords[], unsigned int counters[], unsigned int n) { for (unsigned int i = 0; i

void printLengthStats(const unsigned int counters[], unsigned int n, unsigned int counterForLonger, unsigned int total) { cout

void printSpecialWordsStats(const string specialWords[], const unsigned int counters[], unsigned int n, unsigned int total) { cout Goal: Your assignment is to arite a C+progam to rend in a file of English text, and derermine the mber of occnrences of each lettencharacter on the file Additionlly yon will count bow many times twie are cutan wal ds (allicks). This assignmail will allow you to peactoe eking with aays ad reintore your proticcncy work ng with files. Gnal: Your assignment is so write ? C+in gram to rend in file af English text. md drennine the length disburion of words in the text as well as counr the occunenes of specific words. This assiznment will allow yon to practice working with atays Output: The lext for The Message translation of Jean I was ccpied into a fil? called "joan l_nir.txt." Footnote 25 was nn usingile. The toowig ereer sbows wa your progtm The lexl loc On Fallet aul A Tile a?Iwu Ciues was copad ita files er" and "ciryla tr" My soution to this assignment was run using these files. The following screenshot slhows what your program should output when Our Farher file is 185 grnn should d ontp wbe this file i 61 60 As you can se it bas cue te umber ofwords of enchlegh, to 12 chaers log Ir aso counts te mmber of words that are over 12 characters long. I As yon can see it hsr ted the mmber occuences of cach of the chsacters found n fle Nole lt it ws the claacder comnded its ASCII code, its couat aud its elative the pmgram ?0'rted the cocurrences of the articles A, AN and THEN, showimg also the relative percentage tor ech of these threse nght o te actual count In addlition, it has comnted the amber of times rao This lab assignmentves you the opport nity to practice using anays. As you read tluongh the charactes in the text you will ase one anay (a 1Lay of 256 eleuents) to couut the nuber of cach chauacter, and you will se oue set of paiallel aay to couut de ber of oceurences of the article using clys. As you reand through the woeds in the texi ccunt the number of werds of ench length, nd you will use two sets of paallel ays to count the eamber of ot you need to write: 1) ? finetan that takes 1 string read from the file as a aud with alL lelfers coaverted to upptcae. NOTE: lo dus co you wll wacil to use Bu1 there LS ? stnall w2nukle Lie 'est tile was copied fiou be interuet aud it contains some &-bit ASCII chamcters. Iyoectype functicus directly.g ill get an assam. Yc shldcast ter vale to msigned char irst betore passing to tie cctype> function. Use tatic castunsigned char> 2) A function that takes a count anny and the number of elements in this anmy as paaerers, and sets all 2) A function that takes ? word. ccout art ay, the iniller of elements uitle art ay, anoa reference lo"?.meter fot 'he co"nt of wotals w ith le"?11 kmiset llat '1K size. This ''Detes w.u Functions you need to witte: Yon are to nrite the l even functions for your zsin ogrtu to call Takes a file. be aray of size thax repcesents the count of altbough the size is was 216. RemrDs the mamber of Enerelt et! lhe 3ppie,priate coint depending on the ten 'li of the wuxd. Note that this ti'????" will not he callod with a zo-leneth wd, bacause yauops ipore these woeds, bat becmase yon are a goodprogryou wil inelade an nssert statemcnt to make sue is not called with anepy w 3) A filleton dal lakes word, all attay of spectal words. pilallel altay ?[evutils, and the uamber of elements in the aay as te The fanetion will update the sppropriane ccant if the word imatches one of the wordk in the array of soccial words. Takes?nle.?set ot'pannel anays (2), one that represents repre sets teauticles. ad the size of esea Ramembar s s a e ef parallel anhy ae A fmction that talkes a count auny the unber lements in the amay, the cont of loneT capitalized leters. This ficticu will be sed to cempce with the cticle words that are capitalizec A ton thei takes a spec wod ay. the puleont stuny. thebeelesu he arrays, and the totnl mber of words ithe file. This fimction writes the results to cout the tabe. The able las the followi olns Main Program ibe inmi propian instpoolp te user to etter ? file name You will opet that file tot uput It the file is ot suecesyp yoa will t a inowative eomessnge d exit tha with ASCII code 10. instead od prizrnz tb invisible cluepcia LF. and it the chaca Ascil code i13 cout static castschar (S5 endl; Next you will init lize ll count atays to zeo using the tinction described above. Yon wil then bepio reading through the file word by woed. Yowil call you fuctiT conmalize the word yo read. In soe cases. you may ind ta thete is nothn lett in teword because it a umber of coutsins only punctaatio I hat case, y will ot try to comnt that Yon y write addition ctTite the aforenretitioned functions Far womb that are l character ?' longer, you should can the first count fucion to cont it by leugt The yo will call the secccxd count Euctiotwice, oforeach rop of specitic words. The main program fiist prompts the user to emer a file nie. Yoa will open thatfle for inpu. If Maim the file is ot successfully opened y will print an informative enor message axd exi the ain Afrer you finish readine throngh the file, youwillouse close the file. Tben call yoar first print roatine to print out the distribation of vword lengths as shown i he screen sho Next call the second print routiae twice to ptint cut the occurrences of each group of ecific words Of You will ebeading luug the lile clcle by hag yuur Countcharacters uacion Atheandsy will ead the tile agnin, sing ur CountArticles fimcticn, tean the beuinming, word by word this time,to ct the auticle weds, retnenlber to chsme each wod t you cad to epita letmers. After you finish readine though the file, yon ill of oouse clase the file. Finaly yon will call your WritecharacterCount amdWritearticlecount fanctiees to urout the tables Goal: Your assignment is to arite a C+progam to rend in a file of English text, and derermine the mber of occnrences of each lettencharacter on the file Additionlly yon will count bow many times twie are cutan wal ds (allicks). This assignmail will allow you to peactoe eking with aays ad reintore your proticcncy work ng with files. Gnal: Your assignment is so write ? C+in gram to rend in file af English text. md drennine the length disburion of words in the text as well as counr the occunenes of specific words. This assiznment will allow yon to practice working with atays Output: The lext for The Message translation of Jean I was ccpied into a fil? called "joan l_nir.txt." Footnote 25 was nn usingile. The toowig ereer sbows wa your progtm The lexl loc On Fallet aul A Tile a?Iwu Ciues was copad ita files er" and "ciryla tr" My soution to this assignment was run using these files. The following screenshot slhows what your program should output when Our Farher file is 185 grnn should d ontp wbe this file i 61 60 As you can se it bas cue te umber ofwords of enchlegh, to 12 chaers log Ir aso counts te mmber of words that are over 12 characters long. I As yon can see it hsr ted the mmber occuences of cach of the chsacters found n fle Nole lt it ws the claacder comnded its ASCII code, its couat aud its elative the pmgram ?0'rted the cocurrences of the articles A, AN and THEN, showimg also the relative percentage tor ech of these threse nght o te actual count In addlition, it has comnted the amber of times rao This lab assignmentves you the opport nity to practice using anays. As you read tluongh the charactes in the text you will ase one anay (a 1Lay of 256 eleuents) to couut the nuber of cach chauacter, and you will se oue set of paiallel aay to couut de ber of oceurences of the article using clys. As you reand through the woeds in the texi ccunt the number of werds of ench length, nd you will use two sets of paallel ays to count the eamber of ot you need to write: 1) ? finetan that takes 1 string read from the file as a aud with alL lelfers coaverted to upptcae. NOTE: lo dus co you wll wacil to use Bu1 there LS ? stnall w2nukle Lie 'est tile was copied fiou be interuet aud it contains some &-bit ASCII chamcters. Iyoectype functicus directly.g ill get an assam. Yc shldcast ter vale to msigned char irst betore passing to tie cctype> function. Use tatic castunsigned char> 2) A function that takes a count anny and the number of elements in this anmy as paaerers, and sets all 2) A function that takes ? word. ccout art ay, the iniller of elements uitle art ay, anoa reference lo"?.meter fot 'he co"nt of wotals w ith le"?11 kmiset llat '1K size. This ''Detes w.u Functions you need to witte: Yon are to nrite the l even functions for your zsin ogrtu to call Takes a file. be aray of size thax repcesents the count of altbough the size is was 216. RemrDs the mamber of Enerelt et! lhe 3ppie,priate coint depending on the ten 'li of the wuxd. Note that this ti'????" will not he callod with a zo-leneth wd, bacause yauops ipore these woeds, bat becmase yon are a goodprogryou wil inelade an nssert statemcnt to make sue is not called with anepy w 3) A filleton dal lakes word, all attay of spectal words. pilallel altay ?[evutils, and the uamber of elements in the aay as te The fanetion will update the sppropriane ccant if the word imatches one of the wordk in the array of soccial words. Takes?nle.?set ot'pannel anays (2), one that represents repre sets teauticles. ad the size of esea Ramembar s s a e ef parallel anhy ae A fmction that talkes a count auny the unber lements in the amay, the cont of loneT capitalized leters. This ficticu will be sed to cempce with the cticle words that are capitalizec A ton thei takes a spec wod ay. the puleont stuny. thebeelesu he arrays, and the totnl mber of words ithe file. This fimction writes the results to cout the tabe. The able las the followi olns Main Program ibe inmi propian instpoolp te user to etter ? file name You will opet that file tot uput It the file is ot suecesyp yoa will t a inowative eomessnge d exit tha with ASCII code 10. instead od prizrnz tb invisible cluepcia LF. and it the chaca Ascil code i13 cout static castschar (S5 endl; Next you will init lize ll count atays to zeo using the tinction described above. Yon wil then bepio reading through the file word by woed. Yowil call you fuctiT conmalize the word yo read. In soe cases. you may ind ta thete is nothn lett in teword because it a umber of coutsins only punctaatio I hat case, y will ot try to comnt that Yon y write addition ctTite the aforenretitioned functions Far womb that are l character ?' longer, you should can the first count fucion to cont it by leugt The yo will call the secccxd count Euctiotwice, oforeach rop of specitic words. The main program fiist prompts the user to emer a file nie. Yoa will open thatfle for inpu. If Maim the file is ot successfully opened y will print an informative enor message axd exi the ain Afrer you finish readine throngh the file, youwillouse close the file. Tben call yoar first print roatine to print out the distribation of vword lengths as shown i he screen sho Next call the second print routiae twice to ptint cut the occurrences of each group of ecific words Of You will ebeading luug the lile clcle by hag yuur Countcharacters uacion Atheandsy will ead the tile agnin, sing ur CountArticles fimcticn, tean the beuinming, word by word this time,to ct the auticle weds, retnenlber to chsme each wod t you cad to epita letmers. After you finish readine though the file, yon ill of oouse clase the file. Finaly yon will call your WritecharacterCount amdWritearticlecount fanctiees to urout the tables

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions

Question

4. Why does transfer matter?

Answered: 1 week ago

Question

What is management growth? What are its factors

Answered: 1 week ago