![]() |
|
#1
|
|||
|
|||
vectors.. calculating # of occurencesi wanna my program to read a text and calculate the number of occurrences of each letter in the file... this is what i have so far:
CPP / C++ / C Code:
where do i go from here... Last edited by LuciWiz : 03-Dec-2005 at 12:57.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
||||
|
||||
Re: vectors.. calculating # of occurencesHi blablabla(What is your name?)
Welcome to GIDForums. Since your program is to read a text and calculate the number of occurrences of each letter in the file..., there is no need for a vector. Dont use assert. It is only for debugging purposes. Instead, use if statements. So, to check the number of occurences, create a new character say c. Create a counter say 'i' which is initialized to zero. Then, use a while loop until the end of the file. Get each character from the file one by one, and check whether it is equal to c. It it is, then increment a counter i. So, here is a sample: CPP / C++ / C Code:
If you want to find the occurence of any other character, simply change this statement: CPP / C++ / C Code:
And remove all unnecessary headers: cassert, numeric, and vector. If you are not going to get command line arguments, you can change the main function simply like this: CPP / C++ / C Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#3
|
|||
|
|||
Re: vectors.. calculating # of occurencesok .. i get u ..
but the thing is the program has to find the number of occurrences of each letter ( all 26 letters) from the same loop ... not one by one the thing is i was instructed (lol) to use a vector of length 26 to do this ... sucks huh? .. bcuz i know there must be other easier ways to do this without using vectors... but i have to do it the vector way so the program must be able to give the occurrences of all 26 letters and must recognize uppercase letters as the lowercase equivalent.. but i will try to work with what u gave me .. see if i can take it from there thanks much |
Recent GIDBlog
A Week in Kuwait by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| vectors of references | mirizar | C++ Forum | 1 | 12-Apr-2005 02:02 |
| newbie needs help with vectors | Quesius | C++ Forum | 0 | 30-Nov-2004 23:35 |
| C++ Vectors | Katie | C++ Forum | 5 | 17-May-2004 23:36 |
| Declaring a vector of vectors? | Lethal411 | C++ Forum | 2 | 20-Mar-2004 09:02 |
| Calculating mathematical string | flowercamel | C Programming Language | 9 | 04-Feb-2004 13:55 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The