You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
// License: AGPLv3 or later. https://www.gnu.org/licenses/licenses.html |
|
|
|
/* General functions which can be used in any program |
|
*/ |
|
|
|
#ifndef _GENERAL_FUNCTIONS_H_ |
|
#define _GENERAL_FUNCTIONS_H_ |
|
|
|
#include <vector> |
|
|
|
std::vector<std::string> get_textfile_lines(std::string filename); |
|
|
|
int random_int(int lower_bound, int upper_bound); |
|
|
|
bool is_string_some_positive_number(std::string a_string); |
|
|
|
/* Its a good practice to prototype all functions including which are |
|
* defined in header file itself such as inline functions before defining |
|
* any function. This way, even if we use one function in another |
|
* function, we do not have to worry about function undefined error |
|
* possibilities. |
|
*/ |
|
|
|
inline int absolute_number(int number); |
|
|
|
inline int smaller_number(int a, int b); |
|
|
|
inline int bigger_number(int a, int b); |
|
|
|
/* this function is used between different parts of program's standard |
|
* output for better sepration of dissimilar outputs |
|
*/ |
|
inline void print_three_newlines(); |
|
|
|
inline int absolute_number(int number) |
|
{ |
|
if (number < 0) |
|
return -(number); |
|
else |
|
return number; |
|
} |
|
|
|
inline int smaller_number(int a, int b) |
|
{ |
|
if (a > b) |
|
return b; |
|
else |
|
return a; |
|
} |
|
|
|
inline int bigger_number(int a, int b) |
|
{ |
|
if (a < b) |
|
return b; |
|
else |
|
return a; |
|
} |
|
|
|
inline void print_three_newlines() |
|
{ |
|
std::cout << "\n" << std::endl; |
|
} |
|
|
|
#endif
|
|
|