Programmer-Defined Functions, Call-by-Value, Multiple Files Lab 5

Slides:



Advertisements
Similar presentations
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
Advertisements

Chapter 7 - Functions. Functions u Code group that performs single task u Specification refers to what goes into and out of function u Design refers to.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 - The Preprocessor Outline 17.1Introduction 17.2The #include Preprocessor Directive 17.3The.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
Chapter 6: Functions.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
C++ Functions. Objectives 1. Be able to implement C++ functions 2. Be able to share data among functions 2.
Functions Modules in C++ are called functions and classes Functions are block of code separated from main() which do a certain task every C++ program must.
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 6 September 17, 2009.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Functions CIS Feb-06. Summary Slide Using Functions Mathematical Functions Misc. Functions Naming Conventions Writing Functions –Function Prototype.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Chapter 6: Programmer- defined Functions Development of simple functions using value and reference parameters JPC and JWD © 2002 McGraw-Hill, Inc. Modified.
Chapter 8 Scope of variables Name reuse. Scope The region of program code where it is legal to reference (use) a variable The scope of a variable depends.
L function n predefined, programmer-defined l arguments, (formal) parameters l return value l function call, function invocation l function definition.
Object-Oriented Programming. Procedural Programming All algorithms in a program are performed with functions and data can be viewed and changed directly.
CSIS 113A Lecture 8 Parameters.  Two methods of passing arguments as parameters  Call-by-value  ‘copy’ of value is passed  Call-by-reference  ‘address.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
CSCI 171 Presentation 6 Functions and Variable Scope.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Chapter 6 Functions. Topics Basics Basics Simplest functions Simplest functions Functions receiving data from a caller Functions receiving data from a.
L what are predefined functions? l what is? n function name n argument(s) n return value n function call n function invocation n nested function call l.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
Function 2. User-Defined Functions C++ programs usually have the following form: // include statements // function prototypes // main() function // function.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
L what are executable/non-executable statements l out of the ones below which constructs are executable #include p=3.14; const double PI=3.14; int myfunc(int);
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
Lecture 2 Functions. Functions in C++ long factorial(int n) The return type is long. That means the function will return a long integer to the calling.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 6: Functions.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
Chapter 6 Functions. 6-2 Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5.
L what is a void-function? l what is a predicate? how can a predicate be used? l what is program stack? function frame? l what’s call-by-value? l what’s.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
L what is a void-function? l what is a boolean function? l is it possible for a function to have no parameters? l what is program stack? function frame?
Pointer to an Object Can define a pointer to an object:
What Is? function predefined, programmer-defined
Lab Instructor: Salem Othman
Predefined Functions Revisited
Lab Instructor: Salem Othman
Chapter 13 - The Preprocessor
Functions Separate Compilation
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
Chapter Structured Types, Data Abstraction and Classes
FUNCTIONS IN C++.
Chapter 6: Functions Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Global & Local Identifiers
Multiple Files Revisited
Structures putting data together.
User Defined Functions
Previous Lecture Review
6 Chapter Functions.
Functions.
Structures putting data together.
C++ Compilation Model C++ is a compiled language
C Preprocessor Seema Chandak.
Multiple Files Revisited
Predefined Functions Revisited
What Is? function predefined, programmer-defined
Class rational part2.
Presentation transcript:

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