Knowee
Questions
Features
Study Tools

Write a C++ program to find Reverse of a Number using class.inputEnter a number: 12345output54321

Question

Write a C++ program to find Reverse of a Number using class.inputEnter a number: 12345output54321

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C++ program that uses a class to reverse a number:

#include<iostream>
using namespace std;

class ReverseNumber {
    int num, rev;
public:
    ReverseNumber() : num(0), rev(0) {}

    void input() {
        cout << "Enter a number: ";
        cin >> num;
    }

    void reverse() {
        while(num != 0) {
            int digit = num % 10;
            rev = rev * 10 + digit;
            num /= 10;
        }
    }

    void display() {
        cout << "Reversed Number: " << rev << endl;
    }
};

int main() {
    ReverseNumber rn;
    rn.input();
    rn.reverse();
    rn.display();

    return 0;
}

In this program, we have a class ReverseNumber with two data members num and rev. The input() member function is used to take the number as input from the user. The reverse() member function is used to reverse the number. The display() member function is used to display the reversed number. The main() function creates an object of the ReverseNumber class and calls these member functions.

This problem has been solved

Similar Questions

algorithm for a program to reverse a number in c programming

Write a C program to find reverse of a string using pointers

Select the missing code lines from the dropdown provided.The C code given below should print the reverse of a number entered by the user.But, line numbers 9 and 10 are missing.1. #include <stdio.h>2. int main()3. {4.   int num, reverse=0, rem;5.   printf("Enter an integer:");6.   scanf("%d", &num);7.   while(num>0)8.   {9.        ---------------Missing code -------------------10.      ---------------Missing code -------------------11.      num/=10;12.   }13.   printf("Reverse is = %d",reverse);14.   return 0;15. }

Write a program in C to print a string in reverse using a character pointer.Also print the uppercase of the first letter of the reversed word.

Reverse last k digits of the given numberInput Format:Accept two integer  as inputOutput Format:print the reversed k digits

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.