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

There was a same question posted on here for this but the answer given was incor

ID: 3581996 • Letter: T

Question

There was a same question posted on here for this but the answer given was incorrect as I tried to fix it so please dont copy and paste it from there.

Write a program that will demonstrate some of the C++ Library Functions, Stream Manipulators, and Selection Control Structures. The user will be given a menu of four choices. They can input a 1 for finding Cosines, 2 for finding Logarithms, 3 for converting between Decimal and Hexadecimal, or 4 to Exit the program. You must use the proper functions and/or stream manipulators to find the answers.

If the user picks the cosine, ask them if they want to find the cosine, arc cosine, or hyperbolic cosine. Then input a floating point number (in radians) and find and print to three decimal places the proper type of cosine.

If the user picks the logarithms, ask them if they want to find the common logarithm or the natural logarithm. Then input a floating point number and find and print to three decimal places and a plus or minus sign (for positive or negative numbers) the proper type of logarithm.

If the user picks the conversion, ask them if they want to convert decimal to hexadecimal or hexadecimal to decimal. If they pick decimal to 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 user'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.

If the user picks the exit, use the actual exit function to end the program

If you want to use a loop in the program for multiple runs that is fine, but you can write it so it does one thing per run if you wish.

Run your program with all of the following sets of data, showing all possibilities work correctly. Submit your .cpp main program and the output .txt saved (copy & paste from console) into a plain text file. Include in the program a full paragraph of documentation (at least 4 lines). Supply extra documentation (at least 5 comments) throughout for all of the not easily understandable lines of code (especially on how you used the library functions or stream manipulators).

Cosine of .87

Arc Cosine of .87

Hyperbolic Cosine of .87

Common Logarithm of 33

Natural Logarithm of 33

Decimal 93 to Hexadecimal with true Lower Case

Decimal 93 to Hexadecimal with false Lower Case - Upper Case

Hexadecimal 5d to Decimal

Exit     g

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{int flag=1;
     
   while(flag)
   {

       cout<<"1)Cosine 2)Logarithms 3)Conversion 4)Quit ";
           int ch;float n;
           cin>>ch;


           switch(ch)
           {
               case 1:cout<<"1)Cosine 2)Arc Cosine 3)Hyperbolic Cosine ";
                   cin>>ch;
                   cout<<"Enter number ";
                     
                   cin>>n;
                   if(ch==1)
                   {
                      cout<<"Cosine of"<<n<<" "<<std::setprecision(3)<<cos(n);
                   }
                   if(ch==2)
                   {
                      cout<<"Arc Cosine of"<<n<<" "<<std::setprecision(3)<<acos(n);
                   }
                   if(ch==3)
                   {
                      cout<<"Hyperbolic Cosine of"<<n<<" "<<std::setprecision(3)<<acosh(n);
                   }
                   cout<<endl;
                   break;
               case 2:
                   cout<<"1)Comman Logarithm 2)Natural Cosine Logarithm ";
                   cin>>ch;
                   cout<<"Enter number ";
                  
                   cin>>n;
                   if(ch==1)
                   {
                      cout<<"Common Logarithm of "<<n<<" "<<log(n)<<endl;
                   }
                   else
                   {
                      cout<<"Natural Logarithm of "<<n<<" "<<log10(n)<<endl;
                   }
                   break;

               case 3:cout<<"1)decimal to hexadecima 2)hexadecimal to decimal ";
                           cin>>ch;
                           if(ch==1)
                           {
                               string re;
                               cout<<"true)lowercase flase)Uppercase ";
                               cin>>re;
                               cout<<"Enter number ";
                               cin>>n;
                               if(re=="true")
                               {
                                       cout<<"Decimal "<<n<<" to Hexadecimal with true Lower Case is "<<std::uppercase<<std::hex<<n<<endl;
                               }
                               else
                               {
                                       cout<<"Decimal "<<n<<" to Hexadecimal with true false Lower Case - Upper Case is "<<std::nouppercase<<std::hex<<n<<endl;
                               }
                           }
                           else
                           {
                               cout<<"Enter number ";
                              

                               unsigned int x;   
                               string s;
                               cin>>s;
                               std::stringstream ss;
                               ss << std::hex << s;
                               ss >> x;
                                 
                               cout<<"Hexadecimal "<<s<<" to Decimal ";
                               std::cout << static_cast<int>(x) << std::endl;


                           }
                           break;
                   case 4:flag=0;
                   break;

           }
   }
  
   return 0;
}

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ g++ man.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
1)Cosine
2)Logarithms
3)Conversion
4)Quit
3
1)decimal to hexadecima
2)hexadecimal to decimal
1
true)lowercase
flase)Uppercase
true
Enter number
12
Decimal 12 to Hexadecimal with true Lower Case is 12
1)Cosine
2)Logarithms
3)Conversion
4)Quit
1
1)Cosine
2)Arc Cosine
3)Hyperbolic Cosine
1
Enter number
.87
Cosine of0.87 0.645
1)Cosine
2)Logarithms
3)Conversion
4)Quit
4

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