Coding in C++

10.

These are the instructions:

This is an updated version of assignment from a previous chapter that calculated the minimum and maximum values. This version will enhance the program by using more of the built-in math functions. In this assignment, your program will calculate the square root, absolute value, next highest number, and next lowest whole number. It then asks for a second number and calculate the higher and the lower of the two numbers (what it previously did). You may (and are encouraged to do so) begin with a copy of the previous version of this program. Below are the details.


double input1 (first user input),
double input2 (second user input),
double sqRoot (the square root),
double absoluteValue (absolute value),
double nextHighestNum (the next highest whole number),
double nextLowestNum (the next lowest whole number),
double minimumValue (lower inputted value),
double maximumValue (higher inputted value).

1. Using the appropriate functions (sqrtf, fabs, ceilf, floorf) in the cmath library, store and display the calculations from the first inputted number. Print these using the sentence form of the commented text for each variable (the stuff in the parenthesis above). For instance, given the input of 42.51, the first line should read: "Square root: 6.51997".

2. Prompt the user to enter the second number after displaying the previous four values and display results of the remaining two functions (fmin and fmax). The final message should state something like "The number 23.2 is lower than 65".
Liberally comment the code. Each variable must have a descriptive comment on the same line. I have included the comments to use in the parenthesis after each variable above.

3. The output should look something like this -- user inputs are the numbers:

Welcome to the math calculator program.
This program asks for a decimal number, and calculates the square root, absolute value, and the next highest and next lowest whole number. It then asks for a second number, and calculates the higher and the lower of the two numbers.

Enter the first number: 42.87
Square root: 6.54752
Absolute value: 42.87
Next highest whole number: 43
Next lowest whole number: 42

Enter the second number: 3.25
The number 3.25 is lower than 42.87
Thank you for using this program!

The previous code talked about in the beginning is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 #define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;

int main()
{
   std::cout << "Enter the first number: ";
   double input1 { };
   std::cin >> input1;

   std::cout << "Enter the second number: ";
   double input2 { };
   std::cin >> input2;
   std::cout << '\n';

   double min_num { fmin(input1, input2) };
   double max_num { fmax(input1, input2) };

   std::cout << "Minimum: " << min_num << ", Maximum: " << max_num << '\n';
}



Please write the code that produces those results in C++ and in the simplest way possible. Yes this is a homework question but it's the end of the semester and I have a lot of other homework to do for this class. Please help out. Thank you so much.
Last edited on
Do it yourself, you lazy piece of shit.
Homework questions are for you to code, so you learn from the experience.

If we want us to do all the work for you, you might as well post an advertisement in the Jobs section.
Registered users can post here. Sign in or register to post.