Google Answers Logo
View Question
 
Q: C++ Problem ( No Answer,   1 Comment )
Question  
Subject: C++ Problem
Category: Computers > Programming
Asked by: atishpanje-ga
List Price: $11.00
Posted: 28 Mar 2005 17:08 PST
Expires: 29 Mar 2005 13:05 PST
Question ID: 501677
i have C++ Problem : ( i need acual code for this problem):
1. A palindrome is a number or a text phrase that reads the same
backwards as forwards. For example, each of the foDowing 5 digit
integers is a palindrome: 12321, 55555, 15551, 11611. Write a function
that reads a positive five digit integer and determines whether it is
a palindrome. Use the division and modulus operators to separate the
number into its individual digits. For example the first digit is
determined by:

/I determine first digit by integer division by 10000 	firstDigit = number /10000;

and the second digit by:

/I determine second digit
/I first calculate last 4 digits by using mod operator
/I then use integer division by 1000 to obtain second digit
secondDigit = number % 10000/1000;

NOTE: stop looping when the user enters a negative value.

2. A company wants to transmit data over the telephone, but is
concerned with privacy. AD of the data are transmitted as four-digit
integers. You wiD write a function to encrypt the data with a simple
cipher. Create an input file that has 20, 4-digit integers. Your
function shall read each four-digit integer and encrypt it as foDows:
a. replace each digit by (the sum of that digit plus 7) modulus 10.
1. first = ( number /1000 + 7 ) % 10;
b. Swap the first digit with the third
c. Swap the second digit with the fourth
d. add components to obtain decrypted number
e. Print the encrypted integer.
f. Write the integer to a file "encrypted.txt"

3. Write another function that inputs the encrypted four-digit integer
(from file "encrypted.txt" and decrypts it to the original number.
Your function shall read a four-digit integer and decrypt it as
follows:
i. replace each digit by (the sum of that digit plus 3) modulus 10.
ii. swap first and third iii. swap second and fourth iv. add
components to obtain decrypted number v. Print the decrypted integer.
vi. Write the integer to a file "decrypted.txt"
Answer  
There is no answer at this time.

Comments  
Subject: Re: C++ Problem
From: vanithasaran-ga on 29 Mar 2005 10:31 PST
 
Hi, here is the code for your pallindrome porgram.
#include <iostream.h>
void main () {
   int AB, BA;           // Numbers to test if palindromes
   int Q;                // Quotient of division by 10
   do {
     cout << "Enter unsigned 16-bit integer:";
     cin >> AB;
     if (AB > 0) {
       BA = 0;
       Q = AB;
       while ( Q != 0 ) {            // Reverse AB to BA
           BA = BA * 10;             // Shift BA left 1 digit
           BA = BA + Q % 10;         // Right digit of Q = left BA
           Q = Q / 10;               // Drop right digit
       }
       if (AB==BA)                   // If Reversal == Forward
          cout <<  "Palindrome\n";     //   Then Palindrome
       else cout << "Not Palindrome\n";//   Else Not Palidrome
     }
  } while (AB != 0); 
}

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy