0% found this document useful (0 votes)
49 views2 pages

Class Based Program

The document outlines the design of several classes in a programming assignment, each with specific functionalities. Classes include Exchange for interchanging first and last letters of words, Change for string operations, FeDis for calculating text distance between two strings, Encrypt for replacing vowels in a word, Alpha for arranging letters of a word, and Special for checking if a number is a special number. Each class includes data members, member functions, and a main function to demonstrate their usage.

Uploaded by

Priyanshu Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Class Based Program

The document outlines the design of several classes in a programming assignment, each with specific functionalities. Classes include Exchange for interchanging first and last letters of words, Change for string operations, FeDis for calculating text distance between two strings, Encrypt for replacing vowels in a word, Alpha for arranging letters of a word, and Special for checking if a number is a special number. Each class includes data members, member functions, and a main function to demonstrate their usage.

Uploaded by

Priyanshu Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Homework :

1) 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. [10]
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: 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 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 functions accordingly to enable the task.
2) Design a class Change to perform string-related operations. The details of the class are given below:
Class name: Change
Data members / Instance variables:
str = stores the word
newstr = stores the changed word
len = stores the length of the word
Member functions:
Change() : default constructor
void inputword() : to accept a word
char caseconvert(char ch) : converts the case of the character and returns it
void display() : displays both the words
Specify the class Change giving details of the constructor and the functions void inputword(), char caseconvert(char
ch), void display().
Call the above functions using appropriate statements from the main method.

3) The text distance between two strings is calculated by counting the number of corresponding characters that
are unequal. For example, the text distance between "Sunday" and "Friday" is:
1 + 1 + 1 + 0 + 0 + 1 = 4 (i.e., when the character matches it is 0, otherwise it is 1).
[It seems the line might also say: (If two strings are of unequal length, then the comparison will be done up to
the last character of the smaller string.)]
Some of the members of the class are given below:
Class Name: FeDis
Data Members / Instance Variables:
S1, S2 : To store two strings
D : To store the distance (integer)
Member Functions / Methods:
FeDis() : Default constructor to initialize the data members
void read() : To accept values for S1 and S2 from user
void dist() : To calculate distance between S1 and S2 and store in D
void display() : To display the data members with a appropriate message.
4) A class Encrypt hass been defined to replace only the vowels in a word by the next corresponding vowel and
forms a new word i.e. A-E, E-I, I-O, O-U, U-A, example Input : COMPUTER Output : CUMPATIR
Class Name: Encrypt
Data Members / Instance Variables:
word: a string to store the word
len: integer to store the length of the word
len1: integer to store the length of the encrypted word
Methods / Member Functions:
Encrypt(): a default constructor to initialize the data members with legal initial values
void acceptword(): to accept a word in UPPERCASE
void frequency(): finds the frequency of the vowels and consonants in the word and displays them with an
appropriate message
void nextvowel(): replaces all the vowels from the word stored in word by the next corresponding vowel and
assigns it to len1 with the remaining alphabet unchanged
void disp(): displays the original word along with the encrypted word
specify the class Encrypt by giving details of each method, and to define a main function that creates an object
of this class and calls the functions accordingly.

5) Design a class Word Alpha which enables a word to be arranged in ascending order of its letters.
Class Name: Alpha
Data Members:
str: to store a word
Member Functions:
Alpha(): default constructor
void readword(): to accept a word
void arrange(): to arrange the word in alphabetical order
void disp(): displays the words
specify the class Alpha with details of each method and to define a main function that creates an object and
executes the class functions.

6) A special number is a number in which the sum of the factorial of each digit is equal to the number itself.
For example: 145.
1! + 4! + 5! = 1 + 24 + 120 = 145.
Thus, 145 is a special number.
Design a class Special to check if a given number is a special number. Some of the members of the class are
given below:
Class name: Special
Data members:
n: to store the integer number.
Member functions:
Special(): default constructor.
void read() : to accept the number.
int factorial (int n) : to return the factorial of a number.
boolean isSpecial(): check for the special number by invoking the function factorial().
Void display : To show the result with an appropriate message

You might also like