C++ 2
Upcoming SlideShare
Loading in...5
×
 

C++ 2

on

  • 166 views

 

Statistics

Views

Total Views
166
Views on SlideShare
166
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

C++ 2 C++ 2 Presentation Transcript

  • FUNCTION IN C++ GUIDED BYPREPARED BY MR.MITESH JAISWALAKSHAY JANI(116380307521) LCTURER INKAUSHAL SONI PIET(DS) 2ND SHIFT(116380307509)
  •  WE ARE IMMENSLY GREATFUL TO OUR LECTURER AND PROJECT GUIDE, MR.MITESH JAISWAL, FOR HER INVALUABLE GUIDANCE WHICH GAVE US A DEEP INSIGHT ON THE SUBJECT. WITH HER KEEN INTEREST AND CONSTANT MORAL BOOSTING, WE ARE ABLE TO IMPLEMENT THE PROJECT SATISFACTORILY. WE EXPRESS OUR VERY SINCERE THANKS TO COMPUTER ENGINEERING DEPT. FOR PROVIDING ADEQUATE FACILITIES TO COMPLETE OUR PROJECT. WE ARE AGAIN CORDIALLY THANKFUL TO OUR C&E DEPARTMENT STAFF, FRIENDS AND OTHER PEOPLE WHO HAVE DIRECTLY OR INDIRECTLY HELPED US IN COMPLETION OF THIS PROJECT. LAST BUT NOT THE LEAST, WE ARE ALSO THANKFUL TO OUR FAMILY MEMBERS WHO ENGOURAGED AND SUPPORTED US ROUND THE CLOCK FOR THIS PROJECT. Akshay Jani Kaushal Soni
  • CERTIFICATEThis is to certify that AKSHAY JANI Student of computerEngineering, bearing Enrollment No: 116380307521 have satisfactorilycompleted his/her Seminar work as a part of course curriculum inDiploma Engineering semester III having a report title “ FUNCTIONS INC++ ”. MR.MITESH JAISWAL Lecturer, computer Dept. PIETDS-2nd Shift, Limda. PARUL INSTITUTE OF ENGINEERING & TECHNOLOGY COMPUTER ENGG. DEPARTMENT LIMDA, VAGHODIA, VADODARA
  • This is to certify that KAUSHAL SONI Student of computerEngineering, bearing Enrollment No: 116380307509 have satisfactorilycompleted his/her Seminar work as a part of course curriculum inDiploma Engineering semester III having a report title “ FUNCTIONS INC++ ”. MR.MITESH JAISWAL Lecturer, computer Dept. PIETDS-2nd Shift, Limda. PARUL INSTITUTE OF ENGINEERING & TECHNOLOGY COMPUTER ENGG. DEPARTMENT LIMDA, VAGHODIA, VADODARA
  • FUNCTIONS IN C++ Experience has shown that the best way to develop and maintain large programs is to construct it from smaller pieces(Modules) This technique Called “Divide and Conquer” Bad Development Approach Wise Development Approach main() main() •Easer To { { ----- ----- Design ---- ----- Build } ----- Debug ----- Extend function f1() . Modify { . Understand --- . Reuse --- ---- Better Organization } ----- ----- function f2() Return 0; { } --- --- }
  • FUNCTIONS IN C++(CONT.) In FORTRAN Modules Known as Subprograms In Pascal Modules known as Procedures & Functions In C++ Modules Known as Functions & Classes Programs use new and “prepackaged” modules  New: programmer-defined functions and classes  Prepackaged: from the standard library
  • ABOUT FUNCTIONS IN C++  Functions invoked by a function–call-statement which consist of it’s name and information it needs (arguments)  Boss To Worker Analogy  A Boss (the calling/caller function) asks a worker (the called function) to perform a task and return result when it is done. Boss Main WorkerWorker Worker Function ZFunction A Function B Worker Worker Note: usual main( ) Calls other Function B1 Function B2 functions, but other functions can call each other
  • ADVANTAGES OF USING FUNCTIONS1. To help make the program more understandable2. To modularize the tasks of the program  building blocks of the program3. Write a module once  those lines of source code are called multiple times in the program 8
  • ADVANTAGES OF USING FUNCTIONS4. While working on one function, you can focus on just that part of the program  construct it,  debug it,  perfect it.5. Different people can work on different functions simultaneously.6. If a function is needed in more than one place in a program, or in different programs, you can write it once and use it many times 9
  • FUNCTION OVERLOADING Function overloading  Functions with same name and different parameters  Should perform similar tasks  I.e., function to square ints and function to square floats int square( int x) {return x * x;} float square(float x) { return x * x; } A call-time c++ complier selects the proper function by examining the number, type and order of the parameters
  • USING DEFAULT ARGUMENTS When you don’t provide enough arguments in a function call, you usually want the compiler to issue a warning message for this error Sometimes it is useful to create a function that supplies a default value for any missing parameters 11
  • USING DEFAULT ARGUMENTS Two rules apply to default parameters:  If you assign a default value to any variable in a function prototype’s parameter list, then all parameters to the right of that variable also must have default values  If you omit any argument when you call a function that has default parameters, then you also must leave out all arguments to the right of that argument 12
  • EXAMPLES OF LEGAL AND ILLEGALUSE OF FUNCTIONS WITH DEFAULTPARAMETERS 13
  • OVERLOADING FUNCTIONS In most computer programming languages, each variable used in a function must have only one name, but C++ allows you to employ an alias Similarly, in most computer programming languages, each function used in a program must have a unique name You don’t have to use three names for functions that perform basically the same task, C++ allows you to reuse, or overload, function names 14
  • OVERLOADING FUNCTIONS When you overload a function, you must ensure that the compiler can tell which function to call When the compiler cannot tell which version of a function to use, you have created ambiguity 15
  • THREE OVERLOADED FUNCTIONSTHAT PERFORM SIMILAR TASKS 16
  • POSTSCRIPT "The important thing is not to stop questioning; never lose a holy curiosity." -- Albert Einstein