object oriented lecture notes, Assignments of C programming

c programming features lecture notes

Typology: Assignments

2020/2021

Uploaded on 05/18/2021

vinodkumard
vinodkumard 🇮🇳

5 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Silent Features of C++ Program :
C++ is quite similar to C programming. In fact, C++ supports all the features offered with C with
the addition to various other important features like object-oriented programming, operator
overloading, exception and error handling, the namespace feature, and many more.
Here are some of the remarkable features of C++ language:
1. OOP (Object-Oriented Programming)
C++ is an object-oriented language, unlike C which is a procedural language. This is one of the
most important features of C++. It employs the use of objects while programming. These
objects help you implement real-time problems based on data abstraction, data encapsulation,
data hiding, and polymorphism. We have briefly discussed all the 5 main concepts of object-
oriented programming.
The OOP concepts are:
Data abstraction: Data abstraction is an act of representing the important features of
data without including the background details or the method applied to obtain it.
Data encapsulation: Data encapsulation is nothing but a process to implement data
abstraction by wrapping up the data and functions into an exclusive block.
Inheritance: The term inheritance refers to transferring the properties of the parent
class to the child class. We can implement the basic idea of inheritance by creating more
than one class, which we formally refer to as derived classes by linking them with what we
call the base class. This concept reduces the redundancy of the program and makes it easy
to transfer/copy the properties of one class to another
Data hiding: Data hiding refers to protecting data from unauthorized access. It is
basically responsible for securing the data. It is important to note that data encapsulation
is different from data hiding as encapsulation mainly focuses on shifting the focus on
important data than explaining its complex nature.
Polymorphism: The word poly means ‘many’ and morphism means ‘forms’. Clearly,
polymorphism refers to displaying that data in more than one form.
2. Platform or Machine Independent/ Portable
Although C++ is not platform-independent as compiled programs on one operating system
won’t run on another operating system
But in another term, portability refers to using the same piece of code in varied environments.
Let us understand this C++ feature with the help of an example. Suppose you write a piece of
code to find the name, age, and salary of an employee in Microsoft Windows and for some
apparent reason you want to switch your operating system to LINUX. This code will work in a
similar fashion as it did in Windows.
pf3
pf4
pf5

Partial preview of the text

Download object oriented lecture notes and more Assignments C programming in PDF only on Docsity!

Silent Features of C++ Program : C++ is quite similar to C programming. In fact, C++ supports all the features offered with C with the addition to various other important features like object-oriented programming, operator overloading, exception and error handling, the namespace feature, and many more. Here are some of the remarkable features of C++ language:

1. OOP (Object-Oriented Programming) C++ is an object-oriented language , unlike C which is a procedural language. This is one of the most important features of C++. It employs the use of objects while programming. These objects help you implement real-time problems based on data abstraction, data encapsulation, data hiding, and polymorphism. We have briefly discussed all the 5 main concepts of object- oriented programming. The OOP concepts are:  Data abstraction: Data abstraction is an act of representing the important features of data without including the background details or the method applied to obtain it.  Data encapsulation: Data encapsulation is nothing but a process to implement data abstraction by wrapping up the data and functions into an exclusive block.  Inheritance: The term inheritance refers to transferring the properties of the parent class to the child class. We can implement the basic idea of inheritance by creating more than one class, which we formally refer to as derived classes by linking them with what we call the base class. This concept reduces the redundancy of the program and makes it easy to transfer/copy the properties of one class to another  Data hiding: Data hiding refers to protecting data from unauthorized access. It is basically responsible for securing the data. It is important to note that data encapsulation is different from data hiding as encapsulation mainly focuses on shifting the focus on important data than explaining its complex nature.  Polymorphism: The word poly means ‘many’ and morphism means ‘forms’. Clearly, polymorphism refers to displaying that data in more than one form. 2. Platform or Machine Independent/ Portable Although C++ is not platform-independent as compiled programs on one operating system won’t run on another operating system But in another term, portability refers to using the same piece of code in varied environments. Let us understand this C++ feature with the help of an example. Suppose you write a piece of code to find the name, age, and salary of an employee in Microsoft Windows and for some apparent reason you want to switch your operating system to LINUX. This code will work in a similar fashion as it did in Windows.

3. Simple When we start off with a new language, we expect to understand in-depth. The simple context of C++ gives an appeal to programmers, who are eager to learn a new programming language. If you are already familiar with C, then you don’t need to worry about facing any trouble while working in C++. The syntax of C++ is almost similar to that of C. Afterall C++ is referred to as “C with classes”. 4. High-level programming language It is important to note that C++ is a high-level programming language, unlike C which is a mid- level programming language. It makes it easier for the user to work in C++ as a high-level language as we can closely associate it with the human-comprehensible language, that is, English. 5. Popular After learning C, it is the base language for many other popular programming languages which supports the feature of object-oriented programming. Bjarne Stroustrup found Simula 67, the first object-oriented language ever, lacking simulations and decided to develop C++. 6. Case sensitive Just like C, it is pretty clear that the C++ programming language treats the uppercase and lowercase characters in a different manner. For instance, the meaning of the keyword ‘cout’ changes if we write it as ‘Cout’ or “COUT”. Other programming languages like HTML and MySQL are not case sensitive. 7. Compiler-Based Unlike Java and Python that are interpreter-based, C++ is a compiler-based language and hence it a relatively much faster than Python and Java. 8. DMA (Dynamic Memory Allocation) Since C++ supports the use of pointers, it allows us to allocate memory dynamically. We may even use constructors and destructors while working with classes and objects in C++. 9. Existence of Libraries The C++ programming language offers a library full of in-built functions that make things easy for the programmer. These functions can be accessed by including suitable header files. 10. Speed As discussed earlier, C++ is compiler-based hence it is much faster than other programming languages like Python and Java that are interpreter-based.

Example: #include Definition Preprocessor :- This the section where we define all our symbolic constant we gonna use in our program. Example: #define PI 3. #define TRUE 1 Global Declarations :- This is the section where all the global declaration comes. All of the variables, structures, classed and function defined or declared outside the main function are treated as global. Class Definition :- The classes are used to map real world entities into programming. The Classes are the key building block of any C++ program. A C++ program may include several class definitions. This is the section where we define all of our classes. Main Method Definition :- This is the most vital part of each and every C++ program, it is mandatory for C++ program to have a main() method definition. There can be only one main() method in C++ program. The execution of a C++ program starts with the main() method. The C+

  • program can not be executed without the main() method. The main() method is responsible for the execution of all the user defined statement, functions and library functions. The main() method further structured into – variable declaration, function declaration and user defined executable statements. User defined functions :- This is the section of where we put all the user defined functions created to perform a specific task. A user defined function must be defined before use it. User defined function can written before or immediately after the main ( ) function and called inside the main ( ) function. Sample C++ Programs :

Execution of a C++ Program: Errors: