CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 8th, 2009, 10:15 PM
    CNovice CNovice is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 5
    CNovice is an unknown quantity at this point (<10)
    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.
    Reply With Quote
      #2    
    Old November 8th, 2009, 10:26 PM
    Arjay's Avatar
    Arjay Arjay is offline
    Moderator / MS MVP
    Power Poster
     
    Join Date: Aug 2004
    Posts: 6,914
    Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+)
    Re: Stuck on a programming assignment

    What code do you have so far?
    Reply With Quote
      #3    
    Old November 8th, 2009, 11:44 PM
    CNovice CNovice is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 5
    CNovice is an unknown quantity at this point (<10)
    Re: Stuck on a programming assignment

    Absolutely nothing. I don't know even know where to start.
    Reply With Quote
      #4    
    Old November 8th, 2009, 11:53 PM
    Paul McKenzie Paul McKenzie is offline
    Elite Member
    Power Poster
     
    Join Date: Apr 1999
    Posts: 20,960
    Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+)
    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
    Reply With Quote
      #5    
    Old November 8th, 2009, 11:54 PM
    Arjay's Avatar
    Arjay Arjay is offline
    Moderator / MS MVP
    Power Poster
     
    Join Date: Aug 2004
    Posts: 6,914
    Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+) Arjay has a reputation beyond repute (3000+)
    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.
    Reply With Quote
      #6    
    Old November 9th, 2009, 03:10 PM
    CNovice CNovice is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 5
    CNovice is an unknown quantity at this point (<10)
    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("%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.
    Reply With Quote
      #7    
    Old November 9th, 2009, 04:28 PM
    Paul McKenzie Paul McKenzie is offline
    Elite Member
    Power Poster
     
    Join Date: Apr 1999
    Posts: 20,960
    Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+)
    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
    Reply With Quote
      #8    
    Old November 9th, 2009, 05:02 PM
    Lindley Lindley is online now
    Elite Member
    Power Poster
     
    Join Date: Oct 2007
    Location: Fairfax, VA
    Posts: 6,905
    Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+)
    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.
    Reply With Quote
      #9    
    Old November 9th, 2009, 07:21 PM
    CNovice CNovice is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 5
    CNovice is an unknown quantity at this point (<10)
    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.
    Reply With Quote
    Reply

    Bookmarks

    Tags
    c programming , c++ , code , shannon entropy , visual studio
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:55 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.