Lecture3
Lecture3
Ninevah University
College of Electronics Engineering
Department of Electronic Engineering
MEDICAL INSTRUMENTATION
2nd Year
2024 – 2025
8:30-10:30
Lecturer
Prof Dr. Qais Thanon
Lecture #3
10/6/2024
Mathematical Functions
Mathematical calculations can be done in C++ programming language
using the mathematical functions which are included in math.h
library.
Let’s learn each of them one by one :−
Calling syntax
double x = sin(ang);
#include <iostream.h> #include <iostream.h>
#include <math.h> #include <math.h>
void main(){ void main(){
double x = 45.3, y; double x = 45.3, y;
y = tan(x); y = tan(x * M_PI/180.0);
cout << y; cout << y;
} }
The angle should be in RAD
2
10/6/2024
Mathematical Functions
Power
The pow function is used to calculate the power of the base raised to the
power of exponent.
Calling syntax
double y = pow(a, n); y = an
#include <iostream.h>
#include <math.h>
void main(){ y = 2.85
double x = 2.8, y;
y = pow(x, 5); y = 172.10368
cout << y;
}
n m 7
y = a y = 2.85
3
10/6/2024
Mathematical Functions
Sqrt ( square root)
sqrt function in C++ returns the square root of the double
integer inside the parameter list.
Calling syntax double y = sqrt(x);
Log The logarithm function is used to find the natural log of
the given number.
Calling syntax double x = log(n); x = log(n)
abs The abs function returns the absolute value of the integer
value.
Calling syntax int x = abs(n); x = 𝒏
4
10/6/2024
Each student should
write, at least, five
functions from
"math.h" with the
syntax and purpose
of each function
5
10/6/2024
Conditional Statements
One-Way (if) Selection
if Selection statements:
if (expression) ;
{statement;}
statement;
Relational operators
if (A == 5)
==
if (A != B)
!=
>
if (A > B)
if (A >= B)
>=
<
if (A < 50)
If there are more than one relational operators logical operators should used.
#include <iostream.h>
void main () {
Ex: Write a C++ program to int A,B;
enter two Boolean numbers then, cin >>A ;
cin >>B ;
print phrase "A and B“ if A and if ((A==1)&&(B==1))
B equal to 1, or print phrase "A Or {cout << "A And B"<<'\n';}
B" if A equal to 1 and B equal to if ((A==1)||(B==0))
{cout << "A or B"<<'\n';}
0.
} &&
7
10/6/2024
if-else Selection statements:
Two-Way (if…else) Selection
if (expression)
statement1;
else
statement2;
if (x == 100)
cout << "x is 100";
else
cout << "x is not 100";
8
10/6/2024
Nested if-else Selection statements:
if (Condition1){
if(Condition2){
Statement1;
}
else {
Statement2;
}
}
else {
if(Condition3)
{
Statement3;
}
else
{
Statement4;
}
} 9
10/6/2024