C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming
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.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 1st, 2003, 09:05 PM
jayrod914 jayrod914 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 4 jayrod914 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old December 1st, 2003, 10:40 PM
pianomahnn pianomahnn is offline
Can this change?
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 266 pianomahnn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 52 sec
Reputation Power: 9
Send a message via AIM to pianomahnn Send a message via Yahoo to pianomahnn
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.

Reply With Quote
  #3  
Old December 1st, 2003, 10:47 PM
jayrod914 jayrod914 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 4 jayrod914 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old December 1st, 2003, 10:54 PM
jayrod914 jayrod914 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 4 jayrod914 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;

ifstream infile (filename);
ofstream outfile ("file.dat");

a=0; e=0; i=0; o=0; u=0;

while (infile.get(ch))
{
outfile << ch;

switch (ch) {
case 'a' : a=a+1; break;
case 'e' : e=e+1; break;
case 'i' : i=i+1; break;
case 'o' : o=o+1; break;
case 'u' : u=u+1; break;
case 'A' : a=a+1; break;
case 'E' : e=e+1; break;
case 'I' : i=i+1; break;
case 'O' : o=o+1; break;
case 'U' : u=u+1; break;

}
}

cout << "A = " << a <<"\n";
cout << "E = " << e <<"\n";
cout << "I = " << i <<"\n";
cout << "O = " << o <<"\n";
cout << "U = " << u <<"\n";

outfile << "\n\n\n-----\n";
outfile << "A = " << a <<"\n";
outfile << "E = " << e <<"\n";
outfile << "I = " << i <<"\n";
outfile << "O = " << o <<"\n";
outfile << "U = " << u <<"\n";

return 0;

}

Reply With Quote
  #5  
Old December 1st, 2003, 11:06 PM
peenie's Avatar
peenie peenie is offline
Google Relay Server
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2003
Location: Oh christ I don't even know any more.
Posts: 1,810 peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)peenie User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 9953 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 1 Day 19 h 12 m 24 sec
Reputation Power: 436
Send a message via AIM to peenie Send a message via MSN to peenie
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.

Reply With Quote
  #6  
Old December 1st, 2003, 11:34 PM
pianomahnn pianomahnn is offline
Can this change?
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 266 pianomahnn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 52 sec
Reputation Power: 9
Send a message via AIM to pianomahnn Send a message via Yahoo to pianomahnn
Eh, so I assumed a bit too much. No big deal. I gave you a life lesson for when you want to do the same thing later on.

Either way, your wants were too many. I would've much rather seen your failed attempts in order to help narrow it down.

Coming to solutions on your own is wonderful. Being able to implement them, even more so.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Frequency Distribution


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap