#include <xtd/diagnostics/trace>
#include <xtd/diagnostics/default_trace_listener>
#include <xtd/console>
#include <xtd/startup>
class binomial {
public:
auto possibilities = .0l;
auto iter = .0l;
default_listener->log_file_name(args[1]);
try {
const auto MAX_POSSIBILITIES = 99.0l;
if (possibilities < 0 || possibilities > MAX_POSSIBILITIES)
throw new system_exception(string::format(
"The number of possibilities must be in the range 0..{}.", MAX_POSSIBILITIES));
auto fail_message = string::format("\"{}\" is not a valid number of possibilities.", args[0]);
default_listener->fail(fail_message, ex.
message());
if (!default_listener->assert_ui_enabled())
return;
}
} else {
const auto ENTER_PARAM = "Enter the number of possibilities as a command line argument.";
default_listener->fail(ENTER_PARAM);
if (!default_listener->assert_ui_enabled())
return;
}
for (iter = 0; iter <= possibilities; iter++) {
auto result = .0l;
auto binomial = string::empty_string;
try {
result = calc_binomial(possibilities, iter);
auto fail_message = string::format("An exception was raised when calculating Binomial( {}, {} ).", possibilities, iter);
default_listener->fail(fail_message, ex.
message());
if (!default_listener->assert_ui_enabled())
return;
}
binomial = string::format("Binomial( {0}, {1} ) = ", possibilities, iter);
default_listener->write(binomial);
default_listener->write_line(string::format("{}", result));
}
}
auto result = 1.0l;
auto iter = .0l;
for (iter = 1.0l; iter <= possibilities - outcomes; iter++) {
result *= outcomes + iter;
result /= iter;
}
return result;
}
};
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::array::begin(),...
Definition basic_array.hpp:246
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static listener_collection & listeners() noexcept
Gets the collection of listeners that is monitoring the trace output.
virtual const xtd::string & message() const noexcept
Gets message associate to the exception.
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
xtd::array< xtd::string > argument_collection
Represents the collection of arguments passed to the main entry point method.
Definition argument_collection.hpp:19
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition assert_dialog_result.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183