File tree 6 files changed +325
-0
lines changed
6 files changed +325
-0
lines changed Original file line number Diff line number Diff line change 62
62
" src/Zombie.cpp"
63
63
],
64
64
"file" : " src/Zombie.cpp"
65
+ },
66
+ {
67
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex05" ,
68
+ "arguments" : [
69
+ " c++" ,
70
+ " -std=c++98" ,
71
+ " -Wall" ,
72
+ " -Wextra" ,
73
+ " -Werror" ,
74
+ " -Iinclude" ,
75
+ " -c" ,
76
+ " -o" ,
77
+ " build/main.o" ,
78
+ " src/main.cpp"
79
+ ],
80
+ "file" : " src/main.cpp"
81
+ },
82
+ {
83
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex05" ,
84
+ "arguments" : [
85
+ " c++" ,
86
+ " -std=c++98" ,
87
+ " -Wall" ,
88
+ " -Wextra" ,
89
+ " -Werror" ,
90
+ " -Iinclude" ,
91
+ " -c" ,
92
+ " -o" ,
93
+ " build/Harl.o" ,
94
+ " src/Harl.cpp"
95
+ ],
96
+ "file" : " src/Harl.cpp"
65
97
}
66
98
]
Original file line number Diff line number Diff line change
1
+ # Compiler
2
+ CXX := c++
3
+
4
+ # Directories
5
+ SRCDIR := src
6
+ INCDIR := include
7
+ BUILDDIR := build
8
+ TARGETDIR := bin
9
+
10
+ # Target executable name
11
+ TARGET := harlFilter
12
+
13
+ # Source files
14
+ SRCEXT := cpp
15
+ SOURCES := $(shell find $(SRCDIR ) -type f -name * .$(SRCEXT ) )
16
+
17
+ # Object files
18
+ OBJECTS := $(patsubst $(SRCDIR ) /% ,$(BUILDDIR ) /% ,$(SOURCES:.$(SRCEXT ) =.o ) )
19
+
20
+ # Includes
21
+ INC := -I$(INCDIR )
22
+
23
+ # Flags
24
+ CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
25
+
26
+ # Final executable
27
+ EXECUTABLE := $(TARGETDIR ) /$(TARGET )
28
+
29
+ # Default make target
30
+ all : directories $(EXECUTABLE )
31
+
32
+ # Ensure build directories exist
33
+ directories :
34
+ @mkdir -p $(BUILDDIR )
35
+ @mkdir -p $(TARGETDIR )
36
+
37
+ # Rule for linking object files into executable
38
+ $(EXECUTABLE ) : $(OBJECTS )
39
+ $(CXX ) $(LDFLAGS ) $^ -o $(EXECUTABLE )
40
+
41
+ # Rule for compiling source files into object files
42
+ $(BUILDDIR ) /% .o : $(SRCDIR ) /% .$(SRCEXT )
43
+ $(CXX ) $(CXXFLAGS ) $(INC ) -c -o $@ $<
44
+
45
+ # Clean build artifacts
46
+ clean :
47
+ @rm -rf $(BUILDDIR )
48
+ @rm -rf $(TARGETDIR )
49
+
50
+ # Run the executable
51
+ run :
52
+ @./$(EXECUTABLE ) $(ARGS )
53
+
54
+ # Phony targets
55
+ .PHONY : all clean run
56
+
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex00" ,
4
+ "arguments" : [
5
+ " c++" ,
6
+ " -std=c++98" ,
7
+ " -Wall" ,
8
+ " -Wextra" ,
9
+ " -Werror" ,
10
+ " -Iinclude" ,
11
+ " -c" ,
12
+ " -o" ,
13
+ " build/main.o" ,
14
+ " src/main.cpp"
15
+ ],
16
+ "file" : " src/main.cpp"
17
+ },
18
+ {
19
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex00" ,
20
+ "arguments" : [
21
+ " c++" ,
22
+ " -std=c++98" ,
23
+ " -Wall" ,
24
+ " -Wextra" ,
25
+ " -Werror" ,
26
+ " -Iinclude" ,
27
+ " -c" ,
28
+ " -o" ,
29
+ " build/newZombie.o" ,
30
+ " src/newZombie.cpp"
31
+ ],
32
+ "file" : " src/newZombie.cpp"
33
+ },
34
+ {
35
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex00" ,
36
+ "arguments" : [
37
+ " c++" ,
38
+ " -std=c++98" ,
39
+ " -Wall" ,
40
+ " -Wextra" ,
41
+ " -Werror" ,
42
+ " -Iinclude" ,
43
+ " -c" ,
44
+ " -o" ,
45
+ " build/randonChump.o" ,
46
+ " src/randonChump.cpp"
47
+ ],
48
+ "file" : " src/randonChump.cpp"
49
+ },
50
+ {
51
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex00" ,
52
+ "arguments" : [
53
+ " c++" ,
54
+ " -std=c++98" ,
55
+ " -Wall" ,
56
+ " -Wextra" ,
57
+ " -Werror" ,
58
+ " -Iinclude" ,
59
+ " -c" ,
60
+ " -o" ,
61
+ " build/Zombie.o" ,
62
+ " src/Zombie.cpp"
63
+ ],
64
+ "file" : " src/Zombie.cpp"
65
+ },
66
+ {
67
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex05" ,
68
+ "arguments" : [
69
+ " c++" ,
70
+ " -std=c++98" ,
71
+ " -Wall" ,
72
+ " -Wextra" ,
73
+ " -Werror" ,
74
+ " -Iinclude" ,
75
+ " -c" ,
76
+ " -o" ,
77
+ " build/main.o" ,
78
+ " src/main.cpp"
79
+ ],
80
+ "file" : " src/main.cpp"
81
+ },
82
+ {
83
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex05" ,
84
+ "arguments" : [
85
+ " c++" ,
86
+ " -std=c++98" ,
87
+ " -Wall" ,
88
+ " -Wextra" ,
89
+ " -Werror" ,
90
+ " -Iinclude" ,
91
+ " -c" ,
92
+ " -o" ,
93
+ " build/Harl.o" ,
94
+ " src/Harl.cpp"
95
+ ],
96
+ "file" : " src/Harl.cpp"
97
+ },
98
+ {
99
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex06" ,
100
+ "arguments" : [
101
+ " c++" ,
102
+ " -std=c++98" ,
103
+ " -Wall" ,
104
+ " -Wextra" ,
105
+ " -Werror" ,
106
+ " -Iinclude" ,
107
+ " -c" ,
108
+ " -o" ,
109
+ " build/main.o" ,
110
+ " src/main.cpp"
111
+ ],
112
+ "file" : " src/main.cpp"
113
+ },
114
+ {
115
+ "directory" : " /nfs/homes/vde-frei/common_core/cpp/module_01/ex06" ,
116
+ "arguments" : [
117
+ " c++" ,
118
+ " -std=c++98" ,
119
+ " -Wall" ,
120
+ " -Wextra" ,
121
+ " -Werror" ,
122
+ " -Iinclude" ,
123
+ " -c" ,
124
+ " -o" ,
125
+ " build/Harl.o" ,
126
+ " src/Harl.cpp"
127
+ ],
128
+ "file" : " src/Harl.cpp"
129
+ }
130
+ ]
Original file line number Diff line number Diff line change
1
+ #ifndef HARL_HPP
2
+ #define HARL_HPP
3
+
4
+ #include < string>
5
+
6
+ class Harl {
7
+
8
+ public:
9
+ Harl ();
10
+ ~Harl ();
11
+
12
+ enum ComplaintLevel {
13
+ DEBUG,
14
+ INFO,
15
+ WARNING,
16
+ ERROR,
17
+ };
18
+
19
+ void complain (std::string level);
20
+
21
+ private:
22
+ void debug (void );
23
+ void info (void );
24
+ void warning (void );
25
+ void error (void );
26
+ size_t select;
27
+ };
28
+
29
+ #endif // !HARL_HPP
Original file line number Diff line number Diff line change
1
+ #include " Harl.hpp"
2
+ #include < iostream>
3
+
4
+ Harl::Harl () {}
5
+
6
+ Harl::~Harl () {}
7
+
8
+ void Harl::complain (std::string level) {
9
+ std::string levels[4 ] = {" DEBUG" , " INFO" , " WARNING" , " ERROR" };
10
+ for (int i = 0 ; i < 4 ; ++i) {
11
+ if (!level.compare (levels[i]))
12
+ this ->select = i;
13
+ }
14
+ switch (this ->select ) {
15
+ case DEBUG:
16
+ debug ();
17
+ info ();
18
+ warning ();
19
+ error ();
20
+ break ;
21
+ case INFO:
22
+ info ();
23
+ warning ();
24
+ error ();
25
+ break ;
26
+ case WARNING:
27
+ warning ();
28
+ error ();
29
+ break ;
30
+ case ERROR:
31
+ error ();
32
+ break ;
33
+ default :
34
+ std::cout << " Invalid entry." << std::endl;
35
+ }
36
+ }
37
+
38
+ void Harl::debug (void ) {
39
+ std::cout
40
+ << " [DEBUG]\n "
41
+ << " I love having extra bacon for my "
42
+ " 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do!"
43
+ << std::endl;
44
+ }
45
+
46
+ void Harl::info (void ) {
47
+ std::cout
48
+ << " [INFO]\n "
49
+ << " I cannot believe adding extra bacon costs more money. You didn’t put "
50
+ " enough bacon in my burger! If you did, I wouldn’t be asking for more!"
51
+ << std::endl;
52
+ }
53
+
54
+ void Harl::warning (void ) {
55
+ std::cout
56
+ << " [WARNING]\n "
57
+ << " I think I deserve to have some extra bacon for free. I’ve been "
58
+ " coming for years whereas you started working here since last month."
59
+ << std::endl;
60
+ }
61
+
62
+ void Harl::error (void ) {
63
+ std::cout << " [ERROR]\n "
64
+ << " This is unacceptable! I want to speak to the manager now."
65
+ << std::endl;
66
+ }
Original file line number Diff line number Diff line change
1
+ #include " Harl.hpp"
2
+ #include < cstdlib>
3
+
4
+ int main (int argc, char *argv[]) {
5
+ Harl harl;
6
+
7
+ if (argc == 2 ) {
8
+ harl.complain (argv[1 ]);
9
+ }
10
+
11
+ return EXIT_SUCCESS;
12
+ }
You can’t perform that action at this time.
0 commit comments