Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read the entire question!! The other answers on chegg do not work, so please do not just copy and paste it! Write a procedural

Please read the entire question!! The other answers on chegg do not work, so please do not just copy and paste it!

Write a procedural C++ program that generates random words from a training set. Do not hard-code the training set! Read it from a file. A suggested format for the input file is

6

a e m r s t

10

ate

eat

mate

meet

rate

seat

stream

tame

team

tear

Here are some suggestions for constants, array declarations, and helper functions (note that use of global variables will be heavily penalized):

#include

#include

#include

#include

#include

using namespace std;

const int SIZE = 27; // 26 chars + 1

const int WORDSIZE = 25; // max word size

// read from input file

char cArray[SIZE]; // array of characters in set

char tArray[SIZE][SIZE]; // training array

//constructed by your program

int firstChars[SIZE]; // array of first character multiplicities

int transArray[SIZE][SIZE]; // transition array of multiplicities

char word[WORDSIZE]; // word being built

// helper functions

int getRandom(int); // get next random integer

int getIndex(char [SIZE], char); // get index of char in cArray

char getChar(char [SIZE], int); // get char at index in cArray

Be sure to seed the random number generator with the current time (ONCE) before using the rand() function:

srand(time(NULL)); // seed random number generator

Prompt the user for the name of the input file and the number of iterations (this program will run forever without this limit!). Either prompt the user for the name of the output file, or inform the user of the name before exiting.

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

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions