Presentation is loading. Please wait.

Presentation is loading. Please wait.

Types of Computer Languages

Similar presentations


Presentation on theme: "Types of Computer Languages"— Presentation transcript:

1 Types of Computer Languages
Procedural BASIC, FORTRAN, PASCAL Functional C,C++ Object Oriented C++, C#,JAVA

2 Object Oriented Programming
An object is an entity that store its own data and its own function. The data is termed as attributes or characteristic and behavior is termed as function. Example: if we consider “monitor” as an object. Then its size, color, manufacturer are attributes and when you switch on it display some information is its behavior. The fundamental idea behind OOP is to combine data and function(s) operating on that data into single unit.

3 Class vs struct Class is a keyword like struct used to define a user-defined data type. The data type is then further used to define a variable (object). So, a class defines the structure of an object A class is like a struct with following differences: All members declared in struct are global or public by default while in class are private by default.

4 Classes are stored in memory via heap whereas structs are stored in memory via stack.
Class can extend another class while a structures cannot extend anything. Structure members cannot be declared as Protected while class members can be. Constructors and Destructors can be defined in classes while in struct it cannot.

5 Access Level of Classes
There are three types of access level of members of a class: Private:    The members are accessible only by the member functions or friend functions. Protected:    These members are accessible by the member functions of the class and the classes which are derived from this class. Public:    Accessible by any external member or function. 5

6 Syntax of defining a Class
Example: class record { Private: float marks; Protected: char name[10]; int RollNo; Public: Void dataentry(); Void datadisp(); } student; Syntax: class class_name { access specifier: (private, protected, public) member(s); function(s) access specifier: function(s); } object_names; 6

7 Defining function Scope operator
Define and declare inside the class. Class record { char name[10]; public: void Entry() cout<<“Enter student Name”; cin>>name; } }; Declare inside and define outside the class class record { char name[10]; public: void Entry(); }; Void record:: Entry() cout<<“Enter student Name”; cin>>name; } Scope operator 7

8 Defining an object and Accessing Members of a class with (.) operator
class record { char name[10]; public: void Entry(); }; Void record:: Entry() cout<<“Enter student Name”; cin>>name; } main() { record student; student.Entry(); }

9 Defining an object and Accessing Members of a class with (->) operator
class record { char name[10]; public: void Entry(); }; Void record:: Entry() cout<<“Enter student Name”; cin>>name; } main() { record *student; student=new record; student->Entry(); }

10 Initializing data members of a class
Data members of a class can be initialized by: Functions Constructors class record { int x; public: void init_x(int a); x=a; } void disp() cout<<“The value of x=“<<x; }; Main() { record obj; obj.init_x(10); obj.disp(); }

11 Constructor Constructors are special member functions of a class used to initialize member data of a class. There can be any number of constructors inside a class, provided they have a different set of parameters. There are some important qualities for a constructor to be noted. Constructors have the same name as the class. Constructors do not return any values They are automatically executed when an object is created. 11

12 Destructor Destructors in C++ also have the same name, except for the fact that they are preceded by a '~' operator. The destructors are called to delete an object . It is not necessary to declare a constructor or a destructor inside a class. If not declared, the compiler will automatically create a default one for each. If the constructor/destructor is declared as private, then the class cannot be instantiated 12

13 Initializing data members of a class by constructor
class record { int x; public: record(int a); x=a; } void disp() cout<<“The value of x=“<<x; }; Main() { record obj(60); obj.disp(); }

14 main() { test a(20); a.disp(); test *b; b=new test(30); b->disp();
class test { int x; public: test(int in) x=in; cout<<" constructor is called and assign a value="<<x<<endl; } ~test() cout<<" destructor is called"<<endl; void disp() cout<<"The value is ="<<x<<endl; }; main() { test a(20); a.disp(); test *b; b=new test(30); b->disp(); delete b; system("pause"); } 14


Download ppt "Types of Computer Languages"

Similar presentations


Ads by Google