Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何修改程序使直方图垂直?I';我很难使它垂直。代码如下_C++ - Fatal编程技术网

C++ 如何修改程序使直方图垂直?I';我很难使它垂直。代码如下

C++ 如何修改程序使直方图垂直?I';我很难使它垂直。代码如下,c++,C++,无法使直方图垂直。如何修改程序使直方图垂直?请帮帮我谢谢!这是代码。这个直方图是水平的,但我不知道如何使它垂直。使直方图垂直更具挑战性。我已经尝试了很多方法,但似乎我尝试的每一件事我都弄乱了代码,它不起作用 #include<iostream> #include<string> using namespace std; int main() { // these 2 arrays will be used to count the letters in str

无法使直方图垂直。如何修改程序使直方图垂直?请帮帮我谢谢!这是代码。这个直方图是水平的,但我不知道如何使它垂直。使直方图垂直更具挑战性。我已经尝试了很多方法,但似乎我尝试的每一件事我都弄乱了代码,它不起作用

#include<iostream>
#include<string>
using namespace std;


int main()
{
    // these 2 arrays will be used to count the letters in string
    char letterArray[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y','z' };
    int letterCountArray[26];

    string userInputString;

    for (int i = 0; i < 26; i++) {
        letterCountArray[i] = 0;
    }
    
    cout << "****************************************THIS IS MY FREQUENCY PROGRAM*****************************************\n\n";
    cout << "Please input your sentence: ";
    getline(cin, userInputString);
    int lengthOfString = userInputString.length();
    for (int i = 0; i < lengthOfString; i++) {
        char letter = tolower(userInputString[i]);
        //finding this letter in letterArray so we can get it's position number and increment in counter array
        for (int j = 0; j < 26; j++) {
            if (letterArray[j] == letter) {
            
                letterCountArray[j] = letterCountArray[j] + 1;
            }
        }
    }
    // showing result
    cout << "\n\n***** Showing Result *****\n";
    cout << "----------------------------------------------------------------------------------------";
    cout <<"\n"<< "We have calculated the frequency of letters succuessfully and accurately for you\n\n";
    cout <<"\n"<< "See Below\n\n";
    for (int i = 0; i < 26; i++) {
        if (letterCountArray[i] > 0) {
            cout << "The letter '" << letterArray[i] << "' occurrs " << letterCountArray[i] << " times.\n";
        }
    }
    cout << "----------------------------------------------------------------------------------------\n";
    // showing histogram
    cout << "\n***** This is the Histogram: *****\n";
    // loop to display numbers and *
    for (int i = 15; i >0 ; i--) {
        cout.width(2);
        cout << i <<"|";
        for (int j = 0; j < 26; j++) {
            if (letterCountArray[j] == i) {
                cout << "* ";
                letterCountArray[j] = letterCountArray[j] - 1;
            }
            else {
                cout << "  ";
            }
        }
        cout << "\n";
    }   
    cout << "   ";
    for (int i = 0; i < 26; i++) {
        cout << "--";
    }
    cout << "\n";
    cout << "   ";
    // displaying letters from letterArray
    for (int i = 0; i < 26; i++) {
        cout << letterArray[i]<<" ";
    }
    cout << "\n";
    // stopPING the screen from dissappearing immideatly 
    system("pause");
    return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
//这两个数组将用于计算字符串中的字母
字符字符数组[26]={a',b',c',d',e',f',g',h',i',j',k',l',m',n',o',p',q',r',s',t',u',v',w',x',y',z'};
int-letterCountArray[26];
字符串userInputString;
对于(int i=0;i<26;i++){
letterCountArray[i]=0;
}

cout我从改变循环的顺序开始:首先是字母,然后是计数。 然后我改变了两个循环的方向。 然后,在打印星号和线条时,我对空格和虚线的数量做了一些调整

    cout << "\n***** This is the Histogram: *****\n";
    // loop to display numbers and *
    for (int j = 25; j >= 0; --j) {
        cout << letterArray[j] <<"|";
        for (int i = 1; i <= 15 ; ++i) {
            if (letterCountArray[j] >= i) {
                cout << " * ";
            }
            else {
                cout << "   ";
            }
        }
        cout << "\n";
    }   
    cout << "  ";
    for (int i = 1; i <= 15; i++) {
        cout << "---";
    }
    cout << "\n";
    cout << "  ";
    // displaying letters from letterArray
    for (int i = 1; i <= 15; i++) {
        cout.width(2);
        cout << i <<" ";
    }
    cout << "\n";
    // stopPING the screen from dissappearing immideatly 
cout=0;--j){
cout“我尝试了很多方法,但似乎我尝试的每件事都弄糟了代码,它不起作用。”似乎描述了一个问题,但您没有显示与此相关的代码,也没有显示“不起作用”的输出。请具体缩小您遇到的困难,显示您尝试过的内容,显示它输出的内容,显示您期望它输出的内容,并且有人肯定会提供帮助。否则,一个完全有效的解决方案可能是“将屏幕转向一边”。请阅读