题目内容
下列程序的功能是计算从键盘输入的字符串中数字元素的数值和。如“A0b1CD23 x456y789Z”数字元素的数值和为0+1+2+3+4+5+6+7+8+9,即45。请完善程序。#include#includeusing namespace std;class String{char *str; // 用str指向的动态空间存储要处理的字符串int s; // s存储根据题意计算的数字元素的数值和public:String(char *p):________{str=____________________;strcpy(str,p);}int number(char c)// 若c是数字字符,返回对应的数值;否则返回整数0{if(c>='0'&&c<='9')return ___________;else return 0;}void fun() // 按题意要求计算字符串中数字元素的数值和{char *p=str;while(*p){s+=_________;p++;}}void print() // 输出字符串及其中数字元素的数值和{cout<
查看答案
搜索结果不匹配?点我反馈