Write a program hex2dec.cpp that asks the user to enter a positive hexadecimal number (i.e., base 16: numbers with digits 0, 1...9, A, B ... F). Read the input as a C++ string object with a maximum length of 10. The program should convert the hexadecimal number to decimal (base 10). For example, if the user enters 31A9, the program should display decimal number 12713. The program will continue asking the user input until the user enters a zero (i.e., 0) number. Note & Hint: The program should validate each digit of the user input (i.e., 0 - 9, A- F). The program allows the user to enter lower case a to f (to make the algorithm simpler, convert all to upper case, use range base for loop by reference). You may use function toupper () from the library. Use unsigned long int type for the decimal number to cover a larger number range. • Conversion starts from the last digit of the hexadecimal. Use the following code to conver a digit A to F to number: char aDigit = 'C'; %3D int aNum; aNum = aDigit - 'A' + 10; // now aNum 12;
Write a program hex2dec.cpp that asks the user to enter a positive hexadecimal number (i.e., base 16: numbers with digits 0, 1...9, A, B ... F). Read the input as a C++ string object with a maximum length of 10. The program should convert the hexadecimal number to decimal (base 10). For example, if the user enters 31A9, the program should display decimal number 12713. The program will continue asking the user input until the user enters a zero (i.e., 0) number. Note & Hint: The program should validate each digit of the user input (i.e., 0 - 9, A- F). The program allows the user to enter lower case a to f (to make the algorithm simpler, convert all to upper case, use range base for loop by reference). You may use function toupper () from the library. Use unsigned long int type for the decimal number to cover a larger number range. • Conversion starts from the last digit of the hexadecimal. Use the following code to conver a digit A to F to number: char aDigit = 'C'; %3D int aNum; aNum = aDigit - 'A' + 10; // now aNum 12;
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
I’m not sure what I should do for this C++ assignment

Transcribed Image Text:Write a program hex2dec.cpp that asks the user to enter a positive hexadecimal number (i.e.,
base 16: numbers with digits 0, 1... 9, A, B... F). Read the input as a C++ string object with a
maximum length of 10. The program should convert the hexadecimal number to decimal (base
10). For example, if the user enters 31A9, the program should display decimal number 12713.
The program will continue asking the user input until the user enters a zero (i.e., 0) number.
Note & Hint:
The program should validate each digit of the user input (i.e., 0 9, A - F).
The program allows the user to enter lower case a to f (to make the algorithm simpler,
convert all to upper case, use range base for loop by reference).
You may use function toupper () from the <cctype> library.
Use unsigned long int type for the decimal number to cover a larger number
range.
Conversion starts from the last digit of the hexadecimal.
Use the following code to conver a digit A to F to number:
char aDigit = 'C';
int aNum;
aNum = aDigit - 'A' + 10;
// now aNum = 12;
Sample Output
Please enter a hexadecimal number to convert: 10
The decimal value of the hexadecimal 1 is = 16
Please enter a hexadecimal number to convert: A
The decimal value of the hexadecimal A is = 10
Please enter a hexadecimal number to convert: f
The decimal value of the hexadecimal F is = 15
Please enter a hexadecimal number to convert: 1374AC
The decimal value of the hexadecimal 1374AC is = 1275052
Please enter a hexadecimal number to convert: FFFF
The decimal value of the hexadecimal FFFF is = 65535
Please enter a hexadecimal number to convert: 123Gz
Invalid input: non digit character detected!
Please enter a hexadecimal number to convert:
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY