help needed please for CS 110 class 
Author Message
 help needed please for CS 110 class

I am taking a comp Science 110 class (Turbo Pascal)this year and because of
having absolutely no programing experience I am finding course content a
bit tough.  Its not so much the concepts ,as the assignments  that the
prof. gives us.  Such as

Assume that a sentence is terminated by a period and that a character that
makes up part of the sentence can be anything but a blank.  Write a program
which accepts as input a sentence and which displays the number of
characters in the sentence.(periods  and spaces not included) You may
assume that the sentence can be typed in on a single line of input.

I realize for some of you this is a peice of cake but as for me I have had
3- 3 hour classes so far, so some of the concepts are a bit foggy.

Now for my question part of this message... Does anyone know of a good
place on the net for reference and some examples.  I find I can probably
learn better from example.

I am thinking part of the solution to the example will be counting the
number of Chars from an output line and some how getting it to loop over
the statement.  Here is kind of the idea I am starting to play with but I
may be far from correct.

Var
    Counter,sum:Integer;
    Output:Char;

Begin
Counter:=0;
Sum:=0;
Writeln ('Please enter a one line sentence ');
Readln (output);
Sum:=?+1 {for every character there is.}

One of the things that totally has me baffled is how to not count spaces
and periods as to the best of my knowledge spaces and . are refered to as
Char.

I realize one might be able to try a statement like if char=. then
Counter:=Counter.

Thanks for any help some may be able to give me..   I am starting to get
the thoughts of dropping this class.

//Thanks in Advance Brian



Wed, 18 Jun 1902 08:00:00 GMT  
 help needed please for CS 110 class

Quote:

> Assume that a sentence is terminated by a period and that a character that
> makes up part of the sentence can be anything but a blank.  Write a program
> which accepts as input a sentence and which displays the number of
> characters in the sentence.(periods  and spaces not included) You may
> assume that the sentence can be typed in on a single line of input.

> I realize for some of you this is a peice of cake but as for me I have had
> 3- 3 hour classes so far, so some of the concepts are a bit foggy.

> Now for my question part of this message... Does anyone know of a good
> place on the net for reference and some examples.  I find I can probably
> learn better from example.

> I am thinking part of the solution to the example will be counting the
> number of Chars from an output line and some how getting it to loop over
> the statement.  Here is kind of the idea I am starting to play with but I
> may be far from correct.

Basic idea seems workable. I'll give some comments with each line;

Quote:

> Var
>     Counter,sum:Integer;
>     Output:Char;             ^^^^ : You need to get 1 line into output, not just one character.

A string type variable would be more appropriate: stores up to 255 characters in
an array-like structure. You look at an individual char in a string using
array subscription: achar := astring[i]; The one thing that makes strings different
from arrays of char is, that the first byte of the string (index of 0) contains the
actual number of characters in a string. This gives you all the info you
need to loop over each charater: FOR i := 1 TO BYTE(str[0]) DO {whatever};

Avoid names like input and output, especially when using Turbo or Borland Pascal:
those compilers use these names to refer to standard input and output, so redefining
them is _not_ a good idea, since you block your channels to screen and keyboard...

Quote:

> Begin
> Counter:=0;
> Sum:=0;
> Writeln ('Please enter a one line sentence ');
> Readln (output);

Now you have you input string (line of text). How would _you_ attack the problem
on paper? Hint: look up the IF/THEN and FOR statements and the NOT operator.
(If you feel really courageous, look at sets as well)

Quote:
> Sum:=?+1 {for every character there is.}

well, you want to add one to sum and store the result:
 sum := sum + 1;

Quote:

> One of the things that totally has me baffled is how to not count spaces
> and periods as to the best of my knowledge spaces and . are refered to as
> Char.

> I realize one might be able to try a statement like if char=. then
> Counter:=Counter.

Close enough, the statement should read:

IF NOT ( (char = '.') OR (char = ' '))
  THEN sum := sum + 1

Quote:

> Thanks for any help some may be able to give me..   I am starting to get
> the thoughts of dropping this class.

> //Thanks in Advance Brian

Now you should have all the pieces to get something working. Don't forget
to test your program before handing it in. Hints: don't forget to display the
result and test, not only with simple stirngs, but also with strings of only spaces
and dots, and with empty strings (hit return without typing anything) or very long
strings.

Good luck,

Remco.

Note for others: this way of phrasing your questions works.
(people aimed at will understand what I mean >:))
--
_________________________________________________________________
Remco Vietor                            Department of Chemistry

                                        University of Glasgow
                                        Glasgow G12 8QQ
                                        U.K.



Wed, 18 Jun 1902 08:00:00 GMT  
 help needed please for CS 110 class

[...]

Quote:
>Assume that a sentence is terminated by a period and that a character that
>makes up part of the sentence can be anything but a blank.  Write a program
>which accepts as input a sentence and which displays the number of
>characters in the sentence.(periods  and spaces not included) You may
>assume that the sentence can be typed in on a single line of input.

>I realize for some of you this is a peice of cake but as for me I have had
>3- 3 hour classes so far, so some of the concepts are a bit foggy.

How about as easy as falling off a log, or stubbing a toe?  :-D

Quote:

>Now for my question part of this message... Does anyone know of a good
>place on the net for reference and some examples.  I find I can probably
>learn better from example.

Attacking your problem this way is like saying the best way to
learn how to design cars is by looking at cars.  While it might
give you ideas how to improve your design, it won't teach you
the skills you need to be able to do it yourself.  

Quote:

>I am thinking part of the solution to the example will be counting the
>number of Chars from an output line and some how getting it to loop over
>the statement.  Here is kind of the idea I am starting to play with but I
>may be far from correct.

I almost skipped your post, but I found a little redeeming
quality in your attempt to explain where you're at and how
you're approaching the problem.

Quote:

>Var
>    Counter,sum:Integer;
>    Output:Char;

>Begin
>Counter:=0;
>Sum:=0;
>Writeln ('Please enter a one line sentence ');
>Readln (output);

Have you considered the inconsistency of asking for a "line" but
reading only one character?  

The online help for Readln states:
  Executes the Read procedure then skips to the next
  line of the file.

There is something so important in this statement that further
down the screen it states in the remarks:
  After executing Read, Readln skips to the beginning
  of the next line of the file.

Even if I entered 100 characters, your readln-statement will
only accept the first character.

Hint:  Use a string variable.

Quote:
>Sum:=?+1 {for every character there is.}

You lost me here.

Quote:

>One of the things that totally has me baffled is how to not count spaces
>and periods as to the best of my knowledge spaces and . are refered to as
>Char.

Yes, Brian, periods and spaces are characters.  The fact that
they are characters and that a string is a series of characters
is the key that allows you to complete the task.

Forget the idea of writing a program for a moment and consider
writing the instructions that _you_ would have to follow in
order to complete the task.  Forget Pascal and simply write the
instructions in the language you use every day to express your
thoughts, ideas and emotions.  Use indentation and words like
EndIf, EndWhile, EndFor to group multiple statements associated
with a particular thought.

I would write something like:

   Read a line.
   Set a counter to zero.
   For every character in the line
      If the current character is not a space or a period Then
         add one to the counter
      EndIf
   EndFor
   Write the value of counter.

Or maybe something like:

   Read a line.
   Set counter to zero.
   Set CurrentPosition to zero.
   While CurrentPosition is less then the length of line Do
     Increment CurrentPosition.
     If character at CurrentPosition is not a space or period
     Then
        Increment Counter.
     EndIf.
   EndWhile.
   Write value of Counter.

If you wrote the steps with enough detail, then the only thing
you have left is to translate your instructions into the target
programming language.  BTW, Brian, a lot of us like Pascal
because it is so close to a pseudo language, that the statements
we write end up being very close to the code we need!

Quote:

>I realize one might be able to try a statement like if char=. then
>Counter:=Counter.

Your closer than you think.  Add quotes to and you will just
about have it.  
  If (Line[CurrentChar] <> '.')
  and (Line[CurrentChar] <> ' ')
  Then
     ...

Quote:

>Thanks for any help some may be able to give me..   I am starting to get
>the thoughts of dropping this class.

You're finding all this overwhelming only because you aren't
considering how you would do the task yourself.  Only after you
are able to do the task yourself can you hope to teach someone
else.  And don't forget, the someone you are trying to teach has
an IQ just above a rock, so keep the steps simple. :-D

    ...red

--
Support the anti-Spam amendment
  Join at http://www.cauce.org/



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. over-110.zip Optimized TP6/BP7 Overlay unit

2. em8x-110.zip Optimized TP6/BP7 hardware emulator files

3. Error 110

4. Problem with Delphi3 CS and Sybase 11 - HELP please

5. Please HELP: class not found

6. Help my class Please.

7. Class not registered, Please help me

8. Need help with Hailstone Sequence program please Help

9. need help on prcedures (please help)

10. I need help fixing this CASE Select code, please help

11. HELP ME PLEASE I NEED HELP ON PROGRAMMING THIS>>>>|||

12. Delphi CS 1.02 to Sybase Help

 

 
Powered by phpBB® Forum Software