Given a decimal number as input, you are asked to write a program in C++ to convert the given decimal number into equivalent Hexadecimal number. Convert the number with base value 10 (Decimal) to base value 16 (Hexadecimal). The base value of a number system determines the number of digits used to represent a numeric value. For example, the binary number system uses two digits 0 and 1, Hexadecimal number system uses 16 digits from 0-9, A, B, C, D, E, and F and decimal number system uses 10 digits 0-9 to represent any numeric value. using this code SAMPLE Sample Input:                         Enter a decimal value (Base-ten): 245 Sample Output:                         Decimal value = 245                         Hexadecimal value = F5                         Programmer name:………….. Algorithm: If the given decimal number is 245. Step 1: Remainder when 245 is divided by 16 is 5. Push the value 5 in the stack. Step 2: Divide 245 by 15. New number is 245/16 = 15. Step 3: Remainder when 15 is divided by 16 is 15. Push the value 15 in the stack. Step 4: Divide 15 by 16. New number is 15/16 = 0. Step 5: Since number becomes = 0. Stop repeating the steps and Pop the items from the stack and display until the stack is EMPTY. To display the Hexadecimal number While (Stack Not Empty)             Pop the item from stack and display Continue Sample Input 2:                         Enter a decimal value (Base-ten): 1243 Sample Output 2:                         Decimal value = 1243                         Hexadecimal value = 4DB                         Programmer name:…………..   Sample Input 3:                         Enter a decimal value (Base-ten): 1000 Sample Output 3:                         Decimal value = 1000                         Hexadecimal value = 3E8   /*---------------Stack.h-----------------------------------   This header file defines a stack data type. Basic operations:      constructor:  Constructs an empty stack    empty:        Check if the stack is empty    push:         Modifies a stack by adding a value at the top    pop:          Remove an element from top of the stack */                    #ifndef STACK_H #define STACK_H using namespace std;   const int STACK_CAPACITY =10; typedef int StackElement;   class Stack { private:        /******* Data Members  **************/          StackElement myArray[ STACK_CAPACITY];        int myTop;        public:        /******* Function Members **************/          Stack();                   //Constructor - An empty stack has been constructed.    bool empty() const;                     //Check if the stack is empty.        void push(const StackElement & value);   //Adds an element to a stack.   StackElement pop();                      //Remove an element from top of the stack };   #endif ------------------------------------------------------------------------------------     /* This file implements Stack member functions. stack.cpp */ #include "Stack.h" #include using namespace std;   //---------Definition of Stack constructor--------------- Stack::Stack() {        //Default Constructor        myTop = -1; }   //---------Definition of empty()------------------------- bool Stack::empty() const {        return (myTop == -1); }   //---------Definition of push()-------------------------- void Stack::push(const StackElement & value) {        if (myTop < STACK_CAPACITY -1)        {              ++myTop;              myArray[myTop] = value;        }        else        { cerr << "*** Stack full -- can't add new value Must increase value of STACK_CAPACITY in Stack.h ***\n";              exit(1);        } }   //---------Definition of pop()-------------------------- StackElement Stack::pop() {          StackElement value;          if (!empty())        {              value = myArray[myTop];              myTop--;        }        else        {              cerr << "*** Stack is empty --can't remove a value ***\n";              exit(1);        }        return value; }

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

Given a decimal number as input, you are asked to write a program in C++ to convert the given decimal number into equivalent Hexadecimal number. Convert the number with base value 10 (Decimal) to base value 16 (Hexadecimal).

The base value of a number system determines the number of digits used to represent a numeric value. For example, the binary number system uses two digits 0 and 1, Hexadecimal number system uses 16 digits from 0-9, A, B, C, D, E, and F and decimal number system uses 10 digits 0-9 to represent any numeric value.

using this code

SAMPLE

Sample Input:

                        Enter a decimal value (Base-ten): 245

Sample Output:

                        Decimal value = 245

                        Hexadecimal value = F5

                        Programmer name:…………..

Algorithm:
If the given decimal number is 245.
Step 1: Remainder when 245 is divided by 16 is 5. Push the value 5 in the stack.
Step 2: Divide 245 by 15. New number is 245/16 = 15.
Step 3: Remainder when 15 is divided by 16 is 15. Push the value 15 in the stack.
Step 4: Divide 15 by 16. New number is 15/16 = 0.
Step 5: Since number becomes = 0. Stop repeating the steps and Pop the items from the stack and display until the stack is EMPTY.

To display the Hexadecimal number
While (Stack Not Empty)

            Pop the item from stack and display

Continue

Sample Input 2:

                        Enter a decimal value (Base-ten): 1243

Sample Output 2:

                        Decimal value = 1243

                        Hexadecimal value = 4DB

                        Programmer name:…………..

 

Sample Input 3:

                        Enter a decimal value (Base-ten): 1000

Sample Output 3:

                        Decimal value = 1000

                        Hexadecimal value = 3E8

 

/*---------------Stack.h-----------------------------------

 

This header file defines a stack data type.

Basic operations:

 

   constructor:  Constructs an empty stack

   empty:        Check if the stack is empty

   push:         Modifies a stack by adding a value at the top

   pop:          Remove an element from top of the stack

*/                 

 

#ifndef STACK_H

#define STACK_H

using namespace std;

 

const int STACK_CAPACITY =10;

typedef int StackElement;

 

class Stack

{

private:

       /******* Data Members  **************/

 

       StackElement myArray[ STACK_CAPACITY];

       int myTop;

      

public:

       /******* Function Members **************/

 

       Stack();                   //Constructor - An empty stack has been constructed.

   bool empty() const;                     //Check if the stack is empty.

       void push(const StackElement & value);   //Adds an element to a stack.

  StackElement pop();                      //Remove an element from top of the stack

};

 

#endif

------------------------------------------------------------------------------------

 

 

/* This file implements Stack member functions. stack.cpp */

#include "Stack.h"

#include <iostream>

using namespace std;

 

//---------Definition of Stack constructor---------------

Stack::Stack()

{

       //Default Constructor

       myTop = -1;

}

 

//---------Definition of empty()-------------------------

bool Stack::empty() const

{

       return (myTop == -1);

}

 

//---------Definition of push()--------------------------

void Stack::push(const StackElement & value)

{

       if (myTop < STACK_CAPACITY -1)

       {

             ++myTop;

             myArray[myTop] = value;

       }

       else

       {

cerr << "*** Stack full -- can't add new value Must increase value of STACK_CAPACITY in Stack.h ***\n";

             exit(1);

       }

}

 

//---------Definition of pop()--------------------------

StackElement Stack::pop()

{  

       StackElement value;

 

       if (!empty())

       {

             value = myArray[myTop];

             myTop--;

       }

       else

       {

             cerr << "*** Stack is empty --can't remove a value ***\n";

             exit(1);

       }

       return value;

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Algebraic Expressions
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
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