Question: CODE TO EDIT #include #include #include #include using namespace std; const int MAX_SIZE = 100; void printMenu() { cout < < Menu ; cout <

CODE TO EDIT

#include

#include

#include

#include

using namespace std;

const int MAX_SIZE = 100;

void printMenu() {

cout << "Menu ";

cout << "1: Print the array ";

cout << "2: Print the stats ";

cout << "3: Exit the program ";

}

void printArray(string arr[], int size) {

cout << "Array: ";

for (int i = 0; i < size; i++) {

cout << arr[i] << endl;

}

}

void printStats(int numRead, int numStored, int numDiscarded) {

cout << "Stats: ";

cout << "Text entries read: " << numRead << endl;

cout << "Text entries stored: " << numStored << endl;

cout << "Text entries discarded: " << numDiscarded << endl;

}

int getData(string arr[]) {

ifstream inputFile("input.txt");

if (!inputFile.is_open()) {

cout << "Error opening input file ";

return 0;

}

int count = 0;

string temp;

while (inputFile >> temp && count < MAX_SIZE) {

if (temp.length() > 3) {

arr[count] = temp;

count++;

}

else {

cout << "Text entry discarded: " << temp << endl;

}

}

if (inputFile.eof()) {

cout << "End of input file reached ";

}

else {

cout << "Input file too big for array ";

}

inputFile.close();

return count;

}

int main() {

string arr[MAX_SIZE];

int size = 0;

int numRead = 0, numStored = 0, numDiscarded = 0;

while (true) {

printMenu();

int choice;

cin >> choice;

if (cin.fail()) {

cin.clear();

cin.ignore(numeric_limits::max(), ' ');

cout << "Invalid input, please enter a number ";

continue;

}

switch (choice) {

case 1:

size = getData(arr);

numRead = MAX_SIZE;

numStored = size;

numDiscarded = MAX_SIZE - size;

printArray(arr, size);

break;

case 2:

printStats(numRead, numStored, numDiscarded);

break;

case 3:

cout << "Exiting program ";

return 0;

default:

cout << "Invalid choice, please try again ";

break;

}

}

return 0;

}

EDITS TO MAKE

use setw() to format output

do not mix setw() and '\t'; it could produce different results on different computers

Print the text entries and their length in a table format with headings; text entries should be left aligned and numerical entries should be right aligned; tip: use setw()

Display stats

the longest word and its length

the shortest word and its length

the count of the text entries stored

the total number of characters in all text entries

Print text entries in ascending order along with their length (use bubble sort)

Quit

Things that should be in the input file:

madison

apples

grapes

fruit

rocks

socks

gym

purple

finance

underwire

sprint

spray

sugar

snap

IT IS JUST A LIST OF RANDOM WORDS

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!