More About FunctionsObjectivesIn this lesson, you will learn to: Use in-built functions in a program Handle command line p...
More About FunctionsIn-Built Functions C++ provides predefined functions to manipulate  string and numeric data Some of th...
More About FunctionsIn-Built Functions (Contd..)     strncpy- Copies the specified number of characters      of the second...
More About FunctionsIn-Built Functions (Contd..)     strstr- Scans string1 for the first occurrence of      string2. The s...
More About FunctionsIn-Built Functions (Contd..)        The syntax is as follows:        Char * strstr (char * string1, ch...
More About FunctionsIn-Built Functions (Contd..) Some of the in-built numeric functions are:     abs- Returns absolute val...
More About FunctionsIn-Built Functions (Contd..)     floor- Returns the largest integer that is less than      or equal to...
More About FunctionsIn-Built Functions (Contd..)     atoi- Returns the integer value stored as a string.      The syntax i...
More About FunctionsCommand Line Parameters Command line parameters are the values are passed  from the command prompt to ...
More About FunctionsDeclaration of Functions The syntax to declare a function is as follows:  void main(int argc, char *ar...
More About Functions  Problem Statement 6.D.1  Write a program, which accepts five numbers from  command line and display ...
More About FunctionsJust a Minute… int argc gives ________________ char *argv[] gives ________________.©NIIT              ...
More About Functions  Problem Statement 6.P.1  Modify the existing empsalary module of Diaz  Telecommunication Inc. to inc...
More About FunctionsPointer to Function Function pointers are pointers, i.e. variables, which  point to the address of a f...
More About FunctionsSummaryIn this lesson, you learned that: C++ provides several in-built functions. Some of the commonly...
More About FunctionsSummary (Contd..) Some of the commonly used numeric functions are:    floor    ceil    abs    Sqrt Com...
Upcoming SlideShare
Loading in …5
×

Aae oop xp_06

891 views

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
891
On SlideShare
0
From Embeds
0
Number of Embeds
91
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Aae oop xp_06

  1. 1. More About FunctionsObjectivesIn this lesson, you will learn to: Use in-built functions in a program Handle command line parameter in a program Handle pointer to functions©NIIT OOPS/Lesson 6/Slide 1 of 16
  2. 2. More About FunctionsIn-Built Functions C++ provides predefined functions to manipulate string and numeric data Some of the in-built string functions are: strcpy- copies the contents of the second string to the first string. The syntax is as follows: char * strcpy ( char * dest, const char * src ); For example, strcpy(cStr1,“Judas Priest”); strcat- is used to join (concatenate) the second string with the first string. The syntax is as follows: char * strcat ( char * dest, const char * src ); For example, strcat(cStr1, “ABC”);©NIIT OOPS/Lesson 6/Slide 2 of 16
  3. 3. More About FunctionsIn-Built Functions (Contd..) strncpy- Copies the specified number of characters of the second string to the first string. The syntax is as follows: char * strncpy ( char * dest, const char * src, sizet_t num ); For example, strcpy(cStr1,“Judas Priest”,5); strlen- Returns the length for the string. The syntax is as follows: size_t strlen ( const char * str1 ); For example, iNum=strlen(cStr1);©NIIT OOPS/Lesson 6/Slide 3 of 16
  4. 4. More About FunctionsIn-Built Functions (Contd..) strstr- Scans string1 for the first occurrence of string2. The syntax is as follows: Char * strstr (char * string1, const char * string2 ); For example, char str1[]=”Hello World”; char str2[]=”or”; char * sFound=strstr(str1,str2); coutsFound-str1+1; strcmp- compares two strings (supplied as its parameters) and returns an integer value.©NIIT OOPS/Lesson 6/Slide 4 of 16
  5. 5. More About FunctionsIn-Built Functions (Contd..) The syntax is as follows: Char * strstr (char * string1, char * string2 ); For example, iNum=strcmp(“madonna”,”maradona”); strchr- Searches for a character in a string. The syntax is as follows: char * strchr ( const char * string, int c ); For example, ptr = strchr( s, 0 );©NIIT OOPS/Lesson 6/Slide 5 of 16
  6. 6. More About FunctionsIn-Built Functions (Contd..) Some of the in-built numeric functions are: abs- Returns absolute value of the integer parameter. The syntax is as follows: int abs ( int n ); For example, abs(-2) ceil- Rounds up the parameter to the nearest integer value. The syntax is as follows: int ceil ( int n ); For example, ceil(1.4)©NIIT OOPS/Lesson 6/Slide 6 of 16
  7. 7. More About FunctionsIn-Built Functions (Contd..) floor- Returns the largest integer that is less than or equal to the integer passed as a parameter. The syntax is as follows: double floor ( double x ); For example, floor(1.8) sqrt- Returns the square root of parameter. The syntax is as follows: double sqrt ( double x ); For example, param = 1024.0; result = sqrt (param);©NIIT OOPS/Lesson 6/Slide 7 of 16
  8. 8. More About FunctionsIn-Built Functions (Contd..) atoi- Returns the integer value stored as a string. The syntax is as follows: int atoi (const char * string) For example, char str[]=”345A”; result=atoi(str);©NIIT OOPS/Lesson 6/Slide 8 of 16
  9. 9. More About FunctionsCommand Line Parameters Command line parameters are the values are passed from the command prompt to the program during program execution. The two parameters of the C++ main() function that interpret the values are: argc argv©NIIT OOPS/Lesson 6/Slide 9 of 16
  10. 10. More About FunctionsDeclaration of Functions The syntax to declare a function is as follows: void main(int argc, char *argv[]) { }©NIIT OOPS/Lesson 6/Slide 10 of 16
  11. 11. More About Functions Problem Statement 6.D.1 Write a program, which accepts five numbers from command line and display it.©NIIT OOPS/Lesson 6/Slide 11 of 16
  12. 12. More About FunctionsJust a Minute… int argc gives ________________ char *argv[] gives ________________.©NIIT OOPS/Lesson 6/Slide 12 of 16
  13. 13. More About Functions Problem Statement 6.P.1 Modify the existing empsalary module of Diaz Telecommunication Inc. to increment the salary of their employees. Increment amount need to be passed from command line.©NIIT OOPS/Lesson 6/Slide 13 of 16
  14. 14. More About FunctionsPointer to Function Function pointers are pointers, i.e. variables, which point to the address of a function. The addresses that the function pointers contain reside in the code segment itself The syntax to declare to declare a function pointer is as follows: [return_type] (*pointer_name)[(list_of_parameters)] A pointer to a function can be initialized with the name of a function, within the declaration of the pointer. For example, long max(const long* array,int cnt); pFun=max;©NIIT OOPS/Lesson 6/Slide 14 of 16
  15. 15. More About FunctionsSummaryIn this lesson, you learned that: C++ provides several in-built functions. Some of the commonly used string functions are: strcpy strcat strncpy strlen strstr strcmp strchr©NIIT OOPS/Lesson 6/Slide 15 of 16
  16. 16. More About FunctionsSummary (Contd..) Some of the commonly used numeric functions are: floor ceil abs Sqrt Command line parameters add functionality to your programs by allowing you to pass parameters with your C++ program. Function pointers are pointers, i.e. variables, which point to the address of a function.©NIIT OOPS/Lesson 6/Slide 16 of 16

×