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.
Re: Stuck on a programming assignment
What code do you have so far?
Re: Stuck on a programming assignment
Absolutely nothing. I don't know even know where to start.
Re: Stuck on a programming assignment
Quote:
Originally Posted by
CNovice
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
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.
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
Re: Stuck on a programming assignment
Quote:
Originally Posted by
CNovice
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
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.
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.