Introduction to C programming Recap session 1 Structure

  • Slides: 20
Download presentation
Introduction to C++ programming • • Recap- session 1 Structure of C++ program Keywords

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

Introduction to C++ programming #includes base-class declarations derived-class declarations non-member function prototypes int main()

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

Introduction to C++ programming: key words • • • class case friend char public

Introduction to C++ programming: key words • • • class case friend char public enum else int unsigned protected struct false float using static default true long namespace this const inline double private new Listed few, there are 60+ key words supported by C++ What is the significance of the number of operators?

Introduction to C++ programming: Operators • All ‘c’ operators are valid in C++ •

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

Introduction to C++ programming: Data Types • Data Types – User defined • structure

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

Introduction to C++ programming: Data Types • Derived • array • function • pointer

Introduction to C++ programming: Data Types • Derived • array • function • pointer Type Size(bytes) char 1 int 2 long int 4 float 4 double 8 long double 10 boolean true/false (1/0) string Variable length

Introduction to C++ programming: classes and objects • Define – A class Defines structure

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/shop. Keeper •

Introduction to C++ programming: objects • object – Instance of a class – It

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

Introduction to C++ programming: C++ supports c-style • Organizing the program into functions Example

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

Introduction to C++ programming: class general syntax Classes are created by using “class ”

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

Introduction to C++ programming: constructors C++ allows objects to initialize themselves when they are

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

Introduction to C++ programming Examples: 1. c-style program (functions) 2. Reading and writing to

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: 1 D and 2 D 11. Object Array 12. Assignment

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax

Introduction to C++ programming: class general syntax