C++ 使用数组和字符串对句子排序

C++ 使用数组和字符串对句子排序,c++,arrays,string,histogram,acsl,C++,Arrays,String,Histogram,Acsl,抱歉,伙计们预先警告我在编码方面很差劲,但我有一个大项目,需要帮助 输入:一个完整的句子 输出:句子的排序顺序(ASCii图表顺序)(忽略大小写。) 输出以下类别的直方图: 1) 元音 2) 辅音 3) 标点符号 4) 大写字母 5) 小写字母 我甚至不知道该怎么办因为你对自己的问题含糊不清,我建议采用以下流程: 审查要求 始终审查要求(任务)。如果有您不理解或与客户(讲师)理解相同的项目,请与客户讨论 编写一个简单的main程序。 编写一个简单的main或“helloworld!”程序来验证I

抱歉,伙计们预先警告我在编码方面很差劲,但我有一个大项目,需要帮助

输入:一个完整的句子

输出:句子的排序顺序(ASCii图表顺序)(忽略大小写。)

输出以下类别的直方图:
1) 元音
2) 辅音
3) 标点符号
4) 大写字母
5) 小写字母


我甚至不知道该怎么办

因为你对自己的问题含糊不清,我建议采用以下流程:

审查要求 始终审查要求(任务)。如果有您不理解或与客户(讲师)理解相同的项目,请与客户讨论

编写一个简单的
main
程序。 编写一个简单的
main
或“helloworld!”程序来验证IDE和其他工具。在继续之前让它工作。保持简单

下面是一个例子:

#include <iostream>
#include <cstdlib>  // Maybe necessary for EXIT_SUCCESS.

int main()
{
   std::cout << "Hello World!\n";
   return EXIT_SUCCESS;
}
#包括
#包括//可能是退出成功所必需的。
int main()
{

要对字符串进行排序,可以使用标准的c qsort函数。要计算元音、辅音、标点符号……需要一个简单的For循环

以下是一个工作示例:

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

int cmp(const void* pc1, const void* pc2)
{
    if(*(char*)pc1 < *(char*)pc2) return -1;
    if(*(char*)pc1 > *(char*)pc2) return  1;
    return 0;
}

void main(int argc, char* argv[])
{
    char pczInput[2000] = "A complete sentence.";

    cout << endl << "Input: '" << pczInput << "'";

    qsort(pczInput, strlen(pczInput), sizeof(char), cmp);

    cout << endl << "Result: '" << pczInput << "'";

    int iCapital     = 0;
    int iLowerCase   = 0;
    int iPunctuation = 0;
    int iVowels      = 0;
    int iConsonants  = 0;

    for(unsigned int ui = 0; ui < strlen(pczInput); ++ui)
    {
        if(isupper(pczInput[ui])) ++iCapital;
        if(islower(pczInput[ui])) ++iLowerCase;
        if(ispunct(pczInput[ui])) ++iPunctuation;
        if(strchr("aeiouAEIOU", pczInput[ui]) != NULL) ++iVowels;
        if(strchr("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ", pczInput[ui]) != NULL) ++iConsonants;
    }

    cout << endl << "Capital chars: "     << iCapital;
    cout << endl << "Lower case chars: "  << iLowerCase;
    cout << endl << "Punctuation chars: " << iPunctuation;
    cout << endl << "Vowels chars: "      << iVowels;
    cout << endl << "Consonants chars: "  << iConsonants;
    cout << endl;
}

堆栈溢出不是一个真正的开始问题的地方。我们通常会解决特定的编程问题。你能给我们提供一个到目前为止你已经得到的代码和任何错误的例子吗,请提前警告这是一个学习的地方。如果你想让别人一如既往地为你编写代码,那就不要到哪里去了,研究一下吧e如果这个项目已经存在。同时搜索项目的部分内容是否已经编写。对于学生作业和家庭作业,搜索现有的例子。用你有问题的特定项目更新你的帖子。例如:你知道元音是什么吗?你知道如何输入句子吗?你知道什么是
std::string吗
is?你知道直方图是什么吗?你知道如何排序吗?你能使用库中的排序功能吗?
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

int cmp(const void* pc1, const void* pc2)
{
    if(*(char*)pc1 < *(char*)pc2) return -1;
    if(*(char*)pc1 > *(char*)pc2) return  1;
    return 0;
}

void main(int argc, char* argv[])
{
    char pczInput[2000] = "A complete sentence.";

    cout << endl << "Input: '" << pczInput << "'";

    qsort(pczInput, strlen(pczInput), sizeof(char), cmp);

    cout << endl << "Result: '" << pczInput << "'";

    int iCapital     = 0;
    int iLowerCase   = 0;
    int iPunctuation = 0;
    int iVowels      = 0;
    int iConsonants  = 0;

    for(unsigned int ui = 0; ui < strlen(pczInput); ++ui)
    {
        if(isupper(pczInput[ui])) ++iCapital;
        if(islower(pczInput[ui])) ++iLowerCase;
        if(ispunct(pczInput[ui])) ++iPunctuation;
        if(strchr("aeiouAEIOU", pczInput[ui]) != NULL) ++iVowels;
        if(strchr("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ", pczInput[ui]) != NULL) ++iConsonants;
    }

    cout << endl << "Capital chars: "     << iCapital;
    cout << endl << "Lower case chars: "  << iLowerCase;
    cout << endl << "Punctuation chars: " << iPunctuation;
    cout << endl << "Vowels chars: "      << iVowels;
    cout << endl << "Consonants chars: "  << iConsonants;
    cout << endl;
}
Input: 'A complete sentence.'
Result: '  .Acceeeeelmnnopstt'
Capital chars: 1
Lower case chars: 16
Punctuation chars: 1
Vowels chars: 7
Consonants chars: 10