Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5 Lab Instructor: Salem Othman
Review Go to Dr. Mikhail Nesterenko website and read the topics: Programmer-defined functions, local and global variables, call-by-value Separate files, independent compilation, header files Void-functions, predicates, call-by-reference You need to understand: Programmer-Defined Functions function name, function head, function body, return type, return statement Function Invocation (caller, callee) Function arguments Function Prototype Local Variables Global Constants and Variables Call-by-Value Program in Multiple Files Include Files Multiple Inclusion Protection
Function argument double circleArea (double r) { function name parameter return type argument double circleArea (double r) { const double PI = 3.1415; return PI * r * r; } function head cout << circleArea(4)+6 << endl; invocation function body return statement
2 5 1 2 5 1 8 2 5 1 2 5 1 8 var1 var2 var3 result arg1 arg2 arg3 2 5 1 2 5 1 8 arg1 arg2 arg3 result 2 5 1 2 5 1 8
sum.cpp
Sum.h sum.cpp sumFun.cpp
Multiple Inclusion Protection header file myheader.h containing definitions usually has the following structure: #ifndef MYHEADER_H #define MYHEADER_H // text of the header file goes here #endif
Character