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 change the format of a cstring date. You must use the proper functions and/or stream manipulators to find the answers.
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
cstring date 10/17/2018 to 10-17-2018
c++ code:
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
int main()
{
while(true)
{
int c ;
cout << "Enter 1 for Cosine calculation!\n" << "Enter 2
for Log calculation!\n";
cout << "Enter 3 to convert into Hexadecimal!\n" <<
"Enter 4 to Quit!\n";
cin >> c;
if(c == 1)
{
int n;
cout << "Enter 1 for Cosine calculation!\n" << "Enter 2
for arc Cosine calculation!\n" << "Enter 3 for hyperbolic
cosine calculation!\n";
cin >> n;
if(n == 1)
{
float d;
cout << "Enter the input number!\n";
cin >> d;
cout << "Cosine(" << d << ") = " << cos(d)
<< endl;
}
else if(n==2)
{
float d;
cout << "Enter the input number!\n";
cin >> d;
cout << "Arc Cosine(" << d << ") = " <<
acos(d) << endl;
}
else if(n == 3)
{
float d;
cout << "Enter the input number!\n";
cin >> d;
cout << "hyperbolic Cosine(" << d << ") = "
<< cosh(d) << endl;
}else{cout << "Invalid input\n";}
}
else if(c == 2)
{
int n;
cout << "Enter 1 for Natural Log calculation!\n" <<
"Enter 2 for common logarithm calculation!\n";
cin >> n;
if(n == 1)
{
float d;
cout << "Enter the input number!\n";
cin >> d;
cout << "log(" << d << ") = " << log(d)
<< endl;
}
else if(n==2)
{
float d;
cout << "Enter the input number!\n";
cin >> d;
cout << "log10(" << d << ") = " << log10(d)
<< endl;
}else{cout << "Invalid input\n";}
}
else if(c == 3)
{
int n;
cout << "Enter 1 for Dec to HexaDec!\n" << "Enter 2 for
HexaDec to Dec!\n";
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!\n";
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!\n";
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\n";}
}
else if(c == 4)
{
exit(0);
}
else
{
cout << "Invalid input!\n";
}
}
return 0;
}
C++ Functions & Streams Write a program that will demonstrate some of the C++ Library Functions,...
Write a C++ program that determines the user's age after the user enters both the current date and hisher birthdate as 3 integers: yyyy mm dd Define a class which is named DateType and will be used to declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy and it will have a second function named “input”...
Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...
Write a C program that will act as a database access tool. Three separate functions are needed to: 1. Print dates 2. Print names 3. Print category numbers and the average of the numbers. A random text file (from notepad) is supplied for the dates, names, and category's. For Example: Storm name: Storm Date: Storm category number: The program must ask the user which of the three items listed above they want to run instead of dumping all of the...
Write a program that incorporates these functions and statements: • list • while loop • for loop • if • print() • input() • concatenation This program must create a grocery shopping list based on the user input • the program will ask a user to enter a new grocery item until the user presses Enter • then all user input will be added to a list • then the list with all grocery items will be printed
Assignment C++: Rock-Scissor-Paper & Tic-Tac-Toe i need you to write two different program for RSP and TTT: R-S-P Requirement: - write one program that mimics the Rock-Scissor-Paper game. This program will ask user to enter an input (out of R-S-P), and the computer will randomly pick one and print out the result (user wins / computer wins). - User's input along with computer's random pick will be encoded in the following format: -- user's rock: 10 -- user's scissor: 20...
c programming Problem 2 Write a Hexadecimal to Decimal converter. Program will take an input (hexadecimal number) from user and display its corresponding decimal number, as an output, on the screen. Moreover, after you're done with one conversion, ask for another input in an infinite loop fashion, link to online Hexadecimal to Decimal converter: https://www.binaryhexconverter.com/hex-to-decimal-converter 50 point
In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...
IN PERL Write a program that will ask the user for a number and will print all the integers in order starting from 1 until the number. Use the <> operator to ask for the user's input. For this program you will write a countdown timer. Your time will count down from 1 minute (60 seconds) to 0. Once the timer gets to 0 seconds the system will display a message that reads: RING RING RING! -using do while-
C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions, files, and arrays. Do NOT use material such as classes. Make sure to add comments** You are to write an ATM Program. The ATM should allow the user to do the following: 1. Create account 2. Log in 3. Exit When they press 1, they are asked for first name (capital first letter). Then it should ask for password. The computer should give the...
USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...