l05_6up - : CSci 1113 C/C++ for Scientists and Engineers...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: : 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 Pure and Effectful 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 Effectful Functions : I How can we modify Random.cpp to generate random integer numbers between a specified range? Say, between 1 and some value n ? I How can we modify it to generate floating 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 Pure and Effectful Functions : Exercise 5.1 Modify your square root program to assign a value to guess randomly. What effect 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 Effectful 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 effect 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....
View Full 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 / 4

l05_6up - : CSci 1113 C/C++ for Scientists and Engineers...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online