A modern and reusable C++ helper library for efficient console output and robust input validation.
It provides two key classes:
- π¨οΈ clsPrint β for printing and formatting data beautifully in the console.
- β clsInputValidate β for validating user input of any type safely and interactively.
πΉ clsPrint:
Enables clean, readable, and feature-rich console printing β from text formatting and random data generation to mathematical pattern output.
πΉ clsInputValidate:
Handles user input safely, checking for type errors, number ranges, positivity, odd/even/prime/perfect/palindrome properties, and more.
π clsPrint.h β Printing and formatting class
π clsInputValidate.h β Input validation class
π clsString.h β String helper utilities (vowels, parsing, etc.)
π clsMath.h β Math helper utilities (prime, palindrome, perfect, etc.)
π clsUtil.h β Utility helper (random chars, keys, levels)
π main.cpp β Example usage and testing
π README.md β Documentation file
Category | Description |
---|---|
Text | Print text, tabs, vowels, first letters, and words |
Numbers | Print digits, Fibonacci, even/odd/prime/palindrome/perfect numbers |
Random | Generate random uppercase, lowercase, and special characters |
Math Integration | Uses clsMath for prime, palindrome, and perfect checks |
Files | Save strings to text files easily |
Console Effects | Change screen colors, alerts, and game result screens |
Dates | Print short day/month names and formatted week headers |
Category | Description |
---|---|
Type Validation | Check if last input was valid |
Range Checking | Ensure number lies between two values |
Positive/Negative | Read only positive or negative numbers |
Odd/Even | Read numbers constrained by parity |
Prime/Perfect/Palindrome | Validate based on mathematical properties |
Characters & Strings | Read single characters and full strings |
Arrays | Read arrays of numbers, strings, or characters |
Enum Input | Read operation types and difficulty levels safely |
#include #include "clsPrint.h" #include "clsInputValidate.h" using namespace std;
int main() { clsPrint::Print("Hello from clsPrint!\n"); cout << clsPrint::Tabs(2) << "Indented text example\n";
cout << "Prime numbers from 1 to 20: ";
clsPrint::PrintPrimeNumbers(1, 20);
cout << "Perfect numbers from 1 to 500: ";
clsPrint::PrintPerfectNumbers(1, 500);
cout << "\nRandom upper letters: ";
clsPrint::PrintRandomUpperLetters(5);
cout << endl;
clsPrint::PrintFirstLetterOfWords("Hello World From clsPrint");
clsPrint::PrintVowels("Programming is Fun!");
clsPrint::SaveStringToFile("output.txt", "Saved line example.");
cout << "\nEnter a number between 1 and 10: ";
int num = clsInputValidate::ReadNumberBetween<int>(1, 10);
cout << "β
You entered: " << num << endl;
cout << "Enter a positive number: ";
int pos = clsInputValidate::ReadPositiveNumber<int>();
cout << "β
Positive number accepted: " << pos << endl;
cout << "Enter a prime number: ";
int prime = clsInputValidate::ReadPrimeNumber<int>();
cout << "β
Prime number accepted: " << prime << endl;
return 0;
}
Hello from clsPrint! Indented text example Prime numbers from 1 to 20: 2 3 5 7 11 13 17 19 Perfect numbers from 1 to 500: 6 28 496 Random upper letters: QWTRB
First Letter of this string H W F C
Vowels In String are : o a i i u
Enter a number between 1 and 10: 7 β You entered: 7 Enter a positive number: 15 β Positive number accepted: 15 Enter a prime number: 13 β Prime number accepted: 13
Method | Description |
---|---|
static void Print(string text); |
Print a string to the console |
static string Tabs(int count); |
Return tab spacing for indentation |
static void PrintPrimeNumbers(int from, int to); |
Print all prime numbers in a range |
static void PrintEvenNumbers(int from, int to); |
Print even numbers in a range |
static void PrintOddNumbers(int from, int to); |
Print odd numbers in a range |
static void PrintPerfectNumbers(int from, int to); |
Print perfect numbers in a range |
static void PrintPalindromeNums(int from, int to); |
Print palindrome numbers in a range |
static void PrintFibonatchiSerie(int number); |
Print a Fibonacci sequence |
static void PrintFirstLetterOfWords(string s); |
Print the first letter of each word |
static void PrintVowels(string s); |
Print all vowels in a string |
static void PrintEachWord(string s); |
Print each word on a new line |
static void SaveStringToFile(string filename, string text); |
Save text to a file |
Method | Description |
---|---|
static bool IsValidLastInput(); |
Check if the last input operation was valid |
template<typename T> static bool IsNumberBetween(T number, T from, T to); |
Check if a number lies between two values |
template<typename T> static T ReadNumber(string errorMsg); |
Read a number safely with error handling |
template<typename T> static T ReadNumberBetween(T from, T to, string errorMsg); |
Read a number within a given range |
template<typename T> static T ReadPositiveNumber(string errorMsg); |
Read a positive number only |
template<typename T> static T ReadNegativeNumber(string errorMsg); |
Read a negative number only |
template<typename T> static T ReadOddNumber(string errorMsg); |
Read an odd number only |
template<typename T> static T ReadEvenNumber(string errorMsg); |
Read an even number only |
template<typename T> static T ReadPrimeNumber(string errorMsg); |
Read a prime number only |
template<typename T> static T ReadPerfectNumber(string errorMsg); |
Read a perfect number only |
template<typename T> static T ReadPalindromeNumber(string errorMsg); |
Read a palindrome number only |
static string ReadString(); |
Read a complete string input |
static char ReadCharacter(string errorMsg); |
Read a single character safely |
static bool ReadBoolean(string errorMsg); |
Read a boolean value (0 or 1) |
- Interactive console programs
- Educational exercises (math, validation, string parsing)
- Small games or quizzes
- Command-line utilities
- Training projects for C++ OOP practice
- C++17 or newer
- Standard I/O stream libraries (, , , )
- Include all helper headers (clsMath, clsString, clsUtil) in your project folder
Developed by: [Faresincode]
π¬ Contributions, issues, and improvements are welcome!
This project is open-source under the MIT License β free to use, modify, and share.