Problem
Take a string input from user and reverse it using C++ language.Code
// P[1].cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include<conio.h>
#include<iostream>
#include<string.h>
using namespace std;
class rvrstr
{
private:
char str1[80];
char str2[80];
int i,j,n;
char ch;
public:
rvrstr(): i(0),j(0),n(0)
{ }
void setstr()
{
cout<<"Enter string: ";
cin.get(str1,80);
}
void reversit()
{
n = strlen(str1);
cout<<"\n\nReversed String: ";
for(i=n;i>=0;i--)
{
str2[j] = str1[i];
cout<<str2[j];
j++;
}
}
};
int main()
{
rvrstr r1;
r1.setstr();
r1.reversit();
cout<<"\n\nPress any key to close.";
getch();
return 0;
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.