Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4- You are working for a client who has come into possession of an encrypted message that they need to be able to read. The

4- You are working for a client who has come into possession of an encrypted message that they need to be able to read. The document appears to be a string of numbers rather than letters. The first step towards cracking the code is to count how frequently each number appears in the document.

(a) Fill in the following two functions to accomplish this:

Parameters: either an open filestream or the name of a valid input file, countArray should be an integer array which will hold the count performed by the function.

Precondition: a file containing a string of integers is accessible by the function. The range of values in the file should be the same as the size of countArray and countArray should be initialized to zeros. Filestream should be open.

Postcondition: countArray will be loaded with counts of each different integer that appears in the input file. So if the number 15 appears 20 times then countArray[15] should equal 20. If a number does not appear in the file then the value at its index should be 0. Filestream should be open if a stream was passed and closed if a name was passed.

Return: false if the file cannot be read, if improper parameters have been passed to the function, or if the count cannot be performed. True otherwise.

bool countIntegers(ifstream file, int * countArray);

bool countIntegers(string fileName, int * countArray);

(b) After the countIntegers functions has run, we will have an array loaded with the total occurrences of each number in the file. The next step in our frequency analysis of this file is to determine which number occurs the most frequently. To do this we need a function that looks at an array and determines the index of the biggest value in the array. Select one of the following functions and implement it in order to accomplish this:

//this function takes an array as input and returns the index of the largest value

int findMostCommon(int * countArray, int size);

//this function takes an array and an integer as input then sets the integer to the index of the

//largest value in the array.

void findMostCommon(int index, int * countArray, int size);

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here's what is inside the text file that I am supposed to used for this code.

"lab8_cipherText.txt" :

18 19 17 5 18 13 23 5 18 13 23 16 5 18 8 9 18 24 13 22 9 19 10 13 24 23 9 16 10 9 0 9 22 3 17 5 18 13 23 5 20 13 9 7 9 19 10 24 12 9 7 19 18 24 13 18 9 18 24 5 20 5 22 24 19 10 24 12 9 17 5 13 18 13 10 5 7 16 19 8 6 9 1 5 23 12 9 8 5 1 5 3 6 3 24 12 9 23 9 5 9 25 22 19 20 9 13 23 24 12 9 16 9 23 23 5 23 1 9 16 16 5 23 13 10 5 20 22 19 17 19 18 24 19 22 3 1 9 22 9 5 23 1 9 16 16 5 23 13 10 5 17 5 18 19 22 19 10 24 12 3 10 22 13 9 18 8 23 19 22 19 10 24 12 13 18 9 19 1 18 1 9 22 9 5 18 3 17 5 18 23 8 9 5 24 12 8 13 17 13 18 13 23 12 9 23 17 9 6 9 7 5 25 23 9 13 5 17 13 18 0 19 16 0 9 8 13 18 17 5 18 15 13 18 8 5 18 8 24 12 9 22 9 10 19 22 9 18 9 0 9 22 23 9 18 8 24 19 15 18 19 1 10 19 22 1 12 19 17 24 12 9 6 9 16 16 24 19 16 16 23 13 24 24 19 16 16 23 10 19 22 24 12 9 9 18 19 17 5 18 13 23 5 18 13 23 16 5 18 8 6 3 14 19 12 18 8 19 18 18 9

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions