home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2968
Discussions: 188,378, Posts: 2,243,450, Members: 232,606
Old November 30th, 2008, 06:49 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Nov 2008
Posts: 2
Letter Count Array

Im writing a program that counts the amount of letters with the user input. I would love it if someone could correct my coding. I am not sure if it runs because I wrote it from the top of my head. I dont have a compiler so it would be really great if someone could fix it for me.

my output needs to be something like this:

Enter a sequence of characters (end with '.'): bcccacaca. dfg

Letter: Number of Occurrences
a 3
b 1
c 5

This is what I have so far. I wrote some comment. If someone could fix up my code that would be great. Im really stuck on it

#include <iostream>
#include <iomanip>
#include <cctype>
using namespace std;

const int NUM_LETTERS = 26;
int frequency;
char letter;
};

int indexOfLargest(letterFrequency frequencyArray[], int startingPoint); void sortFrequencyArray(letterFrequency frequencyArray[]); void countLetters(letterFrequency freqencyArray[]); void initFrequencyArray(letterFrequency frequencyArray[]); void printFrequencyTable(letterFrequency frequencyArray[]);


int main()
{
letterFrequency frequencyArray[NUM_LETTERS];

initFrequencyArray(frequencyArray);
countLetters(frequencyArray);
sortFrequencyArray(frequencyArray);
printFrequencyTable(frequencyArray);
system("PAUSE");
}

void initFrequencyArray(letterFrequency frequencyArray[])

{
for (int count = 0; count < NUM_LETTERS; count++){
frequencyArray[count].frequency = 0;
frequencyArray[count].letter = 'a' + count;
}
}


void countLetters(letterFrequency frequencyArray[]) {
char ch;
cout << "Please enter a sequence of characters terminated with a period ('.'): "<<endl;
cin.get(ch);
while (ch != '.')
{
for (int i = 0; i < strlen(s); i++)
{
s[i] = tolower(s[i]);
for (int j = 0; j < SIZE; j++)
{
if (s[i] == alphabet[j])
{
count[j]++;

cin.get(ch);
}
}

void sortFrequencyArray(letterFrequency frequencyArray[]) {



int indexOfLargest(letterFrequency frequencyArray[], int startingPoint) {

for (int j = 0; j < SIZE; j++)
{

if (s[i] == alphabet[j])
{
count[j]++;

void printFrequencyTable(letterFrequency frequencyArray[])
{
cout <<endl<< "Letter:" << setw(5) << "" << "Number of Occurrences:" << endl;
for (int i = 0; i < SIZE; i++)
{
//Only print the letters that occurred at least once in the sentence
if (count[i] > 0)
{
cout << alphabet[i] << setw(5) << count[i] << endl;

}

Takkun is offline   Reply With Quote
Old November 30th, 2008, 07:39 PM     #2 (permalink)
Member
 
Join Date: Oct 2003
Posts: 255
c++?...eclipse makes a fee c++ ide...never used it, but its free...try that out.

amtrac24 is offline   Reply With Quote
Old November 30th, 2008, 07:41 PM     #3 (permalink)
Junior Member
 
Join Date: Nov 2008
Posts: 2
I use a mac now. I have xcode on my computer but I dont know how to use it. when I had a PC I just used Bloodshed Dev C++
The assignment is due tomorrow so Im rushing to get it done. But I am runnning into many problems unfortunately

Takkun is offline   Reply With Quote
Old December 2nd, 2008, 12:34 AM     #4 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,792
Send a message via AIM to Rootstonian
Wow...that's a big "mess" of code

Why not set up an array.

int alpha_counter[26];

To load it...for example if letter = a, alpha_counter[0] +=1

psuedo code

while letter not equal '.'
{
you could get fancy with for loops or easier,
just code 26 if statements as above
}
Then just for loop through array and print results
cout << "number of A's was " << alpha_counter[i] << endl;

Last edited by Rootstonian : December 2nd, 2008 at 12:39 AM.
Rootstonian is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may 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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any such software as this? to count the # of words in a letter or post? John Prophet IMO Community 12 April 23rd, 2005 07:26 PM
Could not find array galehickey Technical Support 10 July 10th, 2004 11:42 PM
SCSI Array FS darrelld Traders Forum: Buy, Sell, Trade 23 October 18th, 2003 04:06 AM
Help for my new raid array Uncle Bob Storage Related 4 July 24th, 2003 02:26 PM
Ful post count and post count cracked Suggestion Box 22 December 10th, 2002 06:46 PM

Most Active Discussions
Is It Just Me? (2883)
The United States Debt (20)
Looks like Burris will get his Sena.. (7)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Titan quest and Immortal Throne, an.. (17)
Recent Discussions
dual monitors wont boot (0)
Folderchat Weekday thread (439)
New Build ( Finally ) (0)
MSN Hotmail Down??? (7)
Help with an Ati Radeon HD 4850.. (23)
Laptop waking up itself (0)
CPU wont boot (3)
Best digital camera for under 2.. (13)
Building first computer, will t.. (2)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:14 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28