Notes4

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Chapter 4 Functions for All Subtasks Goals: To explore the use of void functions To distinguish between callbyreference and callbyvalue To examine how functions can be nested To introduce testing via stubs and drivers To gain some familiarity with the Visual C++ debugger void Functions When a function returns no value, then it is a void function. void printHeader() { cout << "RUDIMENTARY INTEGER LIST ANALYSIS AND SUMMARY" << endl << endl; cout << "Enter a list of positive integers, ending with -1." << endl; cout << "Afterwards, the maximum, minimum, and mean will be displayed.\n\n"; return; } No Returned Value! int low, int mean) high << endl; low << endl; mean << endl; void outputResults(int high, { cout << "High Value: " << cout << "Low Value: " << cout << "Mean Value: " << return; } CS 140 Most Common Use For void Functions: Pure Output. Page 2 Chapter 4 Calling void Functions void main() { int value; int max = -1; int min = INT_MAX; int total = 0; int count = 0; printHeader(); cout << "Enter value: "; cin >> value; void Function Call When calling a void function, no return value is expected. while (value >= 0) { max = higher(value, max); min = lower(value, min); total += value; count++; cout << "Enter value: "; cin >> value; Non-void Function Call Non-void Function Call } outputResults(max, min, average(total, count)); return; } void Function C...
View Full Document

This note was uploaded on 08/26/2009 for the course CS 140 taught by Professor Staff during the Fall '08 term at Southern Illinois University Edwardsville.

Ask a homework question - tutors are online