首页 > 试题广场 >

编写一个程序,读取键盘输入,直到遇到@符为止,并回显输入(数

[问答题]
编写一个程序,读取键盘输入,直到遇到@符为止,并回显输入(数字除外),同时将大写字符转换为小写,将小写字符转换为大写(别忘了cctype函数系列)
#include <iostream>
#include <cctype>
using namespace std;
int main()
{    
    char ch;
    cout << "Enter text for analysis, and type @ to terminate input. \n";
    cin.get(ch);
    while (ch != '@')
    {
        if (isupper(ch))
        {
            ch = tolower(ch) ;
        }
        else if (islower(ch))
        {
            ch = toupper(ch);
        }
        if (isdigit(ch) == false)
        {
            cout << ch;
        }
            cin.get(ch);
    }
    return 0;
}
编辑于 2020-05-13 16:18:32 回复(0)