-
Notifications
You must be signed in to change notification settings - Fork 3
/
sample.cpp
70 lines (54 loc) · 1.68 KB
/
sample.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
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main() {
srand(static_cast<unsigned>(time(NULL)));
int n, q;
cout << "\nWELCOME TO RANDOM QUESTION ASSIGNING TO GROUPS WHICH WILL SHOW STUDENT'S ASSIGNED QUESTION IN GROUPS OF FIVE\n";
cout << "\nHow many students: ";
cin >> n;
string arr[n];
for (int i = 0; i < n; i++) {
cout << "Enter Student " << i + 1 << " Name: ";
cin >> arr[i];
}
label:
cout << "\nHow many questions are there? : ";
cin >> q;
if (q <= 0) {
cout << "\nPlease input a positive number of questions.\n";
goto label;
}
int que[q];
for (int i = 0; i < q; i++) {
que[i] = i + 1;
}
for (int i = 0; i < n / 5; i++) {
cout << "\n__________________________________________________________________\n";
cout << "\nGroup " << i + 1 << " Name and question:\n";
for (int j = 0; j < 5; j++) {
rerun:
int random = rand() % n;
if (arr[random] == "0") {
goto rerun;
} else {
cout << "\n____________________________________\n";
cout << "\nStudent " << arr[random];
arr[random] = "0";
}
}
int totalq = q / 5;
for (int k = 0; k < totalq; k++) {
another:
int randomq;
do {
randomq = rand() % q;
} while (que[randomq] == 0);
cout << "\nAssigned question " << que[randomq];
que[randomq] = 0;
}
cout << "\n___________________________________________________________\n\n";
}
return 0;
}