@@ -8,48 +8,77 @@ Decode a message from integers to text, without using arrays or strings.
88using std::cin;
99using std::cout;
1010
11- int getModulo (int nr, int mode);
12- char getCharacter (int nr, int mode);
13- char getPunctuation (int nr);
14- enum modeType {UPPERCASE, LOWERCASE, PUNCTUATION};
11+ int getModulo (int nr, int mode); /* (AD): Functions are cammelCase BUT their first letter should be capital as well GetModulo */
12+ char getCharacter (int nr, int mode); /* (AD): Functions are cammelCase BUT their first letter should be capital as well GetCharacter */
13+ char getPunctuation (int nr); /* (AD): Functions are cammelCase BUT their first letter should be capital as well GetPunctuation */
14+ enum modeType {UPPERCASE, LOWERCASE, PUNCTUATION}; /* (AD): I prefer following enumeration, because this type is passed to func as an argument. */
15+ 16+ 17+ 18+ /*
19+ typedef enum mode (AD): Works for both C and C++.
20+ {
21+ T_MODE_UPPERCASE = 0, (AD): Always initialize first enum eventhough it is already 0
22+ T_MODE_LOWERCASE, (AD): Other people can understand it's a typedef enum by seeing 'T' and 'ENUM'
23+ T_MODE_PUNCTUATION You can use '_' between words in enums, constant definitons, typedefs
24+ }T_MODE_ENUM;
25+ */
26+ 27+ 28+ /* Constant definitions
29+ #define D_LIMIT_MAX 100 (AD): So other people can understand it's constant def by seeing 'D' all capital naming.
30+ #define D_LIMIT_MIN 0
31+ */
32+ 33+ 1534
1635int main ()
1736{
1837
19- char digit;
38+ char digit;/* (AD): Always initialize variables during declaration. */
2039 char ch = ' 0' ;
2140 int nr = 0 ;
22- int mode = UPPERCASE;
41+ int mode = UPPERCASE;/* (AD): Why don't you make a typedef enum as above and use it for mode --> T_MODE_ENUM mode = UPPERCASE; */
2342 int modulo = 0 ;
2443 digit = cin.get ();
2544
26- 27- while (digit != 10 ) {
28- while (!(digit == 10 || digit == ' ,' )) {
45+ /* (AD): Don't worry about the code lines, move '{' to one line below such that it becomes aligned with '}'s. */
46+ /* (AD): I'm fixing this part, you can edit the other ones */
47+ while (digit != 10 )
48+ {
49+ while (!(digit == 10 || digit == ' ,' ))
50+ {
2951 nr = nr*10 + digit - ' 0' ;
3052 digit = cin.get ();
3153 }
3254 modulo = getModulo (nr, mode);
33- if (modulo == 0 ) {
55+ if (modulo == 0 )
56+ {
3457 mode = ++mode % 3 ;
35- } else {
58+ }
59+ else
60+ {
3661 ch = getCharacter (modulo, mode);
3762 cout << ch;
3863 }
3964 nr = 0 ;
4065 digit = cin.get ();
4166 }
42- 67+ /* (AD): Missing return statement */
68+ return 0 ;
4369}
4470
4571
46- 47- int getModulo (int nr, int mode) {
72+ /* (AD): Since mode is a typedef now, change its type from int --> T_MODE_ENUM */
73+ /* (AD): This gives clue to other people about what should they pass to this function as an argument. It's not an int but T_MODE_ENUM. */
74+ int getModulo (int nr, int mode) {
75+ /* (AD): I prefer this opening curly bracket '{' right below the function prototype. */
76+ /* (AD): This is not a must but you should choose one and continue with it. It's different for other functions and this function */
4877 if (nr == 0 ) return 0 ;
49- switch (mode) {
78+ switch (mode) {/* (AD): Prefer to use it one line below. This is also valid for while, if, for, do etc... */
5079 case UPPERCASE:
51- return nr % 27 ;
52- break ;
80+ return nr % 27 ;/* (AD): As long as not must, please try to have single return for each function. */
81+ break ;/* (AD): So you can define int result = 0; Update result in cases and return it at the end. --> Easy to follow code */
5382 case LOWERCASE:
5483 return nr % 27 ;
5584 break ;
@@ -63,7 +92,8 @@ int getModulo(int nr, int mode) {
6392
6493
6594}
66- 95+ 96+ /* (AD): GetCharacter, T_MODE_ENUM, move '{' to one line below, single return statement */
6797char getCharacter (int modulo, int mode)
6898{
6999 switch (mode) {
@@ -81,7 +111,8 @@ char getCharacter(int modulo, int mode)
81111 break ;
82112 }
83113}
84- 114+ 115+ /* (AD): GetPunctuation, single return statement, move '{' to one line below. */
85116char getPunctuation (int modulo)
86117{
87118 switch (modulo) {
0 commit comments