-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab_10.cpp
78 lines (60 loc) · 1.24 KB
/
Lab_10.cpp
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
70
71
72
73
74
75
76
77
78
// Lab11.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include <stdlib.h>
#define X 2000
char getRandomLowercaseLetter()
{
return (rand() % (26)) + 97;
}
void initialiseArray(int array[], int len)
{
for (int i = 0; i < len; i++)
{
array[i] = 0;
}
}
int main()
{
int frequency[26];
int scaledFrequency[26];
int min = X;
int max = 0;
int minScale = 0;
int maxScale = 40;
char letter;
initialiseArray(frequency, 26);
for (int i = 0; i < X; i++)
{
letter = getRandomLowercaseLetter();
frequency[letter - 97] += 1;
}
for (int i = 0; i < 26; i++)
{
if (frequency[i]>max)
{
max = frequency[i];
}
if (frequency[i]<min)
{
min= frequency[i];
}
}
int m = (max - min) / (40);
for (int i = 0; i < 26; i++)
{
scaledFrequency[i] = ((maxScale - minScale )* (frequency[i] - min) / (max - min))+minScale;
}
printf("Num Throws = %d , Max Freq = %d , scale = %d - %d \n", X, max, minScale, maxScale);
for (int i = 0; i < 26;i++)
{
printf("%c\t %d \t", 97 + i, frequency[i]);
for (int j = 0; j < scaledFrequency[i]; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}