Page 387 - Computer science 868 Class 12
P. 387

10.  We can also use the “+” operator to ………………… two strings.
                 C.  Answer the following questions:
                    1.  Write a class palindrome to input a word and print whether the word is a palindrome or not.
                        Class name                      :    palindrome
                        Data Members
                        String wd                       :   String to be checked
                        String revwd                    :    String to keep reverse word
                        Member Methods
                        void input()                    :    Enters the word to be checked
                        void reverse()                  :   Reverses wd and keeps in revwd
                        void display()                  :   Invokes the method reverse() and checks whether the word is a palindrome or
                                                            not
                    2.  Write a program in Java to accept two strings. Display the new string by taking each character of the first string from left to right
                       and of the second string from right to left. The letters should be taken alternatively from each string. Assume that the length of
                       both the strings are same.
                        Sample Input:
                        String 1: HISTORY
                        String 2: SCIENCE

                        Sample Output:
                        HEICSNTEOIRCYS
                    3.  Design a class Exchange to accept a sentence and interchange the first alphabet with the last alphabet for each word in the
                       sentence, with single-letter word remaining unchanged. The words in the input sentence are separated by a single blank space
                       and terminated by a full stop.
                        Example:
                        Input: It is a warm day.
                        Output: tI si a mraw yad
                        Some of the data members and member functions are given below.
                        Class name                      :    Exchange
                        Data Members/Instance variables
                        sent                            :    to store the sentence
                        rev                             :    to store the new sentence
                        size                            :    to store the length of the sentence
                        Member Functions
                        Exchange()                      :    default constructor
                        void readsentence()             :    to accept the sentence
                        void exfirstlast()              :   to extract each word and interchange the first and last alphabet of the word and
                                                            form a new sentence rev using the changed words
                        void display()                  :    to display the original sentence along with the new changed sentence
                        Specify the class Exchange giving details of the constructor (), void readsentence (), void exfirstlast () and void display (). Define
                       the main () function to create an object and call the functions accordingly to enable the task.   [ISC 2013]
                    4.  Input a word in uppercase and check for the position of the first occurring vowel and perform the following operations.
                       (i)  Words that begin with a vowel are concatenated with “Y”.
                          For example, EUROPE becomes EUROPEY.
                       (ii)    Words that contain a vowel in-between should have the first part from the position of the vowel till the end, followed by the
                          part of the string from beginning till the position of the vowel and is concatenated by “C”.
                          For example, PROJECT becomes OJECTPRC.
                        (iii)  Words which do not contain a vowel are concatenated with “N”.
                          For example, SKY becomes SKYN.




                                                                                                                       385
                                                                                                              Strings  385
   382   383   384   385   386   387   388   389   390   391   392