Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help on C++ program please!!! Lab Assignment: 1. You will generate all of t

ID: 3703681 • Letter: N

Question

need help on C++ program please!!!

Lab Assignment: 1. You will generate all of the code for this assignment, so begin by creating a new project with your driver file named 'main.cpp.' Then add functions that allow vou to read and write strings from/to a file. 2. Then, take the words that you read in from the example.txt that was provided in the repo and tally the strings in the file by inserting those strings into a map object. Here, the string part of the map will be the individual words read in from the file, and the int portion of the map is the number of times the string part has been inserted in the map. (Hint: figure out what the statement ++tally[item]; does when tally is a map and item is a string) Behind the scenes, the map container stores objects in a balanced binary search tree(research what it means for a tree to be balanced). The map iterator uses an inorder traversal to step through the tree objects, so the objects accessed by the iterator are encountered in sorted order. Think back to last lab and the three different traversal methods we discussed(pre/post/inorder) 3. Iterate through the tally map and write each string the correct number of times to the output file named output.txt. This means that the size of the output file will be the exact same as the input file but the words in output.txt will be sorted.

Explanation / Answer

#include using namespace std; //Read Function void read_file(map &m) { ifstream file; file.open("file_name.txt"); if(!file.is_open()) return; string word; while(file >> word) { m[word]++; } file.close(); } //writeFunction void write_file(map&m) { ofstream file; file.open("output.txt"); for(map::iterator it = m.begin(); it != m.end(); it++) { int i = it->second; while(i>0) { file2