Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PUT THIS INFORMATION IN THE CODE I NEED THAT ADDED TO MY CODE Display in stats I need this added to the stats sections -

PUT THIS INFORMATION IN THE CODE I NEED THAT ADDED TO MY CODE

Display in stats

I need this added to the stats sections

- 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

HI YOU NEED TO ADD THE TOP INFORMATION TO MY CODE PLEASE

I KEEP PUTTING THIS ON CHEGG AND THEY AREN'T ANSWERING CORRECTLY ADD THE TOP INFORMATION TO MY CODE PLEASE

#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;

}

Input.txt

Rice Chicken Spam Food Apricots Alphabet Starbucks Treats Topanga Vanilla Zebra Tigers Danger Toxic food Strange

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago