SlideShare ist ein Scribd-Unternehmen logo
1 von 16
More About Functions


Objectives
In 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
More About Functions


In-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
More About Functions


In-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
More About Functions


In-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
More About Functions


In-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
More About Functions


In-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
More About Functions


In-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
More About Functions


In-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
More About Functions


Command 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
More About Functions


Declaration 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
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
More About Functions


Just a Minute…
 int argc gives ________________
 char *argv[] gives ________________.




©NIIT                            OOPS/Lesson 6/Slide 12 of 16
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
More About Functions


Pointer 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
More About Functions

Summary
In 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
More About Functions

Summary (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

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
String functions in C
String functions in CString functions in C
String functions in C
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in C
 
Code generator
Code generatorCode generator
Code generator
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
 
Pointers
PointersPointers
Pointers
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
Lecture 2. mte 407
Lecture 2. mte 407Lecture 2. mte 407
Lecture 2. mte 407
 
C++ theory
C++ theoryC++ theory
C++ theory
 
Chapter 10 Library Function
Chapter 10 Library FunctionChapter 10 Library Function
Chapter 10 Library Function
 
NUMPY
NUMPY NUMPY
NUMPY
 
L6
L6L6
L6
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
string in C
string in Cstring in C
string in C
 
A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005
 

Andere mochten auch

Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09Niit Care
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20Niit Care
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16Niit Care
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13Niit Care
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01Niit Care
 
Shizuoka pref public_library(20101020)
Shizuoka pref public_library(20101020)Shizuoka pref public_library(20101020)
Shizuoka pref public_library(20101020)真 岡本
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10Niit Care
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04Niit Care
 
Mantenimiento de computo
Mantenimiento de computoMantenimiento de computo
Mantenimiento de computosebassevitas
 
simple present tense
simple present tensesimple present tense
simple present tensekarwinda
 
CacharreAndo
CacharreAndoCacharreAndo
CacharreAndoYcRF
 
Presentación1
Presentación1Presentación1
Presentación1pipe-alejo
 
Presentación del sistema genesis y portal institucional j a
Presentación del sistema genesis y portal institucional j aPresentación del sistema genesis y portal institucional j a
Presentación del sistema genesis y portal institucional j afelipegomezg
 
Idocaedro aplicacion
Idocaedro aplicacionIdocaedro aplicacion
Idocaedro aplicacionAnni Lovee
 

Andere mochten auch (20)

Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09
 
15 ooad uml-20
15 ooad uml-2015 ooad uml-20
15 ooad uml-20
 
Dacj 2-2 c
Dacj 2-2 cDacj 2-2 c
Dacj 2-2 c
 
Oops recap
Oops recapOops recap
Oops recap
 
11 ds and algorithm session_16
11 ds and algorithm session_1611 ds and algorithm session_16
11 ds and algorithm session_16
 
 
09 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_1309 iec t1_s1_oo_ps_session_13
09 iec t1_s1_oo_ps_session_13
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Rdbms xp 01
Rdbms xp 01Rdbms xp 01
Rdbms xp 01
 
Jdbc session01
Jdbc session01Jdbc session01
Jdbc session01
 
Shizuoka pref public_library(20101020)
Shizuoka pref public_library(20101020)Shizuoka pref public_library(20101020)
Shizuoka pref public_library(20101020)
 
07 asp.net session10
07 asp.net session1007 asp.net session10
07 asp.net session10
 
Presentación junio
Presentación junioPresentación junio
Presentación junio
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
Mantenimiento de computo
Mantenimiento de computoMantenimiento de computo
Mantenimiento de computo
 
simple present tense
simple present tensesimple present tense
simple present tense
 
CacharreAndo
CacharreAndoCacharreAndo
CacharreAndo
 
Presentación1
Presentación1Presentación1
Presentación1
 
Presentación del sistema genesis y portal institucional j a
Presentación del sistema genesis y portal institucional j aPresentación del sistema genesis y portal institucional j a
Presentación del sistema genesis y portal institucional j a
 
Idocaedro aplicacion
Idocaedro aplicacionIdocaedro aplicacion
Idocaedro aplicacion
 

Ähnlich wie Aae oop xp_06

C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introductionraghukatagall2
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2IIUM
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxfaithxdunce63732
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingMeghaj Mallick
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptxNelyJay
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework HelpC++ Homework Help
 

Ähnlich wie Aae oop xp_06 (20)

CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2Csc1100 lecture14 ch16_pt2
Csc1100 lecture14 ch16_pt2
 
cp05.pptx
cp05.pptxcp05.pptx
cp05.pptx
 
C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
 
See through C
See through CSee through C
See through C
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Lecture 9_Classes.pptx
Lecture 9_Classes.pptxLecture 9_Classes.pptx
Lecture 9_Classes.pptx
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Ocs752 unit 3
Ocs752   unit 3Ocs752   unit 3
Ocs752 unit 3
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Lecture5
Lecture5Lecture5
Lecture5
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 

Mehr von Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Kürzlich hochgeladen

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Kürzlich hochgeladen (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Aae oop xp_06

  • 1. More About Functions Objectives In 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. More About Functions In-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. More About Functions In-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. More About Functions In-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. More About Functions In-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. More About Functions In-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. More About Functions In-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. More About Functions In-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. More About Functions Command 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. More About Functions Declaration 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. 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. More About Functions Just a Minute… int argc gives ________________ char *argv[] gives ________________. ©NIIT OOPS/Lesson 6/Slide 12 of 16
  • 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. More About Functions Pointer 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. More About Functions Summary In 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. More About Functions Summary (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