2024.3.11 C++作业

1、提示并输入一个字符串,统计该字符中大写、小写字母个数、数字个数、空格个数以及其他字符个数要求使用C++风格字符串完成

cpp 复制代码
#include <iostream>

using namespace std;

int main()
{

    char str[20];
    cout << "please enter the str:";
    gets(str);

    int uppcaseCount = 0; //定义大写字母的个数
    int lowcaseCount = 0; //定义小写字母的个数
    int digitCount = 0;   //定义数字的个数
    int spaceCount = 0;   //定义空格的个数
    int otherCount = 0;    //定义其他字符的个数

    for(int i=0; str[i]!='\0';i++)
    {
        if(str[i]>=65 && str[i]<=90)
        {
            uppcaseCount++;
        }
        else if(str[i]>=97 && str[i]<=122)
        {
            lowcaseCount++;
        }
        else if(str[i]>='1' && str[i]<='9')
        {
            digitCount++;
        }
        else if(str[i] == ' ')
        {
            spaceCount++;
        }
        else
        {
            otherCount++;
        }
    }
    cout << "Uppercase letter:" << uppcaseCount << endl;
    cout << "Lowercase letter:" << lowcaseCount << endl;
    cout << "Digits:" << digitCount << endl;
    cout << "Space:" << spaceCount << endl;
    cout << "Ohter characters" << otherCount << endl;


    return 0;
}

2、思维导图

相关推荐
Xの哲學1 小时前
Linux SKB: 深入解析网络包的灵魂
linux·服务器·网络·算法·边缘计算
无限进步_1 小时前
【C语言&数据结构】二叉树遍历:从前序构建到中序输出
c语言·开发语言·数据结构·c++·算法·github·visual studio
cui__OaO1 小时前
Linux内核--基于正点原子IMX6ULL开发板的内核移植
linux·嵌入式
我想发发发1 小时前
Linux实现虚拟串口通信-socat
linux·运维·服务器
天赐学c语言1 小时前
1.14 - 用栈实现队列 && 对模板的理解以及模板和虚函数区别
c++·算法·leecode
济6171 小时前
linux 系统移植(第五期)--Uboot移植(4)--在U-Boot 中添加自己的开发板(4) -其他需要修改的地方-- Ubuntu20.04
linux·运维·服务器
令狐少侠20112 小时前
Linux 系统部署夜莺 nightingale 监控公司的watchdog
linux·运维·服务器
玖釉-2 小时前
[Vulkan 学习之路] 02 - 万物起源:创建 Vulkan 实例 (Instance)
c++·windows·图形渲染
信工 18022 小时前
RK3588系统烧录后扩容
linux·rk3588
Jay Chou why did2 小时前
程序启动地址0x80000000
linux