Download presentation
Presentation is loading. Please wait.
Published byBryce Poole Modified over 9 years ago
1
You gotta be cool
2
C++ ? C++ Standard Library Header Files Inline Functions References and Reference Parameters Default Arguments and Empty Parameter Lists Unary Scope Resolution Operator Function Overloading Function Templates C++ as a better C
3
Improves many of C features C is structured vs. C++ is Object Oriented (increasing software productivity, quality and reusability) The increment operator (++) indicates that C++ is an enhancement of C C++ is a superset of C, therefore C++ compiler can also compile existing C programs Why C++
4
Can someone in this class be a “lady” or a “gentleman”? Help me here… Come in front and code a simple C program that adds up 2 numbers Shouldn’t be a problem right? Y’all have learned this in Programming I… kehkehkeh…..evil laugh :D Why C++
5
Simple program that you already know with C
6
……and same results with C++
8
- header files from standard library. To tell C++ preprocessor to include the contents of the input/ output stream header file iostream. cout and the << operator – standard output stream, using namespace std (will be discussed in later chapters) cin and the << operator – standard input stream, using namespace std (will be discussed in later chapters) std::endl – stream manipulator abbreviated from “end line” – outputs a new line and flushes the output buffer New things you need to know
9
Comparison
10
Standard Library Revisited **Homework: find out what all these header files do. **Terms and Condition applied
11
Remember that when you use the function from iostream, you have to keep the std:: over and over again? The using statement
12
Use the using statement, we can eliminate the repetition of std:: in every statement The using statement And of course you can shorten this too, where you eliminate the use of variable sum
13
In C, functions are good form a software engineering standpoint. However, function calls involve execution-time overhead. C++ provides inline functions to help reduce function-call overhead – especially for small functions. The qualifier inline before the function’s return type in the function definition “advises” the computer to generate a copy of the function’s code in place to avoid a function call. Trade off? Multiple copies of function code makes the program larger. inline qualifier is good for small functions only. Inline functions
15
Keywords common in C and C++ autobreakcasecharconst continuedefaultdodoubleelse enumexternfloatforgoto ifintlongregisterreturn shortsignedsizeofstaticstruct switchtypedefunionunsignedvoid volatilewhile
16
Keywords only in C++ asmboolcatchclassconst_cast deletedynamic_castexplicitfalsefriend inlinemutablenamespacenewoperator privateprotectedpublicreinterpret_caststatic_cast templatethisthrowtruetry typeidtypenameusingvirtual
17
Previously, you have learnt functions in 2 operations: call-by-value and call-by-reference, right? But do you know that there are 2 techniques for call-by-reference? Can someone demonstrate call-by-reference technique that you have learned in Programming I? Com’on!!!!! References and Reference Parameters
18
The other technique: Reference Parameters
20
$ can also be used as an alias for one other variable. However the alias must represent an existing variable and is only dedicated to that variable only for as long as the program is executed. Or else syntax error will occur.
21
Default Arguments and Empty Parameter Lists Default Arguments Empty Parameter Lists
22
Unary Scope Resolution Operator Global Variable Local Variable
23
Function Overloading First Variation Second Variation Third Variation
24
Overloaded functions are used to perform similar operations that involve different program logic on different data types However, if the program logic and operations are identical for each data type, function templates is more suitable C++ generates separate template function derived from a single function template definition, to handle each type of call appropriately Function Template
25
Each function template definitions begin with keyword template followed by a list of formal type parameters to the function template enclosed in angle brackets ( ) Then every formal type parameter is preceded by either keyword typename or class Function Template
28
Write a C++ program that calculates area for rectangles Use overloading functions with 2 varieties: one accepts 2 integers for height and width. The other accepts 2 floats for height and width Do not use any return value or pointers for either overloaded functions. Let’s try this ….just for fun
29
So you guys and gals understand?
30
Good….. Quiz 1 NOW!!!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.