l05 - CSci 1113 C/C for Scientists and Engineers Section...

This preview shows pages 1–6. Sign up to view the full content.

: CSci 1113 C/C++ for Scientists and Engineers Section 010 - evening class Functions Prof. Eric Van Wyk and Ted Kaminski Spring 2010 c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 1 / 18

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Pure and Eﬀectful Functions : Sample functions I Mathematics I double x = cos(0.34) ; I double p = pow(2.0,5.0); I Random numbers I srand(seed); Seeds the pseudo-random number generator. I r = rand(); Returns the next pseudo-random number. I Need to include <cstdlib> . c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 2 / 18
Pure and Eﬀectful Functions : I How can we modify Random.cpp to generate random integer numbers between a speciﬁed range? Say, between 1 and some value n ? I How can we modify it to generate ﬂoating point random numbers in the range [0,1] ? I http://www.cplusplus.com is a reasonable reference. See also http://www.cppreference.com/ . c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 3 / 18

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Pure and Eﬀectful Functions : Exercise 5.1 Modify your square root program to assign a value to guess randomly. What eﬀect does this have on the behavior of your program? c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 3 / 18
Pure and Eﬀectful Functions : Pure and impure functions I Most functions are pure functions . I A pure function always returns the same result when given the same input and have now eﬀect on program variables. (Except when the result of the function call is assigned to a variable.) I For example, cos and pow are pure functions. I Both srand and rand are not pure, or impure .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 22

l05 - CSci 1113 C/C for Scientists and Engineers Section...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online