Exercise 1-11. How would you test the word count program? What kinds
of input are most
likely to uncover bugs if there are any?
Exercise 1-12. Write a program that prints its input one word per line.
help me with these questions......
HELP with QUESTIONS!!!!!!!!
Started by lionaneesh, Mar 22 2010 11:20 AM
3 replies to this topic
#1
Posted 22 March 2010 - 11:20 AM
|
|
|
#2
Posted 22 March 2010 - 11:52 AM
What word count program are you talking about?
#3
Posted 23 March 2010 - 07:55 PM
The types of input that would be most likely to incur bugs would depend on the way the code was written. So we'd have to see the code. I'd say, generically, inputs with multiple whitespace between them, inputs with digits in it, inputs with multiple lines, inputs with punctuation, inputs with hyphens, etc...
#4
Posted 23 March 2010 - 08:04 PM
As for the second question...
I don't want to give you code on it, because it's something you should learn to do yourself. But think about it. Assuming you wrote the word count program, it should operate fairly similarly. store the input into a string, go through and print the string one character at a time. as you encounter whitespace, instead of printing that character, print the newline character.
A few notes:
-You'll have to account for multiple spaces/tabs in a row. you don't want to have your program put several new lines in-between words.
-You'll have to figure out what you want to do with punctuation.
-IE: you get "hi. bye."
you could print this:
hi.
bye
with no problems, the way described above. however, you could also arrange for it to print:
hi
.
bye
if you wished. the problem with the algorithm described above, however, lies when you reach something like: hi.bye
it would print:
hi.bye
So you need to handle this, so it prints it one of the other ways.
I don't want to give you code on it, because it's something you should learn to do yourself. But think about it. Assuming you wrote the word count program, it should operate fairly similarly. store the input into a string, go through and print the string one character at a time. as you encounter whitespace, instead of printing that character, print the newline character.
A few notes:
-You'll have to account for multiple spaces/tabs in a row. you don't want to have your program put several new lines in-between words.
-You'll have to figure out what you want to do with punctuation.
-IE: you get "hi. bye."
you could print this:
hi.
bye
with no problems, the way described above. however, you could also arrange for it to print:
hi
.
bye
if you wished. the problem with the algorithm described above, however, lies when you reach something like: hi.bye
it would print:
hi.bye
So you need to handle this, so it prints it one of the other ways.


Sign In
Create Account


Back to top









