CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Alphabet soup

  1. #1
    Join Date
    Apr 1999
    Posts
    4

    Alphabet soup

    Help me fiqure out??????
    i was given a program to rewrite has problems in it........here is the code i was given to complete
    should run alphbet Row 1: A-M Row 2: a-m Row 3:N-Z
    Row 4: n-z while keeping trac of hit example A:01, B:25 so on etc here it code have to follow and tips will be appreciated
    Thanks for your comments and help

    #include <iostream>
    using namespace std;
    void main(void)
    {

    int counts[52];
    int words = 0;
    int characters = 0;

    void init(int *);
    int input(int *, int *);
    void output(int *,int, int);

    init(counts);
    characters = input(counts, &words);
    output(counts, characters, words);
    }
    int input(int * counts, int * words)
    {
    char ch;
    int characters = 0;
    int in_a_word = 0;
    characters++;

    while((ch = cin.get()) != EOF)
    {


    if(ch >= 'a' && ch <= 'z')
    counts[ch - 'a']++;
    else if (ch >= 'A' && ch <= 'Z')
    counts[ch - 'A' + 26]++;
    if (ch == ' ');
    if (in_a_word == 1)
    {
    (*words)++;
    in_a_word = 0;
    }
    else
    in_a_word = 1;

    if(ch!=' ')words++;
    cout << characters;
    }

    return characters++;

    }


    void output(int * counts, int characters, int words)
    {
    for(int b = 0; b < 13; b++)
    cout << 'A' + b << ':' << counts[b];
    for(int a = 0; a < 13; a++)
    cout << 'a' + a << ':' << counts[a];
    for(int c = 14; c <= 26; c++)
    cout << 'N' + b << ':' << counts[c];
    for(int n = 14; n <= 26; n++)
    cout << 'n' + n << ':' << counts[n];
    }
    void init(int * counts)
    {

    }










  2. #2
    Join Date
    May 1999
    Posts
    25

    Re: Alphabet soup

    Well - I can see what the program is attempting to do.
    It is trying to count the words and the occurence of each alphabetic character entered.

    However there are soo many things wrong/faulty -here are some:

    1. You have function delcarations within main;
    2. The init() function does not intialise anything so the output is garbage.
    3. The input() function is bad
    4. Characters other than A-Z and a-z such as carriage returns, 0-9, and other characters are included
    in the number of caharcters collected - but are not accounted for.
    5. I am not very familiar with cout - but as it the output function stands it will display the decimal value of the characters not the characters themselseves.
    For example it will display 65 for A.

    6. When the end of file (ctrl+Z) is received in the middle of the word this 'part word is not added to the word count but number of characters have been
    included in the character count.

    7. And on and on and on...



  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: Alphabet soup

    Homework assignment?

    Dave


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured