English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ok here is the story, I had this assignment due that called for a program to test if a WORD (meaning no spaces, unless there is a word in the English language that has a space in it, and is still a word)...regardless my instructor marked me off 10 points! and the only thing he wrote on my paper was "function does not work". He gave me the lowest grade I’ve ever received in one of his classes, an 86.67%, personally I'm not sure whether to be mad, or ashamed of it. Regardless, I have tested this program NUMERIOUS times from before, and after I got it back from the instructor, and I have found NO errors within it, unless you enter something with a space(which the program was not required to have)!!!

The best answer will go to whoever can tell me wtf is wrong with my program, and tell me why I was marked off points. If you need a question format, why was my grade so low on this program.

A link to the program will be up soon.

2006-12-06 05:12:26 · 7 answers · asked by D 4 in Computers & Internet Programming & Design

http://www.geocities.com/youmember2001/recursion.txt

2006-12-06 05:12:39 · update #1

to test if a word is a palendrome or not...sorry that part got cut off.

2006-12-06 05:21:00 · update #2

assignment is written in C++

2006-12-06 05:25:44 · update #3

7 answers

//"Find out" the size the word entered
for (int i = 0;i < 100;i++)
{
if (breakapart[i] != 0)
listsize++;
}

//Assign memory array addresses to pointers
word = new char[listsize];

//Copy only "valid" data into first array
for (int i = 0; i < listsize ; i++)
word[i] = breakapart[i];


Ok, there's one error here, and a few "issues". The error first:
From the first block, you're determining how many non-zero characters start the buffer. For instance, the string "Hello" would result in listsize being 5 (not, not 6, which would include the first 0 byte found).
You then allocate a buffer of size listsize, note that this buffer is too small to actually hold the string in breakapart AND the 0 terminating character.
You then copy the characters from breakapart into word, but only the H, e, l, l, and o, NOT the 0 terminating byte. The array word is now an unterminated string.

The reason you haven't found this bug is probably because you've been running in debug, where a lot of memory is initialized to 0. When the function palindrome reached the end of the array passed in, it went off into memory and found a zero relatively quickly. However, when run in "release" or "optimized" mode, this may not happen, so the program would continue to test word farther and farther into random memory, never realizing it should have stopped after 5 characters (for the test buffer "Hello").

Finally, some style issues. If you want to find out how big a string is, use:
int listsize = strlen( breakapart );
// you may have to #include

Note you'll still need to allocate word to listsize+1, but then you can use:
strcpy( word, breakapart); // copies string from breakapart to word

Anyway, hope this helped. Essentially, the only thing you have to do to get it to work the way you want is to add one to listsize when you USE it:
word = new char[listsize+1];
...
for (int i = 0; i < listsize+1 ; i++)
word[i] = breakapart[i];

See?

2006-12-06 05:42:49 · answer #1 · answered by TankAnswer 4 · 1 0

Where is it's ability to accept hyphenated words? There are many hyphenated words that are true English words and your instruction for no symbols eliminates all of them.

Also, your instructions use "word" and do not mention any limit of English words only.

As to the grade? Go speak to your instructor and ask what the problem is. Don't spend all your time trying to prove it not true, find out what the teacher thinks and if think they are mistaken, ask if you can prove it to them.

When my students kept their mouths shut, they learned nothing. When they came to me with questions, they learned where it went wrong and once in a while actually learned that teachers can err also. Not often mind you, but we are human too so it can happen.

2006-12-06 05:43:26 · answer #2 · answered by Seikilos 6 · 0 0

i'm stunned by the question too. Who gave Canada this low score? there is quite some controversy in the Canadian's progression of their super Oil Sands projects in Alberta. The massive reserves of oil are no longer pumped from a properly like different oil reserves, they actually mine the sand that's rich in oil. they have more desirable a technique to eliminate the oil from the sand. Critics argue that it quite is an excellent earth-raping operation and does super harm to the ambience in comparison with the quite unintrusive approach of basically pumping it from a properly. on the different hand, i do no longer quite understand if it relatively is "Why" Canada scored low.

2016-10-17 21:51:04 · answer #3 · answered by ? 4 · 0 0

Hi

Lets start first , in what did you made the program , and then wish version of it ?

2006-12-06 05:19:15 · answer #4 · answered by Anonymous · 0 0

Try being nicer to the teacher, you'd be surprised the advantage a bit of comradery can get you.

2006-12-06 05:20:07 · answer #5 · answered by Answerer 7 · 0 1

i don't understand but, i'm sorry about your low grade. Hope you can figure it out and get a better grade.

2006-12-06 05:16:55 · answer #6 · answered by chedderapples 4 · 0 1

...To test if a word ???? What?

2006-12-06 05:17:42 · answer #7 · answered by chokscarlett 3 · 0 0

fedest.com, questions and answers