英语专业考法律硕士:请问用C++编程怎样编写这段话?
#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(toupper(c))<<endl;
}
else
{
cout<<"Error!"<<endl;
}
return 0;
}
#include "iostream"
#include "stdlib"
using namespace std;
void main()
{
cin >> ch;
if (ch>='a' && ch<='z') ch-=32;
else if (ch>='A' && ch<='Z') ch+=32;
else {cout << "Input ERROR!";
exit(1);}
cout << ch;
}