a. Write a function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. b. Write a function, called GCD that receives two parameters n, d, and prints their greatest common divisor a. Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options 1. To use the IsPalindrome function you have to enter 1. 2. To use the GCD function you have to enter 2. 3. To Exit the program you have to enter 3. [use exit(0)] Once the user select one of the above choices you have to read the value entered by the user and then to call the respective function.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please code this for me in c++ using void, functions, loops, (basic c++ not complicated or highlevel please). I tried to code it myself but there are many mistakes I dont know how to fix so please write a similar one for me but it works. 

The question is only 1 but it has 2 parts (2 different functions that should be in one code)

 

 

 

MY CODE: 

#include <iostream>
using namespace std;

int IsPalindrome(int p);
void GCD();

int main ()
{
    int choice;
    cout << "Please enter a choice: "<<endl; 
    cout << "Enter one for IsPalindrome "<<endl;
    cout << "Enter 2 for GCD "<<endl;
    cout << "Enter 3 to exit the program "<<endl; 
    cout << "Choice: "<<endl; 
    cin >> choice;
    
    
    if (choice == 1)
    {
        int p;
        cout << "Please enter a 3 digit number: "<<endl; 
        cin >> p;

if(p%10==p/100)     
 {
  cout<<p<<" is a palindrome " <<endl;  }

 else
 {
  cout<<p<< " is not a palindrome " <<endl;  }
}

        
    }
    
    else if (choice == 2)
    GCD();
    
    else if (choice == 3)
    exit (0);
    
    return 0;
}

    

 

void GCD()
{
    int GCD(int n, int d)
{
   if (n == 0)
      return d;
  
   if (d == 0)
      return n;
   if (n == d)
      return n;
   if (n > d)
     return GCD(n-d, d);
     return GCD(n, d-n);
}


int n,d;
cout<<"Enter the value of n= "<<endl; 
cin>>n;
cout<<"Enter the value of d= "<<endl; 
cin>>d;
cout<<"GCD of "<<n<<" and "<<d<<" is "<<GCD(n, d);

}

return 0; 
    
}

a. Write a function called IsPalindrome that receives a 3-digit number and returns whether it is
palindrome or not.
b. Write a function, called GCD that receives two parameters n, d, and prints their greatest common
divisor
a. Now after you created the two functions, you have to write a main function that can call the
above functions according to user choice. Write a menu that allows the user to select from the
following options
1. To use the IsPalindrome function you have to enter 1.
2. To use the GCD function you have to enter 2.
3. To Exit the program you have to enter 3. [use exit(0)]
Once the user select one of the above choices you have to read the value entered by the user and
then to call the respective function.
Transcribed Image Text:a. Write a function called IsPalindrome that receives a 3-digit number and returns whether it is palindrome or not. b. Write a function, called GCD that receives two parameters n, d, and prints their greatest common divisor a. Now after you created the two functions, you have to write a main function that can call the above functions according to user choice. Write a menu that allows the user to select from the following options 1. To use the IsPalindrome function you have to enter 1. 2. To use the GCD function you have to enter 2. 3. To Exit the program you have to enter 3. [use exit(0)] Once the user select one of the above choices you have to read the value entered by the user and then to call the respective function.
Expert Solution
steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education