akIskwiF
IwoPdkqA <-- this part of the program is done
Beidbdmc
the second output (frequency) will be:
a=2
b=2
c=1
d=3
e=1
f=1
g=0
and so on.
I separated the letter increments from the actual frequency count function. So there is a separate function doing the frequency and the output from this function is placed on the 'output' function. So the syntax of the cout portion of the output function (in theory), is:
Expand|Select|Wrap|Line Numbers
- cout<<ch<<" = "<<(cntChar freq. for each letter)<<endl;
Oh well just run the code below to see what I'm talking about. Judging by what I have done though, the problem is referencing the values of the array to the cntChar function (for it to work) and transporting the frequency value of each letter to the output function. I'll find some solutions to this but for the meantime this is it. Thank you very much.
Expand|Select|Wrap|Line Numbers
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- const int size = 100;
- char val(int& length, int& seed);
- int inLgth(int& length, int& seed);
- int output(char& input);
- int main(){
- char a[size], input, ch;
- int seed, length, i;
- bool repeat = false;
- cout<<"Enter the seed number: ";cin>>seed;
- cout<<endl;
- do{
- inLgth(length, seed);
- output(input);
- system("cls");
- } while(input == 'y' || input == 'Y');
- if (input != 'y' || input != 'Y') exit(1);
- system ("pause");
- return 0;
- }
- int inLgth(int& length, int& seed){
- char a[size];
- cout<<"Number of characters: ";cin>>length;
- cout<<endl
- <<"Generated characters:"<<endl<<endl;
- a[size] = val(length, seed);
- cout<<endl;
- return a[size];
- }
- char val(int& length, int& seed) {
- int i;
- srand(seed);
- for (i = 1; i <= length; i++){
- if(i%10==0)cout<<endl;
- char num = rand() % 52;
- if (num < 26) {
- num += 'a';
- } else {
- num -= 26;
- num += 'A';
- }cout<<num;
- }cout<<endl;
- }
- int cntChar( char a[size] , char& ch, int& length ){
- int cntCh = 0;
- for (int i = 0; i<=length; i++){
- if ( a[size] == ch )
- cntCh += 1;
- }
- return cntCh;
- }
- int output(char& input){
- char str, ch, cntCh;
- cout<<"Summary for the characters:"<<endl<<endl;
- for(ch='a';ch<='z';ch++){
- cout<<ch<<" = "<<cntCh<<endl;
- }
- cout<<endl
- <<"Repeat? (same seed) (Y/N) ";cin>>input;
- return input;
- }