请问用C++编程怎样编写这段话?

来源:百度知道 编辑:UC知道 时间:2024/05/15 04:44:19
从键盘上输入一个英文字母,若是小写的,则输出相对应的大写字母;若是大写的,则输入相对应的小写字母,其它字符为非法字符.

#include <iostream>
using namespace std;

int main ()
{
char ch;
int ch_index;
const int des = 32;

cout <<"Input a Character:";
cin >>ch;
ch_index = int (ch);
if ((ch_index >= 65 && ch_index <= 90) || (ch_index >= 97 && ch_index <= 122))
{
if (ch_index >= 65 && ch_index <= 90)
cout <<char(ch_index + des)<<endl;
else
cout <<char(ch_index - des)<<endl;
}
else
cout<<"Wrong Input!";

return 0;
}

多多使用库函数,能不自己写就不自己写
#include <iostream>
#include <cctype> //字符库
using namespace std;

int main()
{
char c;
cin>>c;
if (isupper(c))
{
cout<<char(tolower(c))<<endl;
}
else if (islower(c))
{
cout<<char