唐山住房和城乡建设网站,中国各大网站,钙网logo免费设计在线生成,大兴网站开发网站建设Description 先来个简单习题#xff0c;练练手吧#xff01;现在需要你来编写一个Character类#xff0c;将char这一基本数据类型进行封装。该类中需要有如下成员函数#xff1a; 1. 无参构造函数。 2. 构造函数Character(char)#xff1a;用参数初始化数据成员。 3. void…Description 先来个简单习题练练手吧现在需要你来编写一个Character类将char这一基本数据类型进行封装。该类中需要有如下成员函数 1. 无参构造函数。 2. 构造函数Character(char)用参数初始化数据成员。 3. void setCharacter(char)重新设置字符值。 4. int getAsciiCode()返回字符的ASII码。 5. char getCharacter()返回字符值。 6. 析构函数。 Input 输入只有1行包含一个合法的、可打印的字符。 Output 输出有好多行请参考样例来编写相应的函数。 Sample Input c Sample Output Default constructor is called! Character a is created! ch1 is c and its ASCII code is 99. ch2 is a and its ASCII code is 97. Character a is erased! Character c is erased! HINT Append Code #includeiostream using namespace std; class Character { private: char ch; public: Character(){coutDefault constructor is called!\n;} Character(char c){chc;coutCharacter a is created!\n;} void setCharacter(char c){chc;} int getAsciiCode(){return ch;} char getCharacter(){return ch;} ~Character(){coutCharacter ch is erased!\n;} }; int main() { char ch; Character ch1, ch2(a); cinch; ch1.setCharacter(ch); coutch1 is ch1.getCharacter() and its ASCII code is ch1.getAsciiCode().endl; coutch2 is ch2.getCharacter() and its ASCII code is ch2.getAsciiCode().endl; return 0; }转载于:https://www.cnblogs.com/TogetherLaugh/p/6544690.html