Discuss Frequency Distribution in the C Programming forum on Dev Shed. Frequency Distribution C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
Frequency Distribution
I am just in my first year of programming and I am still a little confused and I was wondering if anyone could help on this program I am trying to do. Thx.
Description: Frequency Distribution Program – Write a program that will process an input file and determine the frequency distribution for the length of words in the file. For our purpose a word is defined as 1 or more alphanumeric characters. The length of the word will not exceed 78 characters in length. Output should consist of a summary of the distribution list and output should be directed to the screen as well as an output file.
Code your algorithm for your solution to include the following:
Prompt and accept the names of the input and output files.
When printing the summary, only print results for lengths of words totals that are greater than zero.
Example:
1 character words = 13
2 character words = 21
3 character words = 7
4 character words = 14
5 character words = 5
6 character words = 6
7 character words = 1
10 character words =3
Use good use of whitespace, and internal documentation. Use functions and procedures as needed.
Posts: 266
Time spent in forums: 3 m 52 sec
Reputation Power: 9
Drop out now.
Getting others to do your homework is:
1) Stupid
2) Against your university's policies
3) Against everything I stand for
4) Not going to teach you a damned thing.
You need to sit down and put forth a valiant effort, then come on back with SPECIFIC questions regarding your assignment. Only then will I (and most others) help you out.
Good luck.
edit: Doesn't your university have course assistants or instructors able to better guide you? I know mine does.
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
First of all I am only 15. I am learning C++ on my own, because I really like computers. I found this program on the internet so I thought I would mess around and try to figure it out just for teh heck of it. So, I don't attend a university and I don't have any teachers or tutors to help me. So, I thought I would turn to one of these forums for help, but undoubtley yall like to make assumptions. Thanks for all your wonderful help.
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
I do put forth effort. I did this code the other day, and I know all I have to do is manipulate it to get to work.The code below is to count the number of vowels in a file. Just can't figure out the problem I have already stated and that rudely replied to. Can you get that your head now, I AM NOT A STUDENT IN A C++ CLASS! I just need help.
#include <iostream.h>
#include <fstream.h>
int main ()
{
int a;
int e;
int i;
int o;
int u;
char ch;
char filename [12];
cout << "What file would like to run?\n";
cin >> filename;
Posts: 1,810
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 436
The solution to your problem would be similar to the solution to the vowel counting problem, in that you'd have separate variables to keep track of the counts of different length words; one variable for each length. To keep things simple, you'd probably just want to keep track of say, words between 1 and 10 characters in length -- although there are many possible ways to allow for words of any length at all.
Then, the only problem left is how to read one word at a time and count the words based on length. Reading a word at a time is simple, and can be done by using the >> ifstream operator to read into a 'string' or a char[] array. If you are using a 'string', then the length() method of string will help you. For char[] arrays or char * pointers, the strlen() function will do what you need.
So you'd basically just read one word at a time, figure out that word's length, then increment the appropriate acount variable depending on the length. You can have 10 separate count variables (assuming you are looking at words from 1 to 10 chars in length) named something like n1, n2, n3, ..., or you could use an array of 10 integers, perhaps declared as "int counts[10];". Either way would work; the advantage of an array is that you can index it with another variable (e.g. counts[len] = counts[len] + 1), which will save you some typing.
Hope that helps,
J.C.
Edit: Also, if you are using >> to read from an ifstream, you can the good() method of ifstream to check to see if more data can be read or if you are at the end of the file (or there is an error).
Last edited by peenie : December 1st, 2003 at 11:09 PM.