Hi Guys Im looking for someone who can translate this c++ code to pseudocode .

#include <algorithm>
#include <cctype>
#include <functional>
#include <string>

bool palindrome( unsigned long n )
  {
  unsigned long x = n;
  unsigned long u = 0;
  while (x)
    {
    u *= 10;
    u += x % 10;
    x /= 10;
    }
  return (n == u);
  }

bool palindrome( std::string s )
  {
  s.erase(
    std::remove_if(
      s.begin(),
      s.end(),
      std::not1( std::ptr_fun <int, int> ( std::isalnum ) )
      ),
    s.end()
    );
  std::transform( s.begin(), s.end(), s.begin(), std::ptr_fun <int, int> ( std::tolower ) );
  std::string z = s;
  std::reverse( z.begin(), z.end() );
  return (s == z);
  }

#include <iostream>
#include <limits>
using namespace std;

int main()
  {
  string        s;
  unsigned long n;
  cout << "Palindrome tester\n";
  cout << "Enter nothing to quit.\n";
  while (true)
    {
    cout << "Enter a string> ";
    getline( cin, s );
    if (s.empty()) break;

    cout << "Enter a number> ";
    cin >> n;
    if (!cin) cin.clear();
    cin.ignore( numeric_limits <streamsize> ::max(), '\n' );

    cout << "The string is " << (palindrome( s ) ? "" : "not ") << "a palindrome.\n";
    cout << "The number is " << (palindrome( n ) ? "" : "not ") << "a palindrome.\n\n";
    }
  cout << "Good bye.\n";
  return 0;
  }

Thanks..

Nick Evan commented: fail -3
jackmaverick1 commented: STEALING +0

:-O Seriously?

Pseudocode is simply a semi-natural-language summary of the actions performed, or a simplified description of an algorithm. If you understand the C++, you should easily be able to write a summary of the program's actions.

Just read through each line of the code and state what it does...

example:

while (i<10) {
  cout << i << " ";
  ++i;
}
cout << endl;

the algorithm:

while the value of "i" is less than 10,
  display the value of "i" followed by a "space"
  increment "i"
once loop is complete, output a newline

the pseudocode:

while "i" less than 10,
  output "i"
  output a "space"
  increment "i"
output a newline

hw did u write the code without knwin the pseudocode, jus samar the code

hw did u write the code without knwin the pseudocode, jus samar the code

I won't down vote because you're new, but please don't use SMS/TXT in your posts. This is a professional forum and the rules require that you use proper English to the best of your ability...

Keep it Clear

  • Do post in full-sentence English
  • Do wrap your programming code blocks within [code] ... [/code] tags
  • Do use clear and relevant titles for new threads
  • Do not write in all uppercase or use "leet", "txt" or "chatroom" speak

Let me make an educated guess here.

Your teacher wanted you to make the palindrome problem and you're required to hand in the pseudocode in addition to your solution. Now you've found this code somewhere on the web and decided to cheat your way through this class.

Am I right?

How do I know this you ask? Because your code is written by someone who knows his/her C++ very well; a skill that you clearly lack.

[edit]

There we go, it was stolen from our own Duoas. One of the usual suspects when it comes to advanced STL use.

commented: How do I know that you are cper ? +0

:D Nice bust! I had my suspicions...

Can somebody help me get the pseudocode of this one.

#include <stdio.h>

int main()

{

    long int binaryvalue, hexadecimalvalue = 0, j = 1, remainder;


    printf("Enter the binary number: ");

    scanf("%ld", &binaryvalue);

    while (binaryvalue != 0)

    {

        remainder = binaryvalue % 10;

        hexadecimalvalue = hexadecimalvalue + remainder * j;

        j = j * 2;

        binaryvalue = binaryvalue / 10;

    }

    printf("Equivalent hexadecimal value: %lX", hexadecimalvalue);

    return 0;

}
commented: do your own homework and don't hijack other peoples' 10 year old posts, kiddo -4
int tc;
double a, b, c, res, l, w, x;
scanf(" %d", &tc);
while(tc--) {
commented: This, if turned in here would get a failing grade. Fine example of undocumented what does this do code. -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.