Problem A: 字符的变化

Description

定义一个Character类,具有:

1. char类型的数据成员。

2.构造函数Character(char)。

3. Character toUpper():如果当前字符是英文小写字母时,则变为相应的大写字母;否则保持当前字符不变。注意:不要改变当前对象的属性值。

4. Character toLower():如果当前字符是英文大写字母时,则变为相应的小写字母;否则保持当前字符不变。注意:不要改变当前对象的属性值。

5. void show():显示当前字符,不输出换行。

Input

第1行N>0表示有N个测试用例。

每个测试用例只有1个字符。

Output

见样例。

Sample Input

3 a A 1

Sample Output

char upper lower a A a A A a 1 1 1

HINT

Append Code

int main()
{
     int cases;
     char c;
     cin>>cases;
     cout<< "char" << " upper" << " lower" <<endl;
     for ( int i = 0; i < cases; i++)
     {
         cin>>c;
         Character character(c);
         character.show();
         cout<< "    " ;
         character.toUpper().show();
         cout<< "     " ;
         character.toLower().show();
         cout<<endl;
     }
}
 
代码
#include<iostream>
using namespace std;

class Character
{
    char x;
public:
    Character(char a):x(a){}
    Character &toUpper()
    {
        if(x>=97&&x<=122)
            x=x-32;
            else x=x;
    }
    Character &toLower()
    {
        if(x>=65&&x<=90)
            x=x+32;
            else x=x;
    }
     void show()
     {
         cout<<x;
     }
};
int main()
{
    int cases;
    char c;
    cin>>cases;
    cout<<"char"<<" upper"<<" lower"<<endl;
    for (int i = 0; i < cases; i++)
    {
        cin>>c;
        Character character(c);
        character.show();
        cout<<"    ";
        character.toUpper().show();
        cout<<"     ";
        character.toLower().show();
        cout<<endl;
    }
}

转载于:https://www.cnblogs.com/go-ahead-TT/p/6730832.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值