注册 登录
编程论坛 C++教室

有人会么

hangtian 发布于 2008-04-01 21:02, 558 次点击
(1)如果C是大写字母,则输出相对应的小写字母;
  (2)如果C是小写字母,则输出相对应的大写字母;
  (3)如果C是数字0~9,则输出其对应的ASCII码值(16进制);
  (4)如果C是除以上情况之外的值,则输出“Control  key”
输出格式:
The source key is: **,after converting is: ##.
3 回复
#2
hgchenkv2008-04-02 09:49
给你个程序,运用这个算法根据ASCII表if&else if&else下就可以了,
/*
a转换为A
b转换为B
*/

#include<iostream.h>
class Sample
{
    char c1,c2;
public:
    Sample(char a){c2=(c1=a)-32;}
    void disp()
    {
        cout<<c1<<"转换为"<<c2<<endl;
    }
};

void main()
{
    Sample a('a'),b('b');
    a.disp();
    b.disp();
}
#3
newyj2008-04-02 13:21
#include<iostream>
#include<cctype>
using namespace std;

int main(){
  char str='0';
  cin>>str;
  if(isupper(str))
    cout<<"The source key is: "<<str<<",after converting is: "<<static_cast<char>(tolower(str))<<endl;
  else if(islower(str))
    cout<<"The source key is: "<<str<<",after converting is: "<<static_cast<char>(toupper(str))<<endl;
  else if(isdigit(str))
    cout<<"The source key is: "<<str<<",after converting is: "<<hex<<str<<endl;
  else
    cout<<"Control  key";
  system("pause");
  return 0;         
}
输出toupper(str)时为什么是int型的
还必须得强制转换啊
#4
张信哲2008-04-13 21:42
hangtian   真可爱
1