0% found this document useful (0 votes)
6 views

Module 15

The document outlines objectives for students to convert algebraic expressions into C++ arithmetic expressions and write algorithms for random number generation. It explains the concept of pseudorandom number generators and provides standard C functions for random number generation and mathematical operations. Additionally, it includes examples of mathematical expressions and their corresponding C++ expressions, along with a C++ program exercise for calculating various mathematical functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Module 15

The document outlines objectives for students to convert algebraic expressions into C++ arithmetic expressions and write algorithms for random number generation. It explains the concept of pseudorandom number generators and provides standard C functions for random number generation and mathematical operations. Additionally, it includes examples of mathematical expressions and their corresponding C++ expressions, along with a C++ program exercise for calculating various mathematical functions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Objectives:

At the end of the reading, the students should be able to;


1. Convert algebraic expression into C++ arithmetic expression.
2. Write an algorithm for the application of the random number generation
useful particularly in games and simulations.
All algorithmic random number generators actually produce
pseudorandom numbers, not true random numbers.
A pseudorandom number generator has a particular period, based on
the nature of the algorithm used. If the generator is used long enough, the
pattern of numbers produced repeats itself exactly. A sequence of true
random numbers would not contain such a repeating subsequence. The
good news is that all practical algorithmic pseudorandom number
generators have periods that are large enough for most applications.
Standard C functions:
void srand(unsigned) - establishes the first value in the sequence
int rand() - returns the next value in the sequence
Header <cmath> or <math.h> declares a set of functions to compute
common mathematical operations and transformations.

Numeric Functions
Trigonometric functions:
 cos Compute cosine
 sin Compute sine
 tan Compute tangent
 acos Compute arc cosine
 asin Compute arc sine
 atan Compute arc tangent a
 atan2 Compute arc tangent with two parameters
Hyperbolic functions:
 cosh Compute hyperbolic cosine
 sinh Compute hyperbolic sine
 tanh Compute hyperbolic tangent
 acosh Compute arc hyperbolic cosine
 asinh Compute arc hyperbolic sine
 atanh Compute arc hyperbolic tangent

Power functions:
 pow Raise to power pow(base, exponent)
 sqrt Compute square root
 cbrt Compute cubic root
 hypot Compute hypotenuse
Exponential and logarithmic functions:
 exp Compute exponential function
 frexp Get significand and exponent
 ldexp Generate value from significand and exponent
 log Compute natural logarithm
 log10 Compute common logarithm
 modf Break into fractional and integral parts
 exp2 Compute binary exponential function
 expm1 Compute exponential minus one
 ilogb Integer binary logarithm
 log1p Compute logarithm plus one
 log2 Compute binary logarithm
 logb Compute floating-point base logarithm
 scalbn Scale significand using floating-point base exponent
 scalbln Scale significand using floating-point base exponent (long)
Mathematical Expressions C++ Expressions

sine x + 3n + tangent 4x sin (x) + 3*n + tan (4*x)

sinh 5x + 3 sinh ( 5*x + 3)

𝑒 2𝑥 exp (2x)

log10 3x log10 (3*x)

log2 4x + log10 5 Log2 (4*x) + log10 (5)

𝑟2 pow(base, exponent) = pow(r,2)

10210 pow(102,10)
3
25𝑥 cbrt (25*x)

3𝑛2 3 * pow (n, 2)

3𝑛 2 Pow (3*n, 2)
1. Create a C++ program that allows you to input values for x
and y, the program will then calculate the following;
a. tan−1 3𝑥 2 + 𝑒 𝑥𝑦
3
b. 3𝑥𝑦 + 3𝑥 2
𝑥𝑦 2
c. sin + 𝑒 𝑥𝑦
2𝑥
3𝑦 2 3𝑥 2
d. + 𝑒
𝑥𝑦 2

e. 𝑐 = 𝑥2 + 𝑦2
a. 3𝑥 2 + 𝑒 𝑥𝑦 − 3 ∗ 𝑝𝑜𝑤 𝑥, 2 + exp(𝑠𝑞𝑟𝑡 𝑥 ∗ 𝑦 )
3 2
b. 3𝑥𝑦 + 3𝑥 −𝑐𝑏𝑟𝑡 3 ∗ 𝑥 ∗ 𝑦 + 𝑝𝑜𝑤 3 ∗ 𝑥, 2
𝑥𝑦 2
c. sin + 𝑒 𝑥𝑦 −(sin(x∗pow(y,2))/(2∗x)) + exp(x*y)
2𝑥
3𝑦 2 2
d. + 𝑒 3𝑥 sqrt( ((3∗pow(y,2)) / (x∗pow(y,2))) + exp(3*pow(x,2)) )
𝑥𝑦 2

e. 𝑐= 𝑥2 + 𝑦2 -sqrt( pow(x,2) + pow(y,2) )

You might also like