[Question 9] ISC 2013 (Theory) Paper Solved


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 marw yad

Some of the data members and member functions are given below:

Class name : Exchange

Data members/instance variables:
sent : stores the sentence
rev : to store the new sentence
size : stores the length of the sentence

Member functions:
Exchange() : default constructor
void readsentence() : to accept the sentence
void exfirstlast() : extract each word and interchange the first and the last alphabet of the word and form a new sentence ‘rev’ using the changed words
void display() : 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 function accordingly to enable the task.

Programming Code:


Enter a sentence : Today was a warm day.
The Original Sentence is : Today was a warm day.
The Changed Sentence is : yodaT saw a marw yad

Enter a sentence : This is a cat
The Original Sentence is : This is a cat.
The Changed Sentence is : shiT si a tac

A teacher whose aim is to make Java a fun to learn experience for the school students by striving to build clear fundamentals of every concepts and helping students to develop their ability to reason and logically analyze any given programs.

Your Turn To Talk

Your email address will not be published.