Default Arguments.

Slides:



Advertisements
Similar presentations
Operator overloading redefine the operations of operators
Advertisements

For(int i = 1; i
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Factorial Preparatory Exercise #include using namespace std; double fact(double); int fact(int); int main(void) { const int n=20; ofstream my_file("results.txt");
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Template Implicit function overload. Function overload Function overload double ssqq(double & a, double & b) { return(a*b);} float ssqq(float & a, float.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
Function Overloading. 2 Function Overloading (Function Polymorphism) Function overloading is a feature of C++ that allows to create multiple functions.
Esempio Polimorfismo1 // Definition of abstract base class Shape #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual double area() const { return.
Constructors 11/10/10. Today  Use constructors to initialize objects.  Use const to protect data members.
// Functions that take no arguments #include using namespace std; void function1(); void function2( void ); int main() { function1(); function2(); return.
Function Overloading Can enables several functions Of same name Of different sets of parameters (at least as far as their types are concerned) Used to.
CS Oct 2006 Chap 6. Functions General form; type Name ( parameters ) { … return value ; }
C++ Training Datascope Lawrence D’Antonio Lecture 5 An Overview of C++: What is Polymorphism? - Overloading.
Templates Overload function: define more than one function With same function name Different parameter type Different type Different number of parameter.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
 Review structures  Program to demonstrate a structure containing a pointer.
Practice 1 Seoul National University Graphics & Media Lab.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Functions Sujana Jyothi C++ Workshop Day 2. Functions 3 Parameter transmission modes pass by value (default) pass by reference (&) pass by const reference.
1 Lecture 17 Operator Overloading. 2 Introduction A number of predefined operators can be applied to the built- in standard types. These operators can.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
Lec 13 Oct 21, 02. Array Initialization in the declaration statement ► int temp[5] = {98, 87, 92, 79,85}; ► char codes[6] = { ‘s’, ’a’, ‘m’, ‘p’, ‘l’,
Constructors Initializing New Objects #include “fraction.h” int main() { float x; float y = 6.7; float z(7.2); Fraction.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Functions Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd September 2006.
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Static Variables. Function Scope  “Normal” local variables go out of scope and are deallocated when a function terminates.
Static Members.
Code -> Build -> Run
LESSON 3 IO, Variables and Operators
Structs versus Classes
Templates in C++.
Reserved Words.
Function Basics.
Methods Additional Topics
Conversions of the type of the value of an expression
Unit-2 Objects and Classes
null, true, and false are also reserved.
Object-Oriented Programming (OOP) Lecture No. 36
Lecture 8.
Stack Memory 2 (also called Call Stack)
Introduction to Java Programming
Working With Arrays.
Introduction to Programming
The Run-Time Stack and Reference Parameters
Lec 14 Oct 23, 02.
Introduction to Programming
Local Variables, Global Variables and Variable Scope
Functions 2: Stupid Function Tricks
Introduction to Programming
JavaScript Reserved Words
Introduction to Programming
Recap Week 2 and 3.
7. Pointers, Dynamic Memory
Introduction to Programming
Function Overloading.
Guidelines for Writing Functions
Programming Language C Language.
Inline Functions.
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
Lecture 8.
Data in a C++ Program Numeric data and character data
Presentation transcript:

Default Arguments

void blanklines (const short num_lines = 4);   int main() { blanklines(8);    blanklines(33);   blanklines();  return 0; } void blanklines (const short num_lines)  {     for (short i = 1; i <= num_lines; i++)         cout<<endl;     return; }    

void blanklines (const short num_lines = 4);   int main() { blanklines(8);    blanklines(33);   blanklines();  return 0; } void blanklines (const short num_lines)  {     for (short i = 1; i <= num_lines; i++)         cout<<endl;     return; }    

void blanklines (const short num_lines = 4);   int main() { blanklines(8);    blanklines(33);   blanklines();  return 0; } void blanklines (const short num_lines)  {     for (short i = 1; i <= num_lines; i++)         cout<<endl;     return; }    

void blanklines (const short num_lines = 4);   int main() { blanklines(8);    blanklines(33);   blanklines();  return 0; } void blanklines (const short num_lines)  {     for (short i = 1; i <= num_lines; i++)         cout<<endl;     return; }    

void blanklines (const short num_lines = 4);   int main() { blanklines(8);    blanklines(33);   blanklines();  return 0; } void blanklines (const short num_lines)  {     for (short i = 1; i <= num_lines; i++)         cout<<endl;     return; }    

void blanklines (const short num_lines = 4);   int main() { blanklines(8);    blanklines(33);   blanklines();  return 0; } void blanklines (const short num_lines)  {     for (short i = 1; i <= num_lines; i++)         cout<<endl;     return; }    

void my_function (int a=6, char b=‘a’, float c=8 void my_function (int a=6, char b=‘a’, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b=‘a’, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b, float c, long d=11, double e=22.5); void my_function (int a, char b, float c, long d, double e=22.5); void my_function (int a, char b, float c, long d, double e); void my_function (int a, char b=‘a’, float c, long d, double e);

void my_function (int a=6, char b=‘a’, float c=8 void my_function (int a=6, char b=‘a’, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b=‘a’, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b, float c, long d=11, double e=22.5); void my_function (int a, char b, float c, long d, double e=22.5); void my_function (int a, char b, float c, long d, double e); void my_function (int a, char b=‘a’, float c, long d, double e);

void my_function (int a=6, char b=‘a’, float c=8 void my_function (int a=6, char b=‘a’, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b=‘a’, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b, float c=8.9, long d=11, double e=22.5); void my_function (int a, char b, float c, long d=11, double e=22.5); void my_function (int a, char b, float c, long d, double e=22.5); void my_function (int a, char b, float c, long d, double e); void my_function (int a, char b=‘a’, float c, long d, double e);

void my_function (int a, char b, float c = 1 void my_function (int a, char b, float c = 1.2, long d = 4, double e = 7.8) {…} int main() { my_function (4,’z’,5.5,6,88.98); my_function (4,’z’,3.5,7); my_funciton (3,’g’); return 0; }

void my_function (int a, char b, float c = 1 void my_function (int a, char b, float c = 1.2, long d = 4, double e = 7.8) {…} int main() { my_function (4,’z’,5.5,6,88.98); my_function (4,’z’,3.5,7); my_funciton (3,’g’); return 0; }

void my_function (int a, char b, float c = 1 void my_function (int a, char b, float c = 1.2, long d = 4, double e = 7.8) {…} int main() { my_function (4,’z’,5.5,6,88.98); my_function (4,’z’,3.5,7); my_funciton (3,’g’); return 0; }

End of Session