Anonymous February 7, 2024 at 4:28 am #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;} Reply
Anonymous February 7, 2024 at 4:28 am #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;} Reply
Anonymous February 7, 2024 at 4:29 am #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;} Reply
#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;
}
#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;
}
#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;
}