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

This program asks user to choose, in case 3, I need to ask the user if they want

ID: 3542886 • Letter: T

Question

This program asks user to choose,

in case 3, I need to ask the user if they want to convert decimal to hexadecimaal or hexadeimal to decimal.


If they pick ===> decimal to hexadecimal, I ask them if they want to use lowercase or uppercase letters in the printing of hexadecimal

Input the answer as true or false

put the user's answer in a boolean alphabetic variable

input a whole number in the proper base

print the inputted number in the usser's base and in the converted base.

use the prefix for the hexadecimal numbers


Case 4:

if user picks exit, use the exit function to end the program.



#include <iostream>

#include <iomanip>

#include <cmath>


using namespace std;


int main()

{

int choice, dec;

char cosine[10], logarithm[10], convert[10];

float ans1, num1, ans2, num2, an2, num3, num, hex;

cout.setf (ios :: fixed);

cout << "Pick one of these choices you want to find: " << endl;

cout << " 1. Find Cosine. "

<< " 2. Find Logarithms. "

<< " 3. Converting between Decimal and Hexadecimal. "

<< " 4. Exit the program, " << endl;

cin >> choice;

switch (choice)

{

case 1 :

{

cout << "Write the value that you want to find the cosine for: " << endl;

cin >> num1;

cout << "Do you want to find the cosine, arc, or hyperbolic" << endl;

cin >> cosine;

if (strcmp(cosine,"cosine")==0)

{

ans1 = cos(num1);

cout << "Cosine of" << num1 << "is:" << setprecision (3) << ans1 << endl;

}


else if (strcmp(cosine,"arc")==0)

{

ans1 = acos(num1);

cout << "Cosine of" << num1 << "is:" << setprecision (3) << ans1 << endl;

}

else if (strcmp(cosine,"hyperbolic")==0)

{

ans1 = cosh(num);

cout << "Cosine of" << num1 << "is:" << setprecision (3) << ans1 << endl;

}

else

cout << "Invalid entry" << endl;

break;

}

case 2:

{

cout << "Write the value that you want to find the logarithms for: " << endl;

cin >> num2;

cout << "Do you want to find the common or natural logarithms: " << endl;

cin >> logarithm;

if (strcmp(logarithm,"common")==0)

{

ans2 = log10 (num2);

cout << "logarithm of" << num2 << "is:" << setprecision (3) << ans2 << endl;

}


else if (strcmp(logarithm,"natural")==0)

{

ans2 = log (num2);

cout << "Cosine of" << num2 << "is:" << setprecision (3) << ans2 << endl;

}

else

cout << "Invalid entry" << endl;

}

break;

}

case 3:

{

cout << "Do you want to convert decimal to hexadecimal or hexadecimal to decimal? : " << endl;

cin >> convert;

if (strcmp(convert, "dectohex")==0)

{

}

}



}

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int choice, dec;
char cosine[10], logarithm[10], convert[10];
float ans1, num1, ans2, num2, an2, num3, num, hex;
cout.setf (ios :: fixed);
cout << "Pick one of these choices you want to find: " << endl;
cout << " 1. Find Cosine. "
<< " 2. Find Logarithms. "
<< " 3. Converting between Decimal and Hexadecimal. "
<< " 4. Exit the program, " << endl;
cin >> choice;
switch (choice)
{
case 1 :
{
cout << "Write the value that you want to find the cosine for: " << endl;
cin >> num1;
cout << "Do you want to find the cosine, arc, or hyperbolic" << endl;
cin >> cosine;
if (strcmp(cosine,"cosine")==0)
{
ans1 = cos(num1);
cout << "Cosine of" << num1 << "is:" << setprecision (3) << ans1 << endl;
}
else if (strcmp(cosine,"arc")==0)
{
ans1 = acos(num1);
cout << "Cosine of" << num1 << "is:" << setprecision (3) << ans1 << endl;
}
else if (strcmp(cosine,"hyperbolic")==0)
{
ans1 = cosh(num);
cout << "Cosine of" << num1 << "is:" << setprecision (3) << ans1 << endl;
}
else
cout << "Invalid entry" << endl;
break;
}
case 2:
{
cout << "Write the value that you want to find the logarithms for: " << endl;
cin >> num2;
cout << "Do you want to find the common or natural logarithms: " << endl;
cin >> logarithm;
if (strcmp(logarithm,"common")==0)
{
ans2 = log10 (num2);
cout << "logarithm of" << num2 << "is:" << setprecision (3) << ans2 << endl;
}
else if (strcmp(logarithm,"natural")==0)
{
ans2 = log (num2);
cout << "Cosine of" << num2 << "is:" << setprecision (3) << ans2 << endl;
}
else
cout << "Invalid entry" << endl;
}
break;
case 3:
{
cout << "Do you want to convert decimal to hexadecimal or hexadecimal to decimal? : " << endl;
cin >> convert;
if (strcmp(convert, "dectohex")==0)
{
char ans;
cout <<"do you want lowercase or uppercase letters in the printing of hexadecimal (t or f)";
cin >> ans;
cout << endl;
int number;
cout << "Enter whole number ";
cin >> number;
cout << endl;
string str;
if(ans=='t')
{
char* table = "0123456789abcdef";
while(number)
{
str = table[number%16] + str;
number = number/16;
}
}
else
{
char* table = "0123456789ABCDEF";
while(number)
{
str = table[number%16] + str;
number = number/16;
}
}
cout << number << " its corresponding hexa decimal is " << str << endl;
}
else if(strcmp(convert, "hextodec")==0)
{
string str;
cout <<"Enter heax deciaml numbeR ";
cin >> str;
int num=0;
for(int i=0; i<str.length(); i++)
{
int power = static_cast<int> (pow(16.0,static_cast<double> (str.length()-1-i)));
if(str[i]>='0' && str[i]<='9')
num = num + power*(str[i]-'0');
else
num = num + power*((str[i]-'A')+10);
}
cout << str << " its corresponding decimal is " << num << endl;
}
}
break;
case 4: cout <<"Program is terminating " << endl; return 0; break;
}
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote