Question

In: Computer Science

In C++ Please, using only the libraries given in this homework prompt, Write a program that...

In C++ Please, using only the libraries given in this homework prompt,

Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number.

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

<your answer goes here>

return 0;

}

Solutions

Expert Solution

Please upvote if you are able to understand this and if there is any query do mention it in the comment section.

(1) CODE:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int n1, n2;//creating two integer variables
cout << "Enter any two integers" << endl;//prompting user for input
cin >> n1 >> n2;

return 0;
}

OUTPUT:

(2) CODE:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int n1, n2;//creating two integer variables
int sum = 0;//creating the variable for sum
cout << "Enter any two integers" << endl;//prompting user for input
cin >> n1 >> n2;
sum = n1 + n2;//adding the both the numbers
cout << "The sum of two numbers is: " << sum;
return 0;
}

OUTPUT:

(3) CODE:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int n1, n2;//creating two integer variables
int sum = 0;//creating the variable for sum
double divide = 0;//creating the variable for dividie
cout << "Enter any two integers" << endl;//prompting user for input
cin >> n1 >> n2;
sum = n1 + n2;//adding the both the numbers
divide = n1 / n2;//dividing the first number by second number
cout << "The sum of two numbers is: " << sum << endl;
cout << "The division of first number by second number is: " << divide;
return 0;
}

OUTPUT:

(4). CODE:

#include <iostream>
#include <iomanip>
#include <cmath>//importing the cmath library

using namespace std;

int main()
{
int n1, n2;//creating two integer variables
int sum = 0;//creating the variable for sum
double divide = 0;//creating the variable for dividie
int power = 0;////creating the variable for calculating power
double naturalLog = 0;
cout << "Enter any two integers" << endl;//prompting user for input
cin >> n1 >> n2;
sum = n1 + n2;//adding the both the numbers
divide = n1 / n2;//dividing the first number by second number
power = pow(n2, n1);//using the pwer function of cmath library
//in this first number will be raise to the power of second number
naturalLog = log(power);//using the function of cmath library
//passing power variable as parameter to the log function to calulate log
cout << "The sum of two numbers is: " << sum << endl;
cout << "The division of first number by second number is: " << divide << endl;
cout << "The first number raised to the power of second number is: " << power << endl;
cout << "The natural log of first number raised to the second number is: " << naturalLog << endl;
return 0;
}

OUTPUT:

If this was supposed to be done in any other way then please mention it in the comment section otherwise please upvote.


Related Solutions

Given a queue of integers, write an algorithm and the program in c++ that, using only...
Given a queue of integers, write an algorithm and the program in c++ that, using only the queue ADT, calculates and prints the sum and the average of the integers in the queue without changing the contents of the queue.
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and...
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and "#include<cmath>" The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:       0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...
Using only core C++ (no special libraries, except STL vector or string if you want), write...
Using only core C++ (no special libraries, except STL vector or string if you want), write a C++ program that allows a user to input a string and (a) Checks if the expression is a valid polynomial. Parentheses or negation are not allowed. Spaces should be ignored. E.g., the following are valid i. n^2+2*n+5 ii. 2*n + 4.54* n^5 +4 +5*n and the following are invalid iii. n^3n iv. n^4.2 v. 5n vi. n^3 -3*n if an input is given...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt the user for 6 integer values and store them in arr. Prompt the user for a target integer target. Search for targetin arr. If targetis found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message “the element target not found” will be printed...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
Write a C program with the following prompt *do not use gotostatement* "Write an interactive...
Write a C program with the following prompt *do not use goto statement* "Write an interactive program that implements a simple calculator. The program should allow the user to choose a binary arithmetic operation and enter two terms to which to apply the operation. The program should then compute the result and display it to the user. Your calculator will have two modes: double-precision mode and integer mode. Double-precision mode will do calculations and output using variables of type double....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT