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

C++ Functions & Streams Write a program that will demonstrate some of the C++ Li

ID: 3835182 • Letter: C

Question

C++ Functions & Streams

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.

1.              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.

2.              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.

3.              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.

4.              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   

Explanation / Answer

c++ code:

#include <bits/stdc++.h>
#include <sstream>
using namespace std;

int main()
{
   while(true)
   {
       int c ;
       cout << "Enter 1 for Cosine calculation! " << "Enter 2 for Log calculation! ";
       cout << "Enter 3 to convert into Hexadecimal! " << "Enter 4 to Quit! ";
       cin >> c;
       if(c == 1)
       {
           int n;
           cout << "Enter 1 for Cosine calculation! " << "Enter 2 for arc Cosine calculation! " << "Enter 3 for hyperbolic cosine calculation! ";           
           cin >> n;
           if(n == 1)
           {
               float d;
               cout << "Enter the input number! ";
               cin >> d;
               cout << "Cosine(" << d << ") = " << cos(d) << endl;
           }
           else if(n==2)
           {
               float d;
               cout << "Enter the input number! ";
               cin >> d;
               cout << "Arc Cosine(" << d << ") = " << acos(d) << endl;
           }
           else if(n == 3)
           {
               float d;
               cout << "Enter the input number! ";
               cin >> d;
               cout << "hyperbolic Cosine(" << d << ") = " << cosh(d) << endl;
           }else{cout << "Invalid input ";}
       }
       else if(c == 2)
       {
           int n;
           cout << "Enter 1 for Natural Log calculation! " << "Enter 2 for common logarithm calculation! ";           
           cin >> n;
           if(n == 1)
           {
               float d;
               cout << "Enter the input number! ";
               cin >> d;
               cout << "log(" << d << ") = " << log(d) << endl;
           }
           else if(n==2)
           {
               float d;
               cout << "Enter the input number! ";
               cin >> d;
               cout << "log10(" << d << ") = " << log10(d) << endl;
           }else{cout << "Invalid input ";}

       }
       else if(c == 3)
       {
           int n;
           cout << "Enter 1 for Dec to HexaDec! " << "Enter 2 for HexaDec to Dec! ";           
           cin >> n;
           std::map<int, string> mymapl;
           mymapl[0] = "0"; mymapl[1] = "1"; mymapl[2] = "2"; mymapl[3] = "3"; mymapl[4] = "4"; mymapl[5] = "5";
           mymapl[6] = "6"; mymapl[7] = "7"; mymapl[8] = "8"; mymapl[9] = "9"; mymapl[10] = "a"; mymapl[11] = "b";
           mymapl[12] = "c"; mymapl[13] = "d"; mymapl[14] = "e"; mymapl[15] = "f";
           std::map<int, string> mymapu;
           mymapu[0] = "0"; mymapu[1] = "1"; mymapu[2] = "2"; mymapu[3] = "3"; mymapu[4] = "4"; mymapu[5] = "5";
           mymapu[6] = "6"; mymapu[7] = "7"; mymapu[8] = "8"; mymapu[9] = "9"; mymapu[10] = "A"; mymapu[11] = "B";
           mymapu[12] = "C"; mymapu[13] = "D"; mymapu[14] = "E"; mymapu[15] = "F";
           if(n == 1)
           {
               int d;
               cout << "Enter the input number! ";
               cin >> d;
               int b;
               cout << "Enter 1 for lower case and 2 for upper!";
               cin >> b;
               if(b == 1)
               {
                   cout << d <<" = 0x";
                   string s = "";
                   while(d > 0)
                   {
                ostringstream temp;
                       int r = d%16;
                       d = d/16;
                   temp<<mymapl[r];
                       s = temp.str() + s;
                   }
                   cout << s << endl;
               }
               else
               {
                   cout << d <<" = 0x";
                   string s = "";

                   while(d > 0)
                   {
                ostringstream temp;
                       int r = d%16;
                       d = d/16;
                   temp<<mymapu[r];
                       s = temp.str() + s;
                   }
                   cout << s << endl;
               }
           }
           else if(n==2)
           {
               string s;
               cout << "Enter the Hexadecimal number! ";
               cin >> s;
               std::map<char,int> mymapu1;
               mymapu1['0'] = 0; mymapu1['1'] = 1; mymapu1['2'] = 2; mymapu1['3'] = 3; mymapu1['4'] = 4; mymapu1['5'] = 5;
               mymapu1['6'] = 6; mymapu1['7'] = 7; mymapu1['8'] = 8; mymapu1['9'] = 9; mymapu1['A'] = 10; mymapu1['B'] = 11;
               mymapu1['C'] = 12; mymapu1['D'] = 13; mymapu1['E'] = 14; mymapu1['F'] = 15;              
               std::map<char,int> mymapl1;
               mymapl1['0'] = 0; mymapl1['1'] = 1; mymapl1['2'] = 2; mymapl1['3'] =3; mymapl1['4'] = 4; mymapl1['5'] = 5;
               mymapl1['6'] = 6; mymapl1['7'] = 7; mymapl1['8'] = 8; mymapl1['9'] = 9; mymapl1['a'] = 10; mymapl1['b'] = 11;
               mymapl1['c'] = 12; mymapl1['d'] = 13; mymapl1['e'] = 14; mymapl1['f'] = 15;
               int b;
               cout << "Enter 1 for lower case and 2 for upper!";
               cin >> b;
               if(b == 1)
               {
                   int sum = 0;
                   int j = 0;
                   for (int i = s.length()-1; i >= 0; i--)
                   {
                       char ns = s[i] ;
                       sum = sum + (pow(16,j))*mymapl1[ns] ;
                       j++;
                   }
                   cout << "0x" << s << " = " << sum << endl;
               }
               else
               {
                   int sum = 0;
                   int j = 0;
                   for (int i = s.length()-1; i >= 0; i--)
                   {
                       char ns = s[i] ;
                       sum = sum + (pow(16,j))*mymapu1[ns];
                       j++;
                   }
                   cout << "0x" << s << " = " << sum << endl;
               }  
           }else{cout << "Invalid input ";}          
       }
       else if(c == 4)
       {
           exit(0);
       }
       else
       {
           cout << "Invalid input! ";
       }
   }
   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