When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
1 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
please put code in .cpp files so we can have syntax colouring.
I think you're supposed to create a second dictionary.
shoot sorry!
Yes I think you need two separate dictionaries.
Linked Lists I mean.
This is a very strange assignment.
Okay then don
Actually yeah you don't even need a second.
I don't get why your cleanword also adds to the dictionary.
It should only clean the word and not add to dictionary.
so do you mean this should not be here? " if (!cleanedWord.empty()) { // If the cleaned word is not empty
dictionary.insert(cleanedWord);"
Yes, and remove the parameter for the dictionary reference.
You want to do that outside the function.
do you think that is messing with the averages too ?
So in the loop .insert it into the dictionary
No, but you need to change that to fix the other issue.
Inside the loop for the book
Don't add the words to anything.
Clean the word.
Check spelling.
okay i will mess with that real quick
and write to the misspelled file.
Here's a tip.
for(istream bookFile("book.txt"); bookFile >> word;)
instead of the while loop
and you don't have to close bookFile manually
okay yeah i forgot that was a problem too it wasnt writing to the misspelled.txt file
this is correct, but it always feels so wrong when I see it lol
The program takes hours to run?
yeah the book.txt file has 1 million words and the dictionary has about 130k
does it complete? or does it just run forever
like those are big data sets, but not unreasonably so
yeah it runs it just doesnt give me the right dictionary size that it should be
and the averages should not be 0 or 1
Yeah, this should definitely be something that takes seconds or a minute at most, not hours lol
He's using a linked list.
Is this for school? Do you have to use linked lists?
I think he does.
haha yeah unfortunatly we cant use hash yet i havent learneed that yet its a linked list program
Ah
i can give more of the prompt here in a sec to help out sorry
i have been struggling with my cosc classes im minoring in it
here is more parameters and rules lol.
Yeah you definitely don't need two dictionaries.
do i still need to incorporate this inside of my ifstream bookFile code? or can i take it out completely and let it be its own thing
Yeah, now you just have to fix the inside of the loop.
what do you mean ?
I don't think your code works yet.
no not to the point where i want it to haha, let me take a step back you said that i don't need to insert anything into the dictionary. So is this more what you had in mind ? cpp string cleanWord(const string& word) { string cleanedWord; // Declaring a variable to store the cleaned word for (char ch : word) { // Loop through each character in the word if (isalnum(ch) || ch == '\'') { // Check if the character is alphanumeric or an apostrophe cleanedWord += tolower(ch); // Convert the character to lowercase and append it to the cleaned word } } return cleanedWord; // Return the cleaned word }
Correct.
so what did you mean by use the parameter outside of the function?
No, add to the dictionary outside the cleanword function.
So when you're reading in the dictionary file.
Read the word, clean it, insert it.
ifstream dictFile("dict.txt"); // Open the dictionary file
string word; // Declare a variable to store each word read from the file
while (dictFile >> word) { // Read each word from the dictionary file
dictionary.insert(word); // Insert the word into the dictionary
}
dictFile.close();
this is the area where im okay to be doing this then
im sorry my code is really messy
You didn't clean the word.
hows this look ? cpp ifstream dictFile("dict.txt"); // Open the dictionary file string word; // Declare a variable to store each word read from the file string cleanedWord = cleanWord(word); while (dictFile >> word) { // Read each word from the dictionary file dictionary.insert(word); // Insert the word into the dictionary } dictFile.close();
? what do you mean then im sorry im confused
ok its in it now im sorry
That looks good.
You could turn that into a for loop like before if you don't want to manually call dictFile.close
but that's not necessary
Although I would recommend that for future code.
ok ill keep it as is then
oh okay i gotcha
Alright so now I have removed my insert to the dict from the clean function, fixed my bookfile loop to a for, and added clean to the dictfile code. It just sucks to see if this fixes my avgs because it takes 2-3 hours to run do you think i should try to run the code and then come back here once its done to give you results?
Run it on a smaller sample.
So it doesn't take as long.
A sample small enough that you can manually check if the output is correct.
i used dict.txt as apple
banana
orange
grape
lemon
book.txt as apple
banana
lemon
watermelon
orange
im so glad if this works. I will get you the results here in a few hours i really appreciate you helping me out monkey your the goat
No problem.
okay so it finished, but my professor says this thing should be taking like anywhere from 2-5 hours of runtime. here are my results : dictionary size: 133168
Done checking and these are the results
finished in time: 447.531
There are 950068 words found in the dictionary
981990 compares. Average: 1.0336
There are 27075 words NOT found in the dictionary
981990 compares. Average: 36.2693
There are 4847 words not checked.
[Done] exited with code=0 in 473.85 seconds so this dictionary size is correct which is good. but the average compares dont seem right still and i believe that the words not checked has to be about 2554
here is the full prompt and i have some slide notes too i just dont understand what i am missing.
maybe i will ask him tomorrow in lecture whats going on i just dont get why my avg is 1
Compare your output with the expected.
Expected : dictionary size 133168
Done checking and these are the results
finished in time: 1306.53
There are 950068 words found in the dictionary
172150028 compares. Average: 181
There are 27075 words NOT found in the dictionary
19383592 compares. Average: 715
There are 2544 words not checked.
The word count seem to be correct.
mine : dictionary size: 133168
Done checking and these are the results
finished in time: 447.531
There are 950068 words found in the dictionary
981990 compares. Average: 1.0336
There are 27075 words NOT found in the dictionary
981990 compares. Average: 36.2693
There are 4847 words not checked.
Send new code maybe you aren't counting the comparisons properly.
okay i will send you my main and my linked list too im sure i messed something up
he gives us the timer code and we dont have to change it at all so i dont need to supply that
wrong code hold on
hows it look ?
I'm not sure how you're supposed to count the comparisons.
I mean here is the notes from the slides in class about this project
do you mean like how to count each comparison
single
idk if the notes help much
just extra stuff i had
okay thank you for the help, might have answers or quesstions about it tomorrow
No problem.
@uncut tartan Has your question been resolved? If so, type !solved :)
no
as for the misspelledfile writing that need sto happen after the timer stops, do i need to open up the book.txt read it again in order to append to the misspelledfile.txt ?
needs to*
my linked list stays unchanged
this is the most recent run of the code that I did with the output
UPDATE: I fixed my misspelled words count it was counting spaces too! Now i am just trying to figure out where i am going wrong with my averaging!
@novel ibex do you have any idea why my avgs are being weird?
@tame gale
Hi.
This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.
@tame gale are you available
<@undefined>
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.