#include #include #include bool isValidExponentialNumber(const std::string& input) { // Check if the input string is empty if (input.empty()) { return false; } bool hasDecimalPoint = false; bool hasExponent = false; bool hasSign = false; // Iterate through each character in the string for (size_t i = 0; i < input.length(); ++i) { char ch = input[i]; // Check for the sign character at the beginning if (i == 0 && (ch == '+' || ch == '-')) { hasSign = true; } // Check for digits else if (isdigit(ch)) { // Digits are allowed } // Check for the decimal point else if (ch == '.') { // Decimal point can only occur once and before the exponent if (hasDecimalPoint || hasExponent) { return false; } hasDecimalPoint = true; } // Check for the exponent character else if (ch == 'e' || ch == 'E') { // Exponent can only occur once and after the sign (if any) if (hasExponent || i == 0 || input.length() <= i + 1) { return false; } hasExponent = true; // Check for the sign of the exponent char nextChar = input[i + 1]; if (nextChar == '+' || nextChar == '-') { ++i; // Skip the exponent sign } } // Invalid character else { return false; } } // The input is valid if it has at least one digit return hasSign || hasDecimalPoint || hasExponent; } int main() { std::string input; std::cout << "Enter a potential exponential number: "; std::cin >> input; if (isValidExponentialNumber(input)) { std::cout << "Valid exponential number." << std::endl; } else { std::cout << "Invalid exponential number." << std::endl; } return 0; }