Presentation is loading. Please wait.

Presentation is loading. Please wait.

1.2 Function and Class Names

Similar presentations


Presentation on theme: "1.2 Function and Class Names"— Presentation transcript:

1 1.2 Function and Class Names
A First Book of C++ 1.2 Function and Class Names

2 Function and Class Names
Modular programs Segments arranged in logical order to form an integrated unit Module Segments of modular program Function: Name of a C++ procedure Composed of sequence of C++ instructions Function interface is its inputs and results Method of converting input to results is encapsulated and hidden within function A First Book of C++ 4th Edition

3 Function and Class Names (cont'd.)
A First Book of C++ 4th Edition

4 Function and Class Names (cont'd.)
A First Book of C++ 4th Edition

5 Function and Class Names (cont'd.)
Identifiers Names that convey an idea of the purpose of function or class Identifier composition rules First character must be a letter or underscore Only letter, digit, or underscore may follow Blank spaces aren’t allowed Identify component words with initial capitalization Cannot be C++ keyword Should be a mnemonic A First Book of C++ 4th Edition

6 Function and Class Names (cont'd.)
A First Book of C++ 4th Edition

7 Function and Class Names (cont'd.)
Examples of valid identifiers: grosspay taxCalc addNums degToRad multByTwo salesTax netPay bessel A First Book of C++ 4th Edition

8 Function and Class Names (cont'd.)
Examples of invalid identifiers: 4ab3 (begins with a number) e*6 (contains a special character) while (is a keyword) A First Book of C++ 4th Edition

9 The main() Function Each C+ program must have one and only one function named main Called a driver function because it drives the other modules A First Book of C++ 4th Edition

10 The main() Function (cont'd.)
A First Book of C++ 4th Edition

11 The main() Function (cont'd.)
First line of function is called header line What type of data, if any, is returned from function The name of function What type of data, if any, is sent into function Data transmitted into function at runtime are referred to as arguments of function A First Book of C++ 4th Edition

12 The main() Function (cont'd.)
A First Book of C++ 4th Edition

13 For Now Basic Format Line 1 - // Your Name
Line // Page # and Problem # Line // Date Assigned Line int main() Line { Line 6 - ? - Indicating "The program begins here" and the last two lines are: Line 998 – return 0; Line } A First Book of C++ 4th Edition


Download ppt "1.2 Function and Class Names"

Similar presentations


Ads by Google