Directory Listing | |
---|---|
array_reference.cpp
|
|
getline.cpp
|
|
isstream.cpp
|
|
namelist.txt
|
|
numbers.txt
|
|
osstream.cpp
|
|
recordgen.c
|
|
result2.txt
|
|
result4.txt
|
|
student_info.cpp
|
|
sum.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
79
80
81
82
83
/*
* Name and Test Record Generator
*
* Description:
* Implements simple name generation with string concatenation and other
* things... Procedural generation ftw.
*
* This file has been modified to work along with Lab I for CS102.
* Used as an example to pseudo randomly generate names and test scores
* for the students to test their code with.
*
* Author:
* Clara Van Nguyen
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
const unsigned int MAX_TEST_COUNT = 12;
const unsigned int SYLL_COUNT = 64;
const char* syllable[] = { "ab" , "al", "ar", "az", "be",
"ca" , "cr", "cw", "da", "de",
"ed" , "fr", "ge", "go", "gr",
"ha" , "ij", "ja", "ka", "ke",
"la" , "le", "li", "ma", "me",
"mi" , "mo", "mu", "n" , "nn",
"oa" , "oe", "oo", "o" , "on",
"pa" , "pe", "pi", "po", "q" ,
"ra" , "re", "ri", "sa", "se",
"shi", "so", "su", "ss", "ta",
"te" , "ti", "to", "tu", "tt",
"u" , "v" , "wa", "we", "wo",
"xx" , "y" , "z" , "zz" };
char* gen_name() {
//Generates names with random number generator
//Calls malloc()! Be sure to free when done with string!
char* random_name = (char *) malloc(sizeof(char) * 32);
memset(random_name, 0, 32);
unsigned int i = 0;
for (; i < (rand() % 4) + 2; i++) {
strcat(random_name, syllable[rand() % SYLL_COUNT]);
}
//Ensure the first letter is capital
random_name[0] += 'A' - 'a';
return random_name;
}
main(int argc, char** argv) {
//Parse arguments
if (argc == 1) {
fprintf(stderr, "Usage: namegen num\n");
return 0;
}
srand(time(NULL));
unsigned int i = 0,
r = atoi(argv[1]),
a, n;
//Generate names and scores
for (; i < r; i++) {
char* firstname = gen_name(),
* lastname = gen_name();
printf("%s %s", firstname, lastname);
n = rand() % MAX_TEST_COUNT;
for (a = 0; a < n; a++) {
//Ensure the score is a decimal number between 0 and 100.
printf(" %g", (double)(rand() % 100) + ((rand() % 100) * .01));
}
printf("\n");
//Free memory
free(firstname);
free(lastname);
}
//Have a nice day.
return;
}