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: ame << " of " << value << " = " << setw(10) << result << endl; return; } outp utRe sult s outp calls utOn eRes ult Page 14 CS 140 Chapter 4 Testing Functions When writing a program, it's a good idea to test individual functions as they're written, rather than waiting until the entire program is complete. CS 140 Chapter 4 Page 15 #include <iostream> using namespace std; double queryUserForValue(); void computeSeries(double x, double &sum, int &nbrLoops); void outputResults(double result, int iterations); void main() { double number, convergentValue; int nbrIterations; number = queryUserForValue(); computeSeries(number, convergentValue, nbrIterations); outputResults(convergentValue, nbrIterations); } double queryUserForValue() { return 0.00; } void computeSeries(double x, double &sum, int &nbrLoops) { sum = 1.234567899; nbrLoops = 999; } void outputResults(double result, int iterations) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(8); cout << "The series converges to " << result << endl << " in " << iterations << " iterations." << endl << endl; } Stub Functions To test whether the main function and the outputResults function are working correctly, the other functions are temporarily written as stubs. When the output is satisfactory, the programmer can proceed to write the real functions. CS 140 Chapter 4 Page 16 The main function below is not the desired main function. A Driver Function #include <iostream> using namespace std; It was designed to test the calculateDayOfYear function! int calculateDayOfYear(int theDay, int theMonth, int theYear); void main() { cout << 1 << '/' << 1 << '/' &l...
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