Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If they pick decimal to If the user picks the conversion, ask them if they want

ID: 3902590 • Letter: I

Question

If they pick decimal to If the user picks the conversion, ask them if they want to convert decimal to hexadecimal or hexadecimal to decimal. hexadecimal, ask them if they want to use lowercase or uppercase letters in the printing of the hexadecimal number. Use boolean input, so input the answer as true or false and put the use?s answer in a boolean alphabetic variable. Then input a whole number in the proper base. Print the inputted number in the user's base and in the converted base. Use the prefix for printing the hexadecimal numbers. 3. 4. If the user picks the cstring date, input a cstring date in the form mm/dd/yyyy to convert to the form mm-dd-yyyy. Use cstring functions for tokens and concatenating. Divide the cstring into three tokens and concatenate the three cstring tokens together with the - between the month and day and the day and year. Print the newly formatted date.

Explanation / Answer

/* C++ Program - Hexadecimal to Decimal Conversion */

#include<iostream.h>

#include<stdlib.h>

#include<conio.h>

#include<math.h>

unsigned long convtodecnum(char hex[]);

void main()

{

clrscr();

unsigned long decnum;

char hex[9]; // 8 characters for 32-bit Hexadecimal Number and one for ' '

cout<<" Enter 32-bit Hexadecimal Number : ";

cin>>hex;

decnum = convtodecnum(hex);

cout<<"Value in Decimal Number is "<<decnum<<" ";

getch();

}

unsigned long convtodecnum(char hex[])

{

char *hexstr;

int length = 0;

const int base = 16; // Base of Hexadecimal Number

unsigned long decnum = 0;

int i;

// Now Find the length of Hexadecimal Number

for (hexstr = hex; *hexstr != ''; hexstr++)

{

length++;

}

// Now Find Hexadecimal Number

hexstr = hex;

for (i = 0; *hexstr != '' && i < length; i++, hexstr++)

{

// Compare *hexstr with ASCII values

if (*hexstr >= 48 && *hexstr <= 57) // is *hexstr Between 0-9

{

decnum += (((int)(*hexstr)) - 48) * pow(base, length - i - 1);

}

else if ((*hexstr >= 65 && *hexstr <= 70)) // is *hexstr Between A-F

{

decnum += (((int)(*hexstr)) - 55) * pow(base, length - i - 1);

}

else if (*hexstr >= 97 && *hexstr <= 102) // is *hexstr Between a-f

{

decnum += (((int)(*hexstr)) - 87) * pow(base, length - i - 1);

}

else

{

cout<<"Invalid Hexadecimal Number ";

}

}

return decnum;

}

4)

#include <iostream>

using namespace std;

int main() {

long int longdate = 20120305, newlongdate;

int Day,Month,Year;

do {d:

cout<<" Enter Long Date (yyyymmdd) "<<endl;

cin>>longdate;

}

while(longdate<0); {

Month = (int)longdate %100; // month

longdate /=100;

Day =(int) longdate % 100; //getting date

longdate /=100;

Year =(int) longdate;

} //year

goto d;

cout<< longdate <<" is "<< Day <<" / " <<Month<<" / " <<Year<<endl;

system("pause");

return 0;

}