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、思维导图

相关推荐
魈十三6 分钟前
进程与线程:从独立空间到协调的深度解析
linux
HYNuyoah9 分钟前
Ubuntu一键安装Docker和Docker Compose
linux·ubuntu·docker
dddddppppp12310 分钟前
arm32段+页映射 手撕mmu的行为之软件模拟
linux·服务器·网络
天赐学c语言13 分钟前
MySQL - 数据库基础
linux·数据库·mysql
水饺编程14 分钟前
第5章,[标签 Win32] :GDI 的基本图形
c语言·c++·windows·visual studio
wwj888wwj16 分钟前
Ansible基础(复习3)
linux·运维·服务器·git·ansible
水饺编程17 分钟前
第5章,[标签 Win32] :GDI 的其他方面的分类
c语言·c++·windows·visual studio
计算机安禾17 分钟前
【数据结构与算法】第46篇:算法思想(一):递归与分治
c语言·数据结构·c++·算法·visualstudio·图论·visual studio code
senijusene18 分钟前
IMX6ULL Linux 驱动开发:GPIO 子系统 + misc 框架实现按键输入驱动开发
linux·运维·驱动开发
捞的不谈~19 分钟前
解决在Ubuntu系统下使用运行Lucid 相机(HTR003S-001)相应实例出现的依赖库缺失的问题
linux·运维·ubuntu