Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,570 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,659 people online right now. Registration is fast and FREE... Join Now!




Program Help on reversing and palindromes

 
Reply to this topicStart new topic

Program Help on reversing and palindromes

grat123
25 Nov, 2007 - 01:40 PM
Post #1

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 1


My Contributions
CODE
  

#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
using namespace std;

bool nbr(char symb);
void revstring(string & s);
void print1(string s);
void print2(string s);
void print3(string s);
void print4(string s);
void print5(string s);

int main()
{
  string s;  // original string
  cout << "Input a string: ";
  getline(cin,s);
  cout << endl << "Output: " << endl;
  print1(s);
  print2(s);
  print3(s);
  print4(s);
  print5(s);
  cout << endl;
  return 0;
}

bool nbr( char symb )
{
  if( symb >= '0' && symb <= '9' )
    return true;
  else
    return false;
}

void revstring(string & s)
{
  stack<char> nbrstk;
  int i=0;

  while( i<s.length() )
    nbrstk.push(s[i++]);
  
  i = 0;
  while(!nbrstk.empty())
  {
    s[i++] = nbrstk.top();
    nbrstk.pop();
  }
}

void print1(string s)
{
  for(int i=0; i<s.length(); i++)
    cout << s[i];
  cout << endl;
}

void print2(string s) // ***Help with this function*** print string in reverse order
{
for (int i=0; i<s.length(); i--)
   cout << s[i];
  cout << endl;
}

void print3( string s ) // Help with this function* print string with every sequence of numbers within string in reverse order
{
for (int=0; i<s.length(); i++)
revstring (string & s)
cout << s[i];
cout << endl;
}

void print4(string s) // ***Help with this function*** determine if string is palindrome (same order when reversed)
{
while (i= <s.length () )
{
symb=s[i]
if (!nbr (symb) )
{
cout<< symb;
i++;
}
else
while (nbr (symb) )
{
nbrstk.push (symbl)
symb= s (i++);                          


cout<< "Not a Palindrome";
}

void print5( string s ) // ***Help with this function*** determine the length of the string at beginning that is palindrome
{
  cout<< "The first"<<  << "characters form a palindrome."
}  

User is offlineProfile CardPM
+Quote Post

Bench
RE: Program Help On Reversing And Palindromes
25 Nov, 2007 - 02:23 PM
Post #2

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 684



Thanked: 24 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
Instead of posting a block of code with words to the effect of "fill in the blanks", have a go at attempting the solutions yourself, and post back if you get stuck. We're not in the business here of finishing homework for people that haven't made any effort themselves.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:19PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month