大萝卜BoBoBoBo~

导航

Problem A: 字符的变化

#include<iostream>
using namespace std;

class Character
{
public:
    char cc;
public:
    Character(char c):cc(c){}               //使用 列表的方法给函数赋值更为简洁
    Character toUpper()
    {if(cc>=97&&cc<=122)                   //                         ASCII码值:97(A)~122(Z)
    cc=cc-32;                  //大写字母与小写字母相差32                65(a)~90(z)
     return cc;}
    Character toLower()
    {if(cc>=65&&cc<=90)
    cc=cc+32;
    return cc;}
    void show(){cout<<cc;}

};

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;
    }
}

  

posted on 2020-04-20 21:29  我有一个大萝北  阅读(258)  评论(0编辑  收藏  举报