CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2009
    Posts
    5

    Stuck on a programming assignment

    I am completely confused at how to go about putting together a code for the following:


    I must accept a string of up to 256 characters from the user, and display the following information about the string:

    -The count, frequency, and probability of each character that appears in the string in decreasing order
    -Compute the Shannon Entropy of the string in bits.


    Thank you for taking the time to read this post, I greatly appreciate any and all help I can get.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Stuck on a programming assignment

    What code do you have so far?

  3. #3
    Join Date
    Nov 2009
    Posts
    5

    Re: Stuck on a programming assignment

    Absolutely nothing. I don't know even know where to start.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Stuck on a programming assignment

    Quote Originally Posted by CNovice View Post
    Absolutely nothing. I don't know even know where to start.
    So what are we supposed to do to help you?

    Start here:
    Code:
    int main()
    {
      // fill this in
    }
    Regards,

    Paul McKenzie

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Stuck on a programming assignment

    Start with programming up a simple console app where you get input from the user.

    Create the main function and prompt the user for the input.

    Once you have that, post your code.

  6. #6
    Join Date
    Nov 2009
    Posts
    5

    Re: Stuck on a programming assignment

    Please don't get me wrong, I don't expect anyone to do the come up with a code for me. I'm just lost as far as how to calculate the count, frequency, and probability of a string of 256 characters. If anyone could at least show/link me some examples of this type of code. This is my first C programming class and I'm having trouble understanding it. This must sound silly to you professionals, but here is as far as I've gotten (probably totally off but I'm willing to work it 'til I've got it down):

    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<time.h>

    int main()
    {
    int count
    int frequency
    int probablity

    printf("Enter Character String (max 256): ");
    scanf("&#37;d, &count&frequency&probability);

    return 0;


    }

    Long story short, i need a code to generate the count, frequency, probability, of each character that appears in the string
    Last edited by CNovice; November 9th, 2009 at 03:41 PM.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Stuck on a programming assignment

    Quote Originally Posted by CNovice View Post
    Please don't get me wrong, I don't expect anyone to do the come up with a code for me. I'm just lost as far as how to calculate the count, frequency, and probability of a string of 256 characters.
    You have an array of 26 integers, all elements of the array are set to 0. Then you loop through the string, and for every character i, you increment the count in array[i]. Then after the loop is finished, you have an array of the count of each character -- part 1 is done.

    If you do not understand the above, please point to what you don't understand. You must have the fundamentals first (an array, loops, etc.) before doing anything else. Programming requires knowledge being built up from a base -- you can't just start from nowhere and all of a sudden, start coding an assignment.

    Regards,

    Paul McKenzie

  8. #8
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Stuck on a programming assignment

    I'm not sure why they think that count, frequency, and probability are three different things. Count and probability are certainly different, but frequency could be the same as either of them depending on how you define it.

  9. #9
    Join Date
    Nov 2009
    Posts
    5

    Re: Stuck on a programming assignment

    Thank you all for you input. This subject is very hard to understand. Maybe my brain isn't built for computer science after all.

Tags for this Thread

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