-
Notifications
You must be signed in to change notification settings - Fork 27
/
5.cpp
128 lines (112 loc) · 2.49 KB
/
5.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Logic flows like water,
//powerful and swift.
//If you are not careful
//friend you just might find:
//logic turns against you,
//seeping through a rift.
//To complete this challenge, be like water and find the cracks.
//Note: if you are trying this on a system that doesn't have heap metadata protection, it won't be much fun.
/**
* A class that contains a character array, provides a method for reading standard input into it.
*/
class Test{
public:
Test(){
printf("Making a new test...\n");
}
/**
* Scan a string into the character array.
*/
void a(){
printf("Reading string...\n");
scanf("%s", buffer);
}
private:
char buffer[10];
};
/**
* A class that provides a method to execute a command.
*/
class Command{
public:
Command(){
printf("Making a new command...\n");
command[0] = 'l';
command[1] = 's';
command[2] = '\0';
}
/**
* Execute the command in the character array.
*/
void a(){
printf("Running shell command %s\n", command);
system(command);
}
private:
char command[10];
};
class Fluff{
char fluff[128];
};
int main(){
char action[32];
Test* tests[10];
int onTest = 0;
int setTest = 0;
Command* commands[10];
int onCommand = 0;
int runCommand = 0;
Fluff* someFluff[5];
int onFluff = 0;
do {
scanf("%31s", action);
printf("running action %s\n", action);
//make a new test
if(strcmp("newtest", action) == 0){
if(onTest < 10){
tests[onTest] = new Test();
onTest++;
}
}
//make a new command, also add some fluff
else if(strcmp("newcommand", action) == 0){
if(onFluff < 5){
someFluff[onFluff] = new Fluff();
onFluff++;
}
if(onCommand < 10){
commands[onCommand] = new Command();
onCommand++;
}
}
//set the value of any test, get rid of some fluff
else if(strcmp("settest", action) == 0){
printf("Number of tests:%d Set test number:", onTest);
scanf("%d", &setTest);
if(setTest >= 0 && setTest < onTest){
tests[setTest]->a();
}
if(onFluff < 5 && someFluff[onFluff] != NULL){
delete someFluff[onFluff];
}
}
//run any command
else if(strcmp("runcommand", action) == 0){
printf("Number of commands:%d Run command number:", onCommand);
scanf("%d", &runCommand);
if(runCommand >= 0 && runCommand < onCommand){
commands[runCommand]->a();
}
}
} while(strcmp("quit",action) != 0);
//cleanup
for(int i = 0; i < 10; i++){
delete commands[i];
}
for(int i = 0; i < 10; i++){
delete tests[i];
}
}