- Lab Section Name Lab 7 Functions Part II Pre-Lab Please read the pre-lab and answer the accompanying questions before your lab session In this

Info iconThis preview shows pages 1–3. 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: Lab Section:______ Name:_________________________________ Lab 7 Functions, Part II Pre-Lab: Please read the pre-lab and answer the accompanying questions before your lab session. In this lab, you will learn: how to describe function headers using plain English the difference between value-returning and non-value-returning functions how to code non-value-returning functions more about value-returning functions more about parameters Two very important elements of any function header are the return type and the parameter list . The return type of a function indicates what kind of data will come out of the function when it is done executing. For instance, if you had a function that looked like this: double getRadius() { double radius; cout << "Please enter the radius of the circle: "; cin >> radius; return radius; } You would know that a double would be returned from the function, and thus you could call it like this: double circleRadius; circleRadius = getRadius(); The typical full description for the function getRadius() would be, "The function getRadius returns a double and takes no parameters." It's a good idea to practice describing functions by their headers, because effectively communicating and understanding function descriptions can save a lot of time and effort when programming, especially in a collaborative setting. As we saw above, many functions return some kind of data to the calling code when they finish executing. These kinds of functions are called value-returning functions . However, while many functions return values, there is a special kind of function that does not. As Captain Obvious could probably guess, they are called non-value-returning functions (or void functions ). Their second name comes from the special return type these functions have. A non-value-returning function might look like this: void printStars(int numStars) { for(int i = 0; i < numStars; i++) { cout << "*"; } cout << endl; return; } CSE 100 Lab 7 1/5 As you can probably tell, this function prints out numStars worth of stars to the console, followed by a new line character. Since this function just executes an action, there's no need to have it return anything....
View Full Document

This note was uploaded on 09/20/2010 for the course CSE 100 taught by Professor Na during the Spring '09 term at University of Arizona- Tucson.

Page1 / 5

- Lab Section Name Lab 7 Functions Part II Pre-Lab Please read the pre-lab and answer the accompanying questions before your lab session In this

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

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