Write a program in C++ and please do ***procedural code*** and the header can not conatin ".h"
Please add comments to all the functions/processes so I know what is going on! THANK YOU!
Write a program in c++ that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file is (using the example from the lectures):
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 thatuse 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 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.
****************Training Set:
ant: a -> n, n -> t, t -> \0 (end of word)
bat: b -> a, a -> t, t -> \0
base: b -> a, a -> s, s -> e, e -> \0
best: b -> e, e -> s, s -> t, t -> \0
east: e -> a, a -> s, s -> t, t -> \0
nest: n -> e, e -> s, s -> t, t -> \0
sane: s -> a, a -> n, n -> e, e -> \0
tab: t -> a, a-> b, b -> \0
ten: t -> e, e-> n, n -> \0
teen: t -> e, e-> e, e -> n, n -> \0
First letters
|
a
|
b
|
e
|
n
|
s
|
t
|
Number
|
1
|
3
|
1
|
1
|
1
|
3
|
Transitions
|
a
|
b
|
e
|
n
|
s
|
t
|
\0
|
a
|
|
1
|
|
2
|
2
|
1
|
|
b
|
2
|
|
1
|
|
|
|
1
|
e
|
1
|
|
1
|
2
|
2
|
|
2
|
n
|
|
|
2
|
|
|
1
|
2
|
s
|
1
|
|
1
|
|
|
3
|
|
t
|
1
|
|
2
|
|
|
|
5
|