Repository navigation
Expand file tree
/
Copy pathtestInputGenerator.cpp
More file actions
74 lines (63 loc) · 1.99 KB
/
Copy pathtestInputGenerator.cpp
File metadata and controls
74 lines (63 loc) · 1.99 KB
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
//============================================================================
// Name : testInputGenerator.cpp
// Author : Hasan Sozer
// Version : 3.0
// Update : use of srand instead of rand for randomization
// Copyright : (c) 2012 Ozyegin University
// Usage : testInputGenerator T k N r
// Parameters :
// T (algorithm type) : 1 or 2
// k (selection index): an integer between 0 and N
// N (input size) : an integer greater than 0
// r (input range) : an integer greater than 0
//============================================================================
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int algorithmType = 0;
int selectionIndex = 0;
int inputSize = 0;
int inputRange = 0;
void printUsage() {
cout << endl << "Usage:" << endl;
cout << "testInputGenerator T k N r" << endl;
cout << endl << "Parameters:" << endl;
cout << "T (algorithm type) : 1, 2, 3 or 4" << endl;
cout << "k (selection index) : an integer between 0 and N" << endl;
cout << "N (input size) : an integer greater than 0" << endl;
cout << "r (input range) : an integer greater than 0" << endl;
}
int parseArguments(int count, char *argList[]) {
if (count != 5) {
cout << "ERROR: Wrong amount of parameters!" << endl;
return -1;
}
algorithmType = atoi(argList[1]);
selectionIndex = atoi(argList[2]);
inputSize = atoi(argList[3]);
inputRange = atoi(argList[4]);
if ((algorithmType < 1 || algorithmType > 4) ||
(inputSize < 1) ||
(inputRange < 1) ||
(selectionIndex < 0) ||
(selectionIndex > inputSize)) {
cout << "ERROR: Wrong value(s) of parameters!" << endl;
return -1;
}
return 0;
}
int main(int argc, char *argv[]) {
if (parseArguments(argc, argv) < 0) {
printUsage();
return -1;
}
cout << algorithmType << endl;
cout << selectionIndex << endl;
cout << inputSize << endl;
srand(time(NULL));
for (int var = 0; var < inputSize; var++) {
cout << rand() % inputRange << endl;
}
return 0;
}