fortification test

 https://youtu.be/zBsAwEJk6hc?t=3777

3 thoughts on “fortification test”

  1. #include
    #include

    using namespace std;

    bool checkDig(char c) {
    if(c >= '0' && c <= '9' or c=='-') return true;
    else return false;
    }

    bool isNumeric(string str) {
    bool point = false;
    for (char c : str) {
    if (c == '.') {
    if (point) return false;
    point = true;
    } else if (!checkDig(c)) {
    return false;
    }
    }
    return true;
    }

    int main() {
    string input;
    cout << "Enter a string: ";
    cin >> input;
    if (isNumeric(input)) {
    cout << "Numeric Constant" << endl;
    } else {
    cout << "Not Numeric" << endl;
    }
    return 0;
    }

  2. #include
    #include
    using namespace std;

    bool OperatorChek(char c) {
    switch(c) {
    case '+':
    case '-':
    case '*':
    case '/':
    case '%':
    case '=':
    return true;
    default:
    return false;
    }
    }

    int main() {
    string str;
    cout << "Enter a string: ";
    getline(cin, str);
    int cnt=0;

    for(int i = 0; i < str.length(); i++) {
    if(OperatorChek(str[i])) {
    cnt++;
    cout <<"Operator "<<cnt<<" :"<< str[i] << endl;
    }
    }

    return 0;
    }

  3. #include
    #include

    using namespace std;

    bool hasComment(string str) {
    for (int i = 0; i < str.length() – 1; i++) {
    if ((str[i] == '/' && str[i+1] == '/') ||
    (str[i] == '/' && str[i+1] == '*') ||
    (str[i] == '*' && str[i+1] == '/')) {
    return true;
    }
    }
    return false;
    }

    int main() {
    string str;
    cout << "Enter a string: ";
    getline(cin, str);

    if (hasComment(str)) {
    cout << "The string contains a comment line.n";
    } else {
    cout << "The string does not contain a comment line.n";
    }

    return 0;
    }

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top