Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.

Similar presentations


Presentation on theme: "Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and."— Presentation transcript:

1 Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and objects Constructors Adding functions to class

2 Introduction to C++ programming #includes base-class declarations derived-class declarations non-member function prototypes int main() { // code } non-member function definitions

3 Introduction to C++ programming: key words classenumstructdefaultconst caseelsefalsetrueinline friendintfloatlongdouble charunsignedusingnamespaceprivate publicprotectedstaticthisnew Listed few, there are 60+ key words supported by C++ What is the significance of the number of operators?

4 Introduction to C++ programming: Operators All ‘c’ operators are valid in C++ C++ introduces some new operators – :: Scope resolution operator – ::* pointer-to-member declarator – ->* pointer to member operator –.* pointer to member operator – delete memory release operator – endl Line feed operator – new Memory allocation operator Note: these operators will be discussed with suitable example in later part of programming

5 Introduction to C++ programming: Data Types Data Types – User defined structure union class enumeration – Built-in/primitive void integral type – int, char floating type – float – double

6 Introduction to C++ programming: Data Types Derived array function pointer TypeSize(bytes) char1 int2 long int4 float4 double8 long double10 booleantrue/false (1/0) stringVariable length

7 Introduction to C++ programming: classes and objects Define – A class Defines structure of the objects Defines a new type Defines abstract data type, that can be treated like any other built-in data type. It is a basic unit of C++ program, it binds data and the functions which operate on that data and it provides ENCAPSULATION service. Logical construct Ex: Florist/shopKeeper

8 Introduction to C++ programming: objects object – Instance of a class – It is a physical reality – Ex: Flora

9 Introduction to C++ programming: C++ supports c-style Organizing the program into functions Example #include using namespace std; // discuss namespace concepts example int AddNums(int a, int b); int main() { int result; result= addNums(10,20); cout << “result=” << result; } int AddNums(int a, int b) { return a+b; }

10 Introduction to C++ programming: class general syntax Classes are created by using “class ” keyword class class_name {//access specifier: private, protected, public private : data and functions public: data functions } object_list; Default: private data and functions.

11 Introduction to C++ programming: constructors C++ allows objects to initialize themselves when they are created. The automatic initialization is performed using constructor functions Constructor types: default constructor: initializes data members to default values Parameterized constructors: initializes data members to parameters passed to constructor functions example

12 Introduction to C++ programming Examples: 1.c-style program (functions) 2.Reading and writing to the console: cout and cin 1.Read two numbers from the console and display the sum 3.Program to illustrate boolean data type 4.Program to illustrate string data type 5.Program without constructor and with constructor 6.Adding methods to class 7.Passing objects to functions 8.Returning objects from functions 9.Object assignments 10.Array: 1D and 2D 11.Object Array 12.Assignment

13 Introduction to C++ programming: class general syntax

14

15

16

17

18

19

20


Download ppt "Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and."

Similar presentations


Ads by Google