Question: Having trouble with this question> Please use template provided. Thanks! // This program is to accept two hexadecimal numbers, to be stored as // arrays
Having trouble with this question> Please use template provided. Thanks!
// This program is to accept two hexadecimal numbers, to be stored as // arrays of up to 10 characters. The program should add these numbers. // // If the sum can be contained in 10 digits, output the sum // otherwise output an indication of overflow error. // // Provide a loop to repeat the action until user wants to end program. // // Note on overflow detection. Overflow occurs when the carry bits into // and out of the highest digit are both set. This condition is is // equivalent to the text's "when the result will not fit in 10 hexadecimal // digits", and is easy to test. // // nice enhancement would be to allow the hexadecimal numbers is entered in either case. //
// Tests the program with single digit, two // digit and with all numbers of data all the way to 10 hex digits, in all // combinations in each of the two input positions, and test with short // data before and after many digit data and conversely. //
#include
void input(char num[]) { using std::cout; using std::cin; using std::endl;
cout << "Enter a hexadecimal number of 10 or fewer hex digits " << "Hex digits are 0-9A-F Code requires uppercase A through F " << "Press lower case q to stop entry of the hex digits ";
// Complete the function }
// internal to the program, hex numbers are stored // with least significant digit first we output // most significant to least significant void output(char num[]) { // Complete the function }
void hexSum(char num1[], char num2[], char sum[]) { // Complete the function }
int main() { using std::cout; using std::cin; using std::endl;
char ans = 'y'; while (ans == 'y') { // put definitions and initialization here so each time through // variables get initialized. char num1[10] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'}; char num2[10] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'}; char sum[10] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'}; char temp[10] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0'};
input(num1); cout << endl; output(num1); cout << endl; input(num2); cout << endl; output(num2); cout << endl << endl;
hexSum(num1, num2, sum);
cout << " "; // for alignment output(num1); cout << " "; cout << "+"; output(num2); cout << " ------------ "; // space at end for alignment output(sum);
cout << endl; cout << "y continues "; cin >> ans; }
return 0; }
/*
Some samples for testing Enter a hexadecimal number of 10 or fewer hex digits Hex digits are 0-9A-F Code requires uppercase A through F Press lower case q to stop entry of the hex digits
FEDCBA9876 Enter a hexadecimal number of 10 or fewer hex digits Hex digits are 0-9A-F Code requires uppercase A through F Press lower case q to stop entry of the hex digits
123456789A
*********Overflow Error ***********
FEDCBA9876 +123456789A ------------ 1111111110 y continues
Enter a hexadecimal number of 10 or fewer hex digits Hex digits are 0-9A-F Code requires uppercase A through F Press lower case q to stop entry of the hex digits
CEDCBA9876 Enter a hexadecimal number of 10 or fewer hex digits Hex digits are 0-9A-F Code requires uppercase A through F Press lower case q to stop entry of the hex digits
123456789A
CEDCBA9876 +123456789A ------------ E111111110 y continues
Enter a hexadecimal number of 10 or fewer hex digits Hex digits are 0-9A-F Code requires uppercase A through F Press lower case q to stop entry of the hex digits
DEDCBA9876 Enter a hexadecimal number of 10 or fewer hex digits Hex digits are 0-9A-F Code requires uppercase A through F Press lower case q to stop entry of the hex digits
123456789A
DEDCBA9876 +123456789A ------------ F111111110 y continues
*/
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
