OOP Lab - 2.3 - C++ Math
OOP Lab - 2.3 - C++ Math
C++ Programming
Computer Instructor: Muhammad Abdullah Orakzai
1) C++ Math
2
C++ Math
C++ has many functions that allows you to perform mathematical tasks on numbers.
3
Max and min
The max(x,y) function can be used to find the highest value of x and y:
Example
cout << max(5, 10);
4
Max and min…
And the min(x,y) function can be used to find the lowest value of x and y:
Example
cout << min(5, 10);
5
Max and min Example
#include<iostream>
int main()
{
return 0;
}
6
C++ <cmath> Headers
Other functions, such as sqrt (square root), round (rounds a number) and log (natural
logarithm), can be found in the <cmath> header file:
Example
// Include the cmath library
#include <cmath>
7
C++ <cmath> Headers Example
#include<iostream>
using namespace std;
#include<cmath>
int main()
{
return 0; 8
}
Other Math Functions
A list of other popular Math functions (from the <cmath> library) can be found in the
table below:
Function Description
abs(x) Returns the absolute value of x
acos(x) Returns the arccosine of x
asin(x) Returns the arcsine of x
atan(x) Returns the arctangent of x
cbrt(x) Returns the cube root of x
ceil(x) Returns the value of x rounded up to its nearest integer
cos(x) Returns the cosine of x
9
Other Math Functions…
10
Other Math Functions…
11
Other Math Functions…
12
Home Task
In previous slides 23 math functions (Other Math Functions) are listed in the form of
table you all are directed to implement all these functions using C++ program. And show
me program in running form in upcoming lab. This task carry 10 marks.
Note: Program copied from someone or plagiarized will not be considered for grading.
Zero percent tolerance with plagiarism.
13
References
• https://beginnersbook.com/2017/08/cpp-data-types/
• https://www.geeksforgeeks.org/c-data-types/
• http://www.cplusplus.com/doc/tutorial/basic_io/
• https://www.geeksforgeeks.org/basic-input-output-c/
• https://www.w3schools.com/cpp/default.asp
• https://www.javatpoint.com/cpp-tutorial
14
THANK YOU
Thanks
15