please debug this

i got this far on the problem, can someone please help me along the rest of it? thanx -Steve...here is the code:

#include<iostream.h>
#include<iomanip.h>
#include<string.h>
array_size=65;
string_size=80;

class wordcount
{
      public:
         void wordcount();
      int entertext();
      int uppercase();
      int sortdata();
   private:
         char strarray1[arraysize][stringsize];
      char strarray2[arraysize][stringsize];
      int k;
};
wordcount::wordcount()
{
      //????????
}
int wordcount::entertext()
{
      cout<<"enter text: ";
   for (k=0;k<arraysize;k++)
         cin>>strarray1[k];
}
int wordcount::uppercase()
{
      for(k=0;k<arraysize;k++)
         strcpy(strarray2[k],strarray1[k]);
   for(k=0;k<arraysize;k++)
         strupr(strarray2[k]);
}
int wordcount::sortdata()
{
      //??????
}
void main()
{
      wordcount.s1;
                  s1.uppercase;
                  s1.sortdata;
}
alter7148Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
What is it doing wrong?
0
nietodCommented:
some inprovements.

Make "k" a local variable to uppercase() not a data member.

The three member procedures are declared to return int's.  But none of them do.  There is no reason for them to return int's so declare them to return void.
0
nietodCommented:
I see a bug.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

nietodCommented:
you start of testing by calling uppercase() on s1.  However, you haven't filled in the strarray1 in s1 yet. This means that straray1 contains garbage. This means that some of the strings might appear to be unterminated, that is, too long for the storage space you set aside.  So when you try to copy the information to strarray2 you could be causing memory access violations.

Soluton.  Have your constructor initialize strarray1.  Or keep an integer count of the number of entries in strarray1 that are valid.  Initialize this to 0.  (The advantage to this is that you don't have to always completely fill the array when you enter the data).
0
alter7148Author Commented:
ummm yea thats all great an dandy about what ya said, but i still don't knwo what the heck to do!??! i mean ya said that stuff but it goes in one ear through the other. heh
and i don't know what to put in the wordcount::sortdata() fuction and the wordcount::wordcoount()function and also the rest of the main function.
-Steve
p.s. would you need the wording of the problem given to me by a co-worker?
0
nietodCommented:
When you create wordcount object like

wordcount.s1;

The strarray1 (and 2 as well) contain garbage.  You do not attempt to initialize them.  So when you do

s1.uppercase();

the program will try to copy garbage from strarray1 to strarray2.  This will probably cause it to crash.

You must prevent this somehow.  How is up to you and your needs.  You could
A.  Initialize strarray1 so it does not contain garbage by making each string stored a NUL string, that is, a string that contains no characters.  You could do this in the constructor.
B.  Keep track of how many strings are actually stored in strarray1 and make uppercase() copy only those strings that are actually stored.  (You have room for array_size strings, but you haven't necessarily filled in array_size entries.)
C.  You can make sure that every string in the array has been set before you call uppercase() or other functions.

As to the sort function, I have no idea what it is supposed to do.  What is supposed to be sorted?

As for counting words.  Create a function that counts the number of words in a string and returns this number.  Then use a for loop to count the words in each string stored in the array and sum them up.  Again you will need to know how many stings in the array have been set or you will need to set all the strings in the array.
0
alter7148Author Commented:
ok, i still am having a lil trouble with it, maybe this will help ya, it's what my co-worker gave me:
C++ Language Question
    Title: "C++ program to perform to read non-punctuated text and give word frequency"

    How to implement a C++ program to perform a case-insensitve, frequency of occurance, analysis of words contained within a
    non-punctuated text. Only blank spaces between words, newline characters, and a single $ to mark end of text.
    Example text: Yellow Blue Green BLUE Red GREEN yellow $
    Example output: Word:   Frequency:
                    BLUE       2
                    GREEN      2      CONVERT ALL WORDS TO
                    RED        1        UPPERCASE
                    YELLOW     2       in alphabetical order
0
nietodCommented:
Co-worker?  I think you mean teacher.

Given that assignment.  I think you are going about it the wrong way.  You have created a data structure to store the data that is entered (each line, as it is entered).  You don't need that.  You just need to read input a word at a time and process the word.  You don't need to store each line.

What you need to do is for each word, convert it to uppercase and then look for it in a list of words.  If it is in the list.  Increment the count associated with the word.  If it is not in the list.  Add it to the list and set its count to 1.  

Now the best way to do that would be to use the STL's map<> template.  That will do 99% of the work for you.  If you are allowed to use it.
0
alter7148Author Commented:
huh, i dunno what that is, and yes a co-worker, but i tink he had it fer a class i dunno?
0
nietodCommented:
Well does your co-worker understand?  If not can he ask specific questions.  It is unethical for me to provide him with a complete answer, but I can give advice, answer specific questions, and look over and critique code he has written.  
0
alter7148Author Commented:
i just wrote that code fer ya!
0
nietodCommented:
That code is not appropriate for the task.  You need to create a structore that stores a list of words and the associated counts.  Each time a new word is encountered add it to the list with a count of one.  Each time a word in the list is found increment the count.

That's the general approach.  Now do you have specifc questions?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.