Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ code Please read all the instructions. no global variables Goal: Your assignment is to write a C++ program to read in a file of

c++ code Please read all the instructions. no global variables

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Goal: Your assignment is to write a C++ program to read in a file of English text, find and count the palindromes1, as well to count the occurrences of specific words (conjunctions). This assignment will allow you to practice working with arrays and strengthen your ability to work with files and strings FOR AND NOR BUT OR YET SO 878 4772 29 450 351 69 453 Program Output: The text for the book A Tale of Two Cities was copied into a file called "2city10.txt". A solution to this assignment was run using this file. The following screenshot shows what your program should output when this Tile is specified 2889 1452 As you can see, the program first outputs how many occurrences there are of the conjunctions2 in the file. Then i outputs each of the palindromes found in file along with how many of each of them was found 4 XIX Xx DID EYE 129 29 Implementation using arrays: This lab assignment gives you the opportunity to practice using arrays As you read through the words in the text, you will use: SEES Two parallel arrays, one of 100 strings and one of 100 size ts. ANNA Both arrays' elements are initialized as empty (empty string for the string array, 0 for the size t array). As you read the file and find:a palindrome, you first check if the palindrome is already in the array of strings, if it is, then you increment the count of that palindrome in the LEVEL REFER 6 6 EKE EVE PEEP DEED NOON size t parallel array. If the palindrome you found is not in the array, you add it to the array (in upper case letters). Be careful not to add more than 100 palindromes, since that is the maximum number of palindromes your array can hold SEXES Two parallel arrays, one of the conjunction words that you must declare like this: const string CONJUCTIONS[] = {"FOR", "AND", "NOR", "BUT", "OR", "YET", "So"); The other is an array of size t that must have the same amount of elements as the CONJUNCTIONS array, the initial value of each element is 0. Each element of this array represents the occurrences of the corresponding conjunction word. Functions vou need to write: 1)A function called IsPalindrome that takes in a string parameter, and it returns true if the parameter is a palindrome word, and false otherwise. 2)A function called PrintpalindromeCount that takes an array of strings that stores the found palindromes, an array of size t that stores the counts of each of those palindromes and the number of palindromes found. The function does not return anything, it only prints the formatted table of palindromes counts on the screen 3)A function called ToUpper that takes in a string and converts it into all capital letters, returns the new string 4)A function called IsPalindromeInArray, it receives a string that holds the palindrome you are searching for, the array of palindromes and the size of this array. The function returns the position of the palindrome in the array, if the palindrome is not found, the function returns -1. 5) A function called Countword, it takes the word that was just read from file, the array of conjunctions, the array of count of conjunctions, and the size of these arrays. Since they are parallel arrays, both have the same size. This function checks if the word is a conjunction, if it is then it finds its position in the array, and increments its count in the counts parallel array. 6) A function called PrintwordCount, it receives the array of conjunctions, the array of counts of conjunctions, and the size of these arrays. It prints out the table of conjunctions with their respective counts Main Program The main program will get the name of the file from the command line using its parameters argc and argv,. You will open that file for input. If the file is not successfully opened, you will print an informative error message and exit the main program. Remember to use cerr to display error messages Next you declare all the needed arrays and variables and initialize them You will then begin reading through the file word by word. You will then count that word using the Countword function, then you will check if it is a palindrome and if it is, and it is a new one you will add it to the palindromes array and increment its count in the palindrome count array. If the palindrome word is already in the array, you will increment the correspondent position in the count array. After you finish reading through the file, you will of course close the file. Then call your first print routine to print the conjunctions count. Next call the second print routine that will show the palindromes found and their count When you design your functions: Make sure that all object parameters are passed by reference. In other words, if you are passing a string object or a stream object, pass by reference . If don't intend for your function to modify an object or array parameter, place const keyword before the parameter. The compiler will then make sure you do not accidentally modify that parameter. In this lab many, but not all, of the object and array parameters of the functions described above should be declared const. Here is some guidance specific to this lab: Declare the array ofconjunctions as const string CONJUNCTIONS[] = { the declaration at the beginning of this document 1) };-check 2) For the parallel arrays, you should not specify the size when you define the array of specific words. Let Ccount it for you based on the list of words you initialize it with. Then use sizeof.()/sizeof(first element of array) when you specify the size of the count array. Variables should be given descriptive names that start with a lowercase letter and obey the camelCase convention Functions should be given descriptive names that start with an uppercase letter and obey the CamelCase convention. First word of a function name typically should be a verb. Don't use global variables. Global variables sometimes are appropriate, but not in the assignments we will be giving this quarter

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

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions

Question

Do not get married, wait until I come, etc.

Answered: 1 week ago

Question

Discuss all branches of science

Answered: 1 week ago