0% found this document useful (0 votes)
43 views

S M U F O: Tring Anipulation Sing Unction Verloading

This document describes a C++ program that implements string manipulation functions using function overloading. It includes functions for concatenating strings, comparing strings, finding the length of a string, and searching for a string in an array. The main function uses a menu to test the different string functions and take user input for operations like entering multiple strings, selecting sorting order, and searching.

Uploaded by

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

S M U F O: Tring Anipulation Sing Unction Verloading

This document describes a C++ program that implements string manipulation functions using function overloading. It includes functions for concatenating strings, comparing strings, finding the length of a string, and searching for a string in an array. The main function uses a menu to test the different string functions and take user input for operations like entering multiple strings, selecting sorting order, and searching.

Uploaded by

aaanathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

STRING MANIPULATION USING FUNCTION OVERLOADING

Ex: No: 4
Date:
Aim:
To implement function overloading.
Algorithm:
Step 1. Start.
Step 2. Create a class string which has the char s[100] and use the read to get the
data.
Step 3. Function concatenation is done to concatenate two strings
Step 4. Here the for loop is used to concatenate two strings.
Step 5. The string compare function is used to compare the strings.
Step 6. The length of the string is found b using the for loop in length function.
Step 7. The program must be done using the menu driven method.
Step 8. !nd.
Sor!e Co"e:
"include#iostream$
"include#string$
using namespace std%
class strings
&
char s[100]%
public'
void read()
&
cin$$s%
*
int string()
&
int i+ len,0%
for(i,0%s[i]-,./0.%i00)
len00%
return(len)%
*
void string(strings a[10]+ int n)
&
int i%
strings r%
strcp(r.s+1 1)%
for(i,0%i#n%i00)
&
strcat(r.s+a[i].s)%
strcat(r.s+1 1)%
*
cout##1/nConcatinated String' 1##r.s%
*
void string(strings b)
&
strcp(s+ b.s)%
cout##1/nCopied String' 1##s%
*
void string(strings a[10]+ int n+ int order)
&
int i+ 2%
strings temp%
for(i,0%i#n31%i00)
&
for(2,i01%2#n%200)
&
if(strcmp(a[i].s+a[2].s)$0)
&
strcp(temp.s+ a[i].s)%
strcp(a[i].s+ a[2].s)%
strcp(a[2].s+ temp.s)%
*
*
*
cout##1/nThe Sorted String' /n1%
if(order,,1)
&
for(i,0%i#n%i00)
cout##a[i].s##1/n1%
*
else
&
for(i,n31%i$,0%i33)
cout##a[i].s##1/n1%
*
*
void string(strings a[10]+ strings c+ int n)
&
int i+ f,0%
for(i,0%i#n%i00)
&
if(strcmp(a[i].s+c.s),,0)
&
f,1%
brea4%
*
*
if(f,,1)
cout##1/n1##c.s##1 is present in the list1%
else
cout##1/n1##c.s##1 is not present in the list1%
*
*%
int main()
&
int ch+ n+ order+ len+ i%
strings c+ d+ f[10]%
do
&
cout##1/n 5!671%
cout##1/n 33331%
cout##1/n 1. 8ength1%
cout##1/n 9. Concatination1%
cout##1/n :. Cop1%
cout##1/n ;. Sort1%
cout##1/n <. Search1%
cout##1/n!nter our choice' 1%
cin$$ch%
if(ch,,9 == ch,,; == ch,,<)
&
cout##1/n!nter the no' of Strings' 1%
cin$$n%
for(i,0%i#n%i00)
&
cout##1String 1##i01##1' 1%
f[i].read()%
*
*
switch(ch)
&
case 1' cout##1/n!nter the String' 1%
c.read()%
len,c.string()%
cout##18ength' 1##len##1/n1%
brea4%
case 9' c.string(f+n)%
brea4%
case :' cout##1!nter the First String' /n1%
c.read()%
cout##1!nter the Second String' /n1%
d.read()%
c.string(d)%
brea4%
case ;' cout##1/n!nter the Sorting >rder' 1%
cout##1/n1. ?scending >rder /n9. @escending >rder1%
cout##1/n!nter Choice' 1%
cin$$order%
c.string(f+ n+ order)%
brea4%
case <' cout##1/n!nter String to be Searched' 1%
c.read()%
c.string(f+ c+ n)%
brea4%
defaut' brea4%
*
* while(ch#,<)%
*
Ot#t:
5!67
33333333
1. 8ength
9. Concatenation
:. Cop
;. Sort
<. Search

!nter our choice' 1
!nter the string' vince
8ength ' <
!nter our choice' 9
!nter the no' of strings' 9
String 1' Hello
String 9' Aorld
Concatenated string' HelloAorld
!nter our choice' :
!nter the First String' First
!nter the Second String' Second
Copied String' Second
!nter our choice' ;
!nter the no' of strings' ;
String 1' Sharon
String 9' ?2a
String :' Bi2a
String ;' Ci2o
!nter the sorting order'
1. ?scending >rder
9. @escending >rder
!nter choice' 1
The sorted string'
?2a
Ci2o
Sharon
Bi2a
!nter our choice' <
!nter the no' of strings' <
String 1' Sha2i
String 9' Tinchu
String :' Binu
String ;' 5aster
String <' Cecil
!nter the string to be searched' Tinchu
Tinchu is present in the list.

Re$lt:
Thus the program is compiled and eDecuted successfull and the output is
verified.

You might also like