如何编写一个c++代码,使函数在初始参数为大写时返回true,如果不是,则返回false

how to write a c++ code to make function that returns true if initial as an argument is capital, returns false if not

本文关键字:返回 false 参数 如果不 true 何编写 一个 c++ 函数 代码      更新时间:2023-10-16

我想写一个程序,使函数在作为参数的initial为大写时返回true,如果不是,则返回false。作为一个论点,它对inital意味着什么#包括使用命名空间std;

bool IsUpper (char);   
int main ( ) {
    char ch;
    cout << "Enter a letter: " ; 
    cin >> ch ;
    if (IsUpper (ch)) 
       cout << ch << " is a  capital " << endl;
    else 
       cout << ch << " is not a capital " << endl;
    return 0;
}
bool IsUpper(char ch) {
{
    if ((ch >= 'A' ) && (ch <= 'Z'))
       return true;
   else 
      return false; 
}
     return false;
}

根据您的代码,您可以替换:

bool IsAVowel (char ch) {
{
   if ((ch >= 'A' ) && (ch <= 'Z'))
     return true;
    else 
     return false; 
}

通过

bool isUpper(const char ch) {
  return (ch >= 'A') && (ch <= 'Z');
}