Odds and ends about Functions

Odds and ends about Functions - suppose you have written a...

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

View Full Document Right Arrow Icon
Odds and ends about Functions
Background image of page 1

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

View Full DocumentRight Arrow Icon
Stubs and Drivers Functions are useful for top-down design break a big problem down into smaller pieces
Background image of page 2
the top level int main () { int a1, a2; float a3; partone(a1, a2); a2 = a2 + parttwo (a1, a3); partThree (a1, a2, a3, 23); return 0; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
but how to compile? the program in the previous slide won't compile until all the other functions have definitions if you just want to write one of them, you have to fill in the others with "dummies" = "stubs" a stub has the right header but doesn't do anything useful towards solving the problem
Background image of page 4
two Stubs void partThree (int p1, int p2, char p3, int p4) { cout << "in the partThree function"; cout << p1 << " " << p2 << " " << p3; } int partTwo (int p1, int p2) { cout << "In PartTwo" << endl; return 1;
Background image of page 5

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

View Full DocumentRight Arrow Icon
going the other way
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: suppose you have written a function that solves a problem, but. .. you don't have the main function written yet how can you test your function without it? write a "driver" Driver Usually a main function just calls the function to be tested with arguments that make sense reports the results does not try to solve the whole problem Example Driver int main () { int x = 5, y, z= 23; cout << "calling fun1 with x = " << x << "and z = " << z << endl; y = fun1 (x, z); cout << "result of calling fun1 is " << y << endl; return 0; scaffolding both stubs and drivers known as "scaffolding" not part of the finished program but very useful when testing parts of the program usually removed when program is finished...
View Full Document

This note was uploaded on 04/13/2011 for the course CS 115 taught by Professor Staff during the Fall '08 term at Kentucky.

Page1 / 9

Odds and ends about Functions - suppose you have written a...

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

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