GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Jun-2008, 09:07
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Awaiting Email Confirmation
 
Join Date: Mar 2008
Posts: 50
khushal_kkk is an unknown quantity at this point

Need help in reversing the alphabets


how to reverse alpahbets by simple using loops need code of it i mean if i enter khushal the output will be lahsuhk.


please help me by using the code insted of theoratical explanation i can reverse a number but alphabets can't be reversed and the code for reversing numbers is given in my code try using this approach to explain my question

CPP / C++ / C Code:
<iostream>
int main()
{
long a,b,c,d,e,no;
	cout<<"\n\n\nEnter a number: ";
	cin>>no;

	a=(no%10);
	b=((no%100)-(a))/10;
	c=((no%1000)-(b*10+a))/100;
	d=((no%10000)-(c*100+b*10+a))/1000;
	e=((no%100000)-(d*1000+c*100+b*10+a))/10000;

	cout<<a<<b<<c<<d<<e;
           return 0;

	}
  #2  
Old 05-Jun-2008, 10:09
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 696
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: need help in reversing the alphabets...?


I don't really understand what you're doing in your example but here is how I would do it:

1) Read the input into a string variable
2) Send that string into a function like: string ReverseString( const string& s )
3) Output the new string


As for the function, here is how I would create it:

CPP / C++ / C Code:
string ReverseString( const string& s )
{ string result;
  int i,length;

  length = s.length();

  for(i=s.length-1;i>=0;++i)
  { 
    // To Do: Append s[i] on to the end of result
  }
  
  return result;
}
  #3  
Old 05-Jun-2008, 10:20
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Awaiting Email Confirmation
 
Join Date: Mar 2008
Posts: 50
khushal_kkk is an unknown quantity at this point

Re: need help in reversing the alphabets...?


i need simple reversing not to use the const etc simple as i reversed it in an example of reversing the numbers.i want to reverse a letter such as if i enter "khushal" the output will be "lahsuhk"
  #4  
Old 05-Jun-2008, 10:28
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 696
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: need help in reversing the alphabets...?


Quote:
Originally Posted by khushal_kkk
i need simple reversing not to use the const etc simple as i reversed it in an example of reversing the numbers.i want to reverse a letter such as if i enter "khushal" the output will be "lahsuhk"
Look at the example above. It is SIMPLE.
  #5  
Old 05-Jun-2008, 10:40
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Awaiting Email Confirmation
 
Join Date: Mar 2008
Posts: 50
khushal_kkk is an unknown quantity at this point

Re: need help in reversing the alphabets...?


sorry for disturbing u again and again i just need the complete code that where the function is used initialization etc....please send me the complete program i really dont understand u.Will be thankful to YOu
  #6  
Old 05-Jun-2008, 12:24
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 696
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: need help in reversing the alphabets...?


Quote:
Originally Posted by khushal_kkk
sorry for disturbing u again and again i just need the complete code that where the function is used initialization etc....please send me the complete program i really dont understand u.Will be thankful to YOu
Please send me $125.00 US and I can get you all of the source code for this example.
  #7  
Old 05-Jun-2008, 12:29
khushal_kkk's Avatar
khushal_kkk khushal_kkk is offline
Awaiting Email Confirmation
 
Join Date: Mar 2008
Posts: 50
khushal_kkk is an unknown quantity at this point

Re: need help in reversing the alphabets...?


sorry cant do this cauz im a bachloer student noe and dont have enough funds to pay even a dollar...sorry buddy if u can help me weelll in good other wise thank you for ur replies byeee
  #8  
Old 06-Jun-2008, 00:34
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: need help in reversing the alphabets...?


it is obvious you didn't read the guidelines which explains how to ask a question we do not do homework for you you have to do the home work and we will help you correct it but we won't write it for you you don't learn if we do it for you and another thing work harder at making your posts readable in english there are things called sentences and they end in a period so we know when the end of of a sentence is reached.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #9  
Old 03-Jul-2008, 14:56
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 221
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: need help in reversing the alphabets...?


Quote:
Originally Posted by fakepoo
I don't really understand what you're doing in your example but here is how I would do it:

1) Read the input into a string variable
2) Send that string into a function like: string ReverseString( const string& s )
3) Output the new string


As for the function, here is how I would create it:

CPP / C++ / C Code:
string ReverseString( const string& s )
{ string result;
  int i,length;

  length = s.length();

  for(i=s.length-1;i>=0;++i)
  { 
    // To Do: Append s[i] on to the end of result
  }
  
  return result;
}

...close. I think that you'd want to post-decrement i rather than pre-increment it.

CPP / C++ / C Code:
#include <iostream>
#include <string>

std::string ReverseString( const std::string& s )
{
    std::string result;
    for( int i = s.length() -1; i >= 0; i-- )
    {
        result.push_back( s[i] );
    }
    return result;
}

int main()
{
    std::cout << "Enter a string: ";
    std::string s;
    std::getline( std::cin, s );
    std::cout << "You entered: " << s << std::endl;
    std::cout << "Reversed is: " << ReverseString( s ) << std::endl;

    return 0;
}



Output:

Code:
Enter a string: The quick brown fox jumped over the lazy dogs. You entered: The quick brown fox jumped over the lazy dogs. Reversed is: .sgod yzal eht revo depmuj xof nworb kciuq ehT
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help reversing an entered String with recursion skis0601 C++ Forum 5 03-Dec-2007 19:41
Printing alphabets and numbers bold parthu Java Forum 1 09-Nov-2007 18:45
Making non-English alphabets work Kimmo C++ Forum 0 17-May-2007 06:06
Reversing Output, Pascals triangle worms707 C++ Forum 1 07-Feb-2006 18:55
Need help with reversing strings Infuriate C Programming Language 13 01-Dec-2005 19:27

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:06.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.