Copyright © – Sudharsan Iyengar

 

CS – 234.                    Lab 6 – Iteration                     2/27/25 & 3/4/25

 

Write a class, that has methods to do the following:

 

a)     Receives an integer value and returns a string with:

a.      all the digits separated by a space

b.     followed by the sum of all the digits. If this sum is greater than 10 then this process is repeated until the sum is less than 10.

 

Ex:                              parameter value is 8886

 

                              returns a string when output should look like

 

                                          8 8 8 6 = 3 0 = 3

 

b)     Receives a String (word) and returns:

a.      the word with all letters capitalized.

b.     Followed by the word with only the first letter capitalized.

 

Ex:                  User inputs WiNona

 

                  The returned string should look like:

 

                  WINONA  Winona

 

c)     Receives a sentence and returns:

a.      the words in the sentence – one word per line

b.     the number of words in the sentence

 

            Ex:                  Use inputs       Winona is a beautiful city in Minnesota

 

                                    Output should look like

 

                                    Winona

                                    is

                                    a

                                    beautiful

                                    city

                                    in

                                    Minnesota

           

                                    The sentence has 7 words.

 

Test these methods with sample values passed to the methods.

 

Then write an application that opens an input file “lines.dat” that contains many sentences, one sentence per line, and outputs for each line the sentence followed by the number of words in that sentence.