




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Notes are for those students who feel problems to understand data structure
Typology: Exams
1 / 128
This page cannot be seen from the preview
Don't miss anything!





























































































By Bishwas Pokharel 068/bct/515(pulchowk campus)
1. Introduction to Object Oriented Programming 1.1 Issues with Procedure Oriented Programming Global variables are visible throughout the program and can be accessed by all function of program. So if any function uses the local variable with the same declaration as global variable then value of local variable is used in place of global variable throughout the function. If program length is long and by some dilemma value of global variable is changed then It is difficult to detect exact location where error takes place. #include
1.2/1.4 Basic features of Object Oriented Programming (Exam Point of view)
1. Class: Class is an interface to create an object. Class has functions and attributes bind together. Function defines the behavior of an object/s and attribute defines the property of an object/s which it holds .From single class any number of an object can be created. Ex class Car{ int weight; int height; string color; void start(){ cout<<"Start"<<endl; } void run(){ cout<<"Run"<<endl; } } Here, Class Car has attributes as weight, height, color and function as start () and run (). 2. Object: Object is a run time entity. Function and attributes comes into play only after creating an object. This refers that features are defined on class where access of these features are possible only after creating an object. Ex Car lamborghini, ferari; Here Lamborghini and ferari are objects of a class Car. You can use start and run function only after real manufacturing of lamborghini, ferari. Note: For easy visualization, compare class with drawing of a car. By using single drawing many car can be manufactured which represents an object in C++.
3. Data Hiding: Data Hiding is the process of hiding an information (data) from an unauthentic users. Information is provided only after the proper validation. If validation fails then information is not shown. Ex I. In ATM machine, people are able to access account information only after proper validation of pin number used for respective ATM card. If pin number goes wrong at the time of validation then information is secure. II. In Facebook, Gmail and others social sites, Password and ID entered must have to match with the previously stored Password and ID, resides in database to view Information. Advantages: It provides security. 4. Abstraction: Abstraction says the detail mechanism is not necessary, just basic knowledge of using system’s features is sufficient for proper utilization of system. Ex To use ATM machine people does not have to learn how ATM card is validated after entering into machine, which language is used to validate data, which databases either SQL or Oracle is implemented in bank to store data. Just basic knowledge of how to use ATM machine is sufficient to access account information. Here detail mechanism is hidden and only basic feature is provided and it’s called an abstraction. Advantages: It provides simplicity.
7. Polymorphism: Polymorphism refers to many forms. This means under different situation same thing can behave differently. We human being is best example of polymorphism. In university a person is a student, In home same person can be son/daughter of parent or husband/wife or father/mother of their child. According to location, relation changes for same person. In OOP, same concept applies in polymorphism. Function Overloading and Dynamic Binding is an example of polymorphism. Ex #include
1.3 Procedure oriented versus Object oriented programming
Divided Into In POP, program is divided into small parts In OOP, program is divided into parts called objects. called functions. Importance In POP, Importance is not given to data but to In OOP, Importance is given to the data rather than functions as well as sequence of actions to be procedures or functions because it works as a real done. world. Approach POP follows Top Down approach. OOP follows Bottom Up approach. Access POP does not have any access specifier. OOP has access specifiers named Public, Private, Specifiers Protected, etc. Data Moving In POP, Data can move freely from function to In OOP, objects can move and communicate with each function in the system. other through member functions. Expansion To add new data and function in POP is not so OOP provides an easy way to add new data and easy. function. Data Access In POP, Most function uses Global data for sharing In OOP, data can not move easily from function to that can be accessed freely from function to function,it can be kept public or private so we can function in the system. control the access of data. Data Hiding POP does not have any proper way for hiding data OOP provides Data Hiding so provides more security. so it is less secure. Overloading In POP, Overloading is not possible. In OOP, overloading is possible in the form of Function Overloading and Operator Overloading. Examples Example of POP are : C, VB, FORTRAN, Pascal. Example of OOP are : C++, JAVA, VB.NET, C#.NET.
Bishwas Pokharel(068/BCT/515) pulchowk camp
2.2 Features of C+ +
2.3 C+ + Versus C
2.1 The Need of C+ +
Bishwas Pokharel(068/BCT/515) pulchowk campus
3. C++ Language Constructs 3.1 General C++ Program Structure #include
3.2.2 Identifiers. An identifier is a sequence of characters used to denote one of the following: Object or variable name Class, structure, or union name Enumerated type name Member of a class, structure, union, or enumeration Function or class-member function typedef name Label name Macro name Macro parameter Rules for writing an identifier A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. The first letter of an identifier should be either a letter or an underscore. However, it is discouraged to start an identifier name with an underscore. There is no rule on length of an identifier. However, the first 31 characters of identifiers are discriminated by the compiler. Identifier must be unique. They are created to give unique name to a entity to identify it during the execution of the program. For example:
3.2.3 Constants/Literals A constant is a value or an identifier whose value cannot be altered in a program. For example: 1, 2.5, "C programming is easy", etc. As mentioned, an identifier also can be defined as a constant.
18 and 21 are literals. We can use these literals in all areas of our program. For example, if(age > 18) or if(age < 21). But we can make our code more understandable if we use constants instead. if(age > VOTING_AGE) is easier to understand. Other benefits of using constants are Constants free the programmer from having to remember what each literal should be. Often values that stay constant throughout the program have a business meaning. If there are several such values, the programmer can define them all in the beginning of the program and then work with the easier-to-remember constant names. If business requirements dictate that the constant be changed (for example, if the drinking age is lowered to 20 in the future), it is much easier to adapt the program. If we use literals throughout the program, the change will be hard to do and there is a good chance some instances will not be corrected. 3.2.4 Operators and Punctuators
convert 4 byte int into 4 byte **Rules:
3. Long: Long is used with all modifiers except short. i. Signed long long (8 byte) **ii. Unsigned long long(8 byte)