I need to read in sentence and then put each letter into an arraylist. When I'm done I need to out put the letter that were in the sentence and how many times they appeared.
ex:
hello how are you
h2
e2
l2
o3
w1
r1
y1
u1
So, I need to read in a string send the first letter, h, to an arraylist. Then when it gets to e, check the arraylist to see if e already exists, since it doesn't I send it to a different position in the arraylist. When it gets to the first l it will send it ot the arraylist. when it gets to the second l it will check and find the l. I getEntry increment the count to 2 and then setEntry. I understand the logic, not the implementation. Here is what I have.
#include "ArrayList.h"
#include <iostream>
#include <string>
struct ItemType
{
char letter;
int count;
};
int main()
{
ArrayList<ItemType> mylist;
ItemType anItem;
string sentence;
cout << "Please enter a sentence: "<< endl;
getline(cin,sentence);
for (int i= 0; i<sentence.length(); i++)
{
anItem.letter = sentence[i];
anItem.count ++;
}
mylist.insert(1,anItem);
for (int i=0; i<mylist.getLength(); i++)
{
ItemType anItem = mylist.getEntry(i+1);
cout << anItem.letter << anItem.count << endl;
}
return 0;
}
If i could get some help, any type of little tips, that's be great.