102using namespace Aleph;
111 cout <<
"+" << string(70,
'-') <<
"+" <<
endl;
113 cout <<
"+" << string(70,
'-') <<
"+" <<
endl;
131 double add(
double a,
double b) {
return a + b; }
132 double sub(
double a,
double b) {
return a - b; }
133 double mul(
double a,
double b) {
return a * b; }
134 double div(
double a,
double b)
136 if (b == 0)
throw runtime_error(
"Division by zero");
139 double mod(
double a,
double b)
141 return static_cast<int>(a) %
static_cast<int>(b);
143 double pow(
double a,
double b) {
return std::pow(a, b); }
148 print_header(
"Example 1: Calculator with Function Pointers");
162 cout <<
"\n Registered operations: + - * / % ^\n" <<
endl;
165 struct TestCase {
double a;
char op;
double b; };
174 cout <<
" Expression Result" <<
endl;
175 cout <<
" " << string(35,
'-') <<
endl;
177 for (
size_t i = 0; i <
tests.
size(); ++i)
180 if (
calc.valid_key(t.op))
182 double result =
calc.run(t.op, t.a, t.b);
183 cout <<
" " <<
setw(6) << t.a <<
" " << t.op <<
" "
184 <<
setw(6) << t.b <<
" = " <<
setw(10) << result <<
endl;
189 cout <<
"\n Checking for unregistered operation '!':" <<
endl;
190 cout <<
" valid_key('!') = " << (
calc.valid_key(
'!') ?
"true" :
"false") <<
endl;
207 for (
char& c : result) c =
toupper(c);
213 for (
char& c : result) c =
tolower(c);
218 return string(s.rbegin(), s.rend());
222 return to_string(s.length()) +
" characters";
247 string text =
"Colombia es un pais de gente trabajadora";
249 cout <<
"\n Original text: \"" <<
text <<
"\"\n" <<
endl;
251 cout <<
" Transformation Result" <<
endl;
252 cout <<
" " << string(55,
'-') <<
endl;
266 cout <<
" " << left <<
setw(18) << op << result <<
endl;
270 cout <<
"\n Available operations: ";
272 for (
auto it = keys.get_it(); it.has_curr(); it.next_ne())
273 cout << it.get_curr() <<
" ";
283 print_header(
"Example 3: Colombian Regions Information System");
291 cout <<
" Departments: Cundinamarca, Boyaca, Santander, Antioquia..." <<
endl;
292 cout <<
" Climate: Temperate to cold (varies with altitude)" <<
endl;
293 cout <<
" Products: Coffee, flowers, potatoes, emeralds" <<
endl;
298 cout <<
" Major cities: Barranquilla, Cartagena, Santa Marta" <<
endl;
299 cout <<
" Departments: Atlantico, Bolivar, Magdalena, La Guajira..." <<
endl;
300 cout <<
" Climate: Tropical hot" <<
endl;
301 cout <<
" Products: Bananas, coal, tourism, fishing" <<
endl;
305 cout <<
"\n REGION PACIFICA" <<
endl;
306 cout <<
" Major cities: Cali, Buenaventura, Quibdo" <<
endl;
307 cout <<
" Departments: Valle del Cauca, Choco, Narino, Cauca" <<
endl;
308 cout <<
" Climate: Very humid tropical" <<
endl;
309 cout <<
" Products: Sugar cane, timber, gold, platinum" <<
endl;
313 cout <<
"\n REGION ORINOQUIA (Los Llanos)" <<
endl;
314 cout <<
" Major cities: Villavicencio, Yopal" <<
endl;
315 cout <<
" Departments: Meta, Casanare, Arauca, Vichada" <<
endl;
316 cout <<
" Climate: Tropical with dry season" <<
endl;
317 cout <<
" Products: Cattle, oil, rice, palm oil" <<
endl;
321 cout <<
"\n REGION AMAZONIA" <<
endl;
322 cout <<
" Major cities: Leticia, Florencia" <<
endl;
323 cout <<
" Departments: Amazonas, Caqueta, Putumayo, Guaviare" <<
endl;
324 cout <<
" Climate: Humid equatorial" <<
endl;
325 cout <<
" Products: Timber, rubber, ecotourism, biodiversity" <<
endl;
329 cout <<
"\n REGION INSULAR" <<
endl;
330 cout <<
" Islands: San Andres, Providencia, Santa Catalina" <<
endl;
331 cout <<
" Location: Caribbean Sea" <<
endl;
332 cout <<
" Climate: Tropical maritime" <<
endl;
333 cout <<
" Products: Tourism, coconut, fishing" <<
endl;
345 cout <<
"\n Colombia's Natural Regions:" <<
endl;
346 cout <<
" " << string(40,
'=') <<
endl;
358 print_header(
"Example 4: Order Processing State Machine");
373 Order order = {1001,
"created",
"Juan Perez", 250000.0,
""};
380 if (
o.state !=
"created") {
381 cout <<
" [ERROR] Cannot confirm - order not in 'created' state" << endl;
385 o.state =
"confirmed";
386 cout <<
" [OK] Order " <<
o.id <<
" confirmed" <<
endl;
390 if (
o.state !=
"confirmed") {
391 cout <<
" [ERROR] Cannot pay - order not confirmed" <<
endl;
397 <<
" COP received" <<
endl;
401 if (
o.state !=
"paid") {
402 cout <<
" [ERROR] Cannot ship - order not paid" <<
endl;
407 cout <<
" [OK] Order shipped to " <<
o.customer <<
endl;
411 if (
o.state !=
"shipped") {
412 cout <<
" [ERROR] Cannot deliver - order not shipped" <<
endl;
416 o.state =
"delivered";
417 cout <<
" [OK] Order delivered successfully!" <<
endl;
421 if (
o.state ==
"delivered") {
422 cout <<
" [ERROR] Cannot cancel delivered order" <<
endl;
426 o.state =
"cancelled";
427 cout <<
" [OK] Order cancelled" <<
endl;
433 cout <<
"\n Processing order:" <<
endl;
434 cout <<
" " << string(40,
'-') <<
endl;
443 cout <<
"\n Attempting invalid transition:" <<
endl;
447 cout <<
"\n Order History:" <<
endl;
458 print_header(
"Example 5: Hash-based Dispatcher Performance");
483 if (
income < 4500000)
return 0.0;
484 if (
income < 10000000)
return (
income - 4500000) * 0.19;
485 if (
income < 25000000)
return (
income - 10000000) * 0.28 + 1045000;
486 return (
income - 25000000) * 0.33 + 5245000;
489 cout <<
"\n Colombian Economic Calculations:" <<
endl;
490 cout <<
" " << string(50,
'-') <<
endl;
494 cout <<
"\n Currency Conversion:" <<
endl;
503 cout <<
"\n Price Calculations:" <<
endl;
511 cout <<
"\n Monthly Income Tax Examples:" <<
endl;
533 print_header(
"Example 6: Variadic Arguments Dispatcher");
541 for (
size_t i = 0; i <
args.
size(); ++i) {
542 if (i > 0) result +=
" ";
550 for (
size_t i = 0; i <
args.
size(); ++i)
575 cout <<
"\n Arguments: Bogota, Medellin, Cali, Barranquilla, Cartagena\n" <<
endl;
577 cout <<
" Operation Result" <<
endl;
578 cout <<
" " << string(50,
'-') <<
endl;
594 cout <<
"========================================================================" <<
endl;
595 cout <<
" ALEPH-W DISPATCHER EXAMPLE" <<
endl;
596 cout <<
" Dynamic Command Dispatching" <<
endl;
597 cout <<
"========================================================================" <<
endl;
607 cout <<
"========================================================================" <<
endl;
608 cout <<
" Example completed successfully!" <<
endl;
609 cout <<
"========================================================================" <<
endl;
Command dispatcher pattern implementation.
Tree-based command dispatcher.
Hash-based command dispatcher.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
size_t size() const noexcept
Count the number of elements of the list.
size_t length() const noexcept
Count the number of elements of a container.
void demo_state_machine()
void demo_hash_dispatcher()
void demo_variadic_dispatcher()
void demo_text_processor()
void print_subheader(const string &subtitle)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log_function > > log(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
std::string tolower(const char *str)
Convert a C std::string to lower-case.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
std::string toupper(const char *str)
Convert a C std::string to upper-case.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Basic arithmetic operations for the calculator.
double sub(double a, double b)
double add(double a, double b)
double div(double a, double b)
double mul(double a, double b)
double pow(double a, double b)
double mod(double a, double b)
Aleph::DynList< T > keys() const
Lazy and scalable dynamic array implementation.