1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
//Ryan Vasichko - 1043181
//Assignment 6
#include <cstdlib>
#include <cmath>
#include <iostream>
using namespace std;
void generateArray(char charArray[], int size, int seed);
void displayArray(char charArray[], int size);
void calculateLetterCount(char charArray[], int charCount[], int size);
void displayLetterCount(int charCount[], int size);
int main() {
int size, seed, charCount[26] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char charArray[100];
cout << "Seed number: " << "\n";
cin >> seed;
cout << "\n" << "Array size: " << "\n";
cin >> size;
cout << "\n";
generateArray(charArray, size, seed);
displayArray(charArray, size);
cin.get();
calculateLetterCount(charArray, charCount, size);
displayLetterCount(charCount, size);
cin.get();
}
void generateArray(char charArray[], int size, int seed) {
int count = 0;
char arrayHelper[52] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
while(count++ < size) {
charArray[count] = arrayHelper[rand() % 52]; }
}
void displayArray(char charArray[], int size) {
int count = 0;
while(count++ < size) {
cout << charArray[count];
}}
void calculateLetterCount(char charArray[], int charCount[], int size) {
int a = 0, b = 0, c = 1;
char upperCase = 'A', lowerCase = 'a';
do {
do {
if(charArray[a] == upperCase++ || lowerCase++)
charCount[b++]++;}
while(c++ < 26);
upperCase = 'A', lowerCase = 'a', b = 0, c = 0;}
while(a++ < size);
a = 0; }
void displayLetterCount(int charCount[], int size) {
char character = 'A';
int count = 0;
cout << "\n";
do {
cout << character++ << ": " << charCount[count] << "\n"; }
while(count++ < 25);
character = 'A'; }
|