Question: for this project, i can only manipulate the code below that is provided but i cannot change any of the code i can only add.

 for this project, i can only manipulate the code below thatis provided but i cannot change any of the code i canonly add. the search.cpp corresponds with the main code given above andi have provided the inputs for the code and the expected outputsfor the code. I need to be shown how to manipulate thesearch.cpp code so i can put the inputs and get the desiredoutputs. in C++14 please. /*search.cpp*/(unfinished code) #include #include #include #include using namespacestd; // // GetFileStats // // Returns the # of (key, value)pairs in the given file. Also returns the first (key, value) //

for this project, i can only manipulate the code below that is provided but i cannot change any of the code i can only add. the search.cpp corresponds with the main code given above and i have provided the inputs for the code and the expected outputs for the code. I need to be shown how to manipulate the search.cpp code so i can put the inputs and get the desired outputs. in C++14 please.

/*search.cpp*/(unfinished code)

#include #include #include #include

using namespace std;

// // GetFileStats // // Returns the # of (key, value) pairs in the given file. Also returns the first (key, value) // pair via the parameters firstKey and firstValue. // // NOTE: it is assumed the file contains at least one (key, value) pair, in this format: // // value key // value key // value key // # # // // where value and key are one word strings (or numbers that will be input as strings). // If the file cannot be opened, the program will be exited. // int GetFileStats(string filename, string& firstKey, string& firstValue) { // // Initialize return value / parameters: // firstKey = "?"; firstValue = "?"; int N = 0; // // TODO: open and read the (key, value) pairs from the file. The goal is // to simply count how many pairs there are and return this value N. Also, // we need to return the first (key, value) pair via the firstKey and // firstValue parameters; just assign to the parameters to "return" the // values. Don't forget to close the file when you're done. // return N; }

// // SearchForKey // // Opens the given file, searches for the given key, and if found, returns true; if the // key is not found then false is returned. // // If the key is found, the value will be returned via the "value" parameter; likewise // the rank will be returned via the "rank" parameter. The rank is simply the line # // where the (key, value) pair was found: 1 for first line, 2 for second line, etc. // If the key is not found, value and rank should be ignored. // // NOTE: it is assumed the file contains at least one (key, value) pair, in this format: // // value key // value key // value key // # # // // where value and key are one word strings (or numbers that will be input as strings). // If the file cannot be opened, the program will be exited. // bool SearchForKey(string filename, string key, string& value, int& rank) { // // initialize return value / parameters: // value = ">"; rank = 0; bool found = false; // not found: // // TODO: search for the key, and if found, we want to return the associated value. // But we also need to return the "rank" via the rank parameter; the rank is the // line number where the (key, value) appears: 1 for first line, 2 for second // line, and so on. Finally, return true if key was found, false if not. // // Don't forget to close the file when you're done.

return found; }

Summary: searching text files for (key, value) pairs, e.g. movies and their total revenue Google collects all sorts of interesting data: what words appear most frequently in searches? What web sites are most commonly searched using Alexa? What are the most popular baby names? For example, the data file "words-by-freq.txt" ranks the English words used most commonly in searches. Here's the start of the file 5627187200 the 3395006400 of 2994418400 and 2595609600 to The words are listed by rank, so "the" is the most frequently searched word with a frequency of 5627187200". The 2nd most frequently searched word is 'of, with a frequency of "3395006400", and so on. The file ends with # and # In general, we call this type of file a(key, value) file, since the data comes in pairs, and the "key uniquely identifies the "value". Note that the value is on the left, and the key is on the right. This implies you should view these types of files like this: value key value key value key Note that you should view the values and keys as strings-often the values are integers and the keys are strings, but it's dangerous to assume this is always true. Instead, treat all input data as strings, and use string variables In this exercise, you're going to write a complete C++ program that searches data from a (key, value) input file, outputting some statistics values, and ranks. The main0 program is written for you (and cannot be modified); your job is to implement the 2 functions in "search.cpp" that do the work of opening, inputting, and searching the input file. First, here's an example input sequence for the program words-by-freq.txt headache the meanwhile

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!