Program in C++ to create function in String class to find reverse of given string
#include<iostream> #include<string.h> #include<conio.h> using namespace std; class String { char *str; int length; public: String() { length=100; str=new char[length]; strcpy(str,"Programming.om"); } void Show() { cout<<" "<<str; } void Input() { cout<<"Enter a string:-"; cin.getline(str,length); } void Strrev(String &str1) { int i; char temp; length=strlen(str1.str); str=new char[length+1]; strcpy(str,str1.str); for(i=0;i<=length/2;i++) { temp=str[i]; str[i]=str[length-1-i]; str[length-1-i]=temp; } } }; int main() { String s1,s2; s1.Input(); s2.Strrev(s1); s2.Show(); getch(); }
Output:-
0 Comments