-4

Sorry guys forewarning I suck at coding but have a big project and need help!

Input: A complete Sentence.

Output: The sorted order (ASCii Chart Order) of the sentence (ignore case.)

Output a histogram for the following categories:
1) Vowels
2) Consonants
3) Punctuation
4) Capital Letters
5) LowerCase Letters

I have no clue what to even do

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
jv1234
  • 1
  • 2
    Stack Overflow is not really a place for where to start questions. We generally solve specific programming problems. – NathanOliver Apr 22 '16 at 14:13
  • Can you provide us with an example of the code you've got so far and any errors you have, be forewarned this is a place to learn.. Not some where to come if you want another person to write your code for you – suroh Apr 22 '16 at 15:54
  • As always, research to see if this project already exists. Also search if parts of the project have already been written. For student assignments and homework, search for existing examples. – Thomas Matthews Apr 22 '16 at 16:01
  • Update your post with specific items you are having issues with. For example: do you know what a vowel is? Do you know how to input a sentence? Do you know what a `std::string` is? Do you know what a *histogram* is? Do you know how to sort? Can you use sorting functions from libraries? – Thomas Matthews Apr 22 '16 at 16:23

2 Answers2

0

Since you are vague in what your issue is, I recommend the following process:

Review Requirements

Always review the requirements (assignment). If there are items you don't understand or have the same understanding as your Customer (instructor), discuss them with your Customer.

Write a simple main program.

Write a simple main or "Hello World!" program to validate your IDE and other tools. Get it working before moving on. Keep it simple.

Here's an example:

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

int main()
{
   std::cout << "Hello World!\n";
   return EXIT_SUCCESS;
}

Update program to input text & validate.

Add in code to perform input, validate the input and echo to the console.

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

int main()
{
   std::string sentence;
   do
   {
      std::cout << "Enter a sentence: ";
      std::getline(cin, sentence);
      if (sentence.empty())
      {
          std::cout << "\nEmpty sentence, try again.\n\n"
      }
   } while (sentence.empty());
   std::cout << "\nYou entered: " << sentence << "\n";

   // Keep the console window open until Enter key is pressed.
   std::cout << "\n\nPaused. Press Enter to finish.\n";
   std::cin.ignore(100000, '\n');

   return EXIT_SUCCESS;
}

Add functionality, one item at a time and test.

Add code for one simple requirement, compile and test.
After it works, make a backup.
Repeat until all requirements are implemented.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
0

For ordering the string you can use standard c qsort function. For counting vowels, consonants, punctuation... you need a simple for loop.

Here is a working example:

#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;
}

Note that I used C standard functions for counting capital, lower case and punctuation, and I had to use strchr function for counting vowels and consonants because such functions are missing in standard C library.

The output of the program is:

Input: 'A complete sentence.'
Result: '  .Acceeeeelmnnopstt'
Capital chars: 1
Lower case chars: 16
Punctuation chars: 1
Vowels chars: 7
Consonants chars: 10
Carlo
  • 1,539
  • 1
  • 11
  • 25