1- #include < iostream>
21#include " ExampleRegistry.h"
2+ #include " Logger.h"
33
44namespace {
55void conditionals () {
6- std::cout << " \n --- Conditional Examples --- \n " ;
6+ LOG ( " Conditional Examples" ) ;
77 // if-else
88 int x = rand ();
9- std::cout << " x = " << x << " \n " ;
9+ LOG_S ( " x = " << x) ;
1010 if (x > 0 ) {
11- std::cout << " x is positive\n " ;
11+ LOG ( " x is positive" ) ;
1212 } else if (x < 0 ) {
13- std::cout << " x is negative\n " ;
13+ LOG ( " x is negative" ) ;
1414 } else {
15- std::cout << " x is zero\n " ;
15+ LOG ( " x is zero" ) ;
1616 }
1717
1818 // switch
1919 int choice = rand () % 2 + 1 ;
20- std::cout << " choice = " << x << " \n " ;
20+ LOG_S ( " Choice = " << std::to_string (x)) ;
2121 switch (choice) {
2222 case 1 :
23- std::cout << " Choice is 1\n " ;
23+ LOG ( " Choice is 1" ) ;
2424 break ;
2525 case 2 :
26- std::cout << " Choice is 2\n " ;
26+ LOG ( " Choice is 2" ) ;
2727 break ;
2828 default :
29- std::cout << " Choice is something else\n " ;
29+ LOG ( " Choice is something else" ) ;
3030 break ;
3131 }
3232}
3333
3434void jumps () {
35- std::cout << " \n --- Jump Statement Examples --- \n " ;
35+ LOG ( " Jump Statement Examples" ) ;
3636
3737 // goto
3838 int num = rand ();
3939 if (num == 3 )
4040 goto jumpLabel;
41- std::cout << " This line will be skipped.\n " ;
41+ LOG ( " This line will be skipped." ) ;
4242
4343jumpLabel:
44- std::cout << " Jumped here using goto!\n " ;
44+ LOG ( " Jumped here using goto!" ) ;
4545
4646 // break / continue
4747 for (int i = 0 ; i < 5 ; ++i) {
4848 if (i == 2 )
4949 continue ; // skip 2
5050 if (i == 4 )
5151 break ; // stop loop at 4
52- std::cout << " i = " << i << " \n " ;
52+ LOG_S ( " i = " << i) ;
5353 }
5454}
5555
@@ -59,43 +59,43 @@ int square(int n) {
5959}
6060
6161void functionCalls () {
62- std::cout << " \n --- Function Call Examples --- \n " ;
62+ LOG ( " Function Call Examples" ) ;
6363 // function call
6464 int result = square (5 );
65- std::cout << " square(5) = " << result << " \n " ;
65+ LOG_S ( " square(5) = " << result) ;
6666}
6767
6868void loops () {
69- std::cout << " \n --- Loop Examples --- \n " ;
69+ LOG ( " Loop Examples" ) ;
7070
7171 // while
7272 int i = 0 ;
7373 while (i < 3 ) {
74- std::cout << " while loop i = " << i << " \n " ;
74+ LOG_S ( " while loop i = " << i) ;
7575 ++i;
7676 }
7777
7878 // do-while
7979 int j = 0 ;
8080 do {
81- std::cout << " do-while loop j = " << j << " \n " ;
81+ LOG_S ( " do-while loop j = " << j) ;
8282 ++j;
8383 } while (j < 2 );
8484
8585 // for(initialization; condition; update)
8686 for (int k = 0 ; k < 3 ; ++k) {
87- std::cout << " for loop k = " << k << " \n " ;
87+ LOG_S ( " for loop k = " << k) ;
8888 }
8989
9090 // ranged-for
9191 const int arr[] = {10 , 20 , 30 };
9292 for (int value : arr) {
93- std::cout << " ranged-for value = " << value << " \n " ;
93+ LOG_S ( " ranged-for value = " << value) ;
9494 }
9595}
9696
9797void halts () {
98- std::cout << " \n --- Halt Examples --- \n " ;
98+ LOG ( " Halt Examples" ) ;
9999
100100 // std::exit() — terminates the program normally
101101 // std::abort() — terminates abnormally (no cleanup)
@@ -106,20 +106,20 @@ void halts() {
106106}
107107
108108void exceptions () {
109- std::cout << " \n --- Exception Handling Examples --- \n " ;
109+ LOG ( " Exception Handling Examples" ) ;
110110
111111 // try - catch - throw
112112 try {
113113 throw std::runtime_error (" Something went wrong!" );
114114 } catch (const std::exception& e) {
115- std::cout << " Caught exception: " << e.what () << " \n " ;
115+ LOG_S ( " Caught exception: " << e.what ()) ;
116116 }
117117}
118118} // namespace
119119
120120class ControlFlow : public IExample {
121121 public:
122- std::string group () const override { return " core" ; }
122+ std::string group () const override { return " core/basics " ; }
123123 std::string name () const override { return " ControlFlow" ; }
124124 std::string description () const override { return " ControlFlow" ; }
125125 void execute () override {
0 commit comments