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...

1 answer below »


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


Answered Same DayApr 27, 2021

Answer To: Write a program in C++ and please do ***procedural code*** and the header can not conatin ".h"...

Ria answered on Apr 28 2021
136 Votes
output.txt
a e m r s t
1 1 2 1 2 3
a e m r s t
a 0 0 3 1 0 5
e 5 0 0 0 0 1
m 1 2 0 0 0 0
r 1 1 0 0 0 0
s 0 1 0 0 0 1
t 1 5 0 1
0 0
output2.txt
a b e n s t
1 3 1 1 1 3
a b e n s t
a 0 1 0 2 2 1
b 2 0 0 0 1 0
e 1 0 0 2 1 0
n 0 0 2 0 0 1
s 1 0 1 0 0 3
t 1 0 2 0 0 0
WordTransition.cpp
#include
#include
#include
#include
using namespace std;
// 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
int main()
{
    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
    ifstream input;
    ofstream output;
    string filename, out_filename, line;
    char c1, c2;
    int count, letter_count, word_count;
    int i, j, k, l;
    int iteration;
    cout << "Enter iteration: ";
    cin >> iteration;
    while...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here