Jump to content

HELP with QUESTIONS!!!!!!!!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
lionaneesh

lionaneesh

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
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......

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What word count program are you talking about?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Osnarf

Osnarf

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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
Osnarf

Osnarf

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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.