27.11.14

C++ Definition : object oriented programming

Write answer for the following questions in comments. Give answer in short. Example as source code is preferable with each answer.


How is OOP important in C++?

What is abstract class?

What is this Pointer ? What is its significance?

What is the difference between while and do-while loop?

Why main() function is important in C++?

What is type casting in C++?


What is OOP?

What is the type conversion in C++

What is the difference between local variable and global variable.

Show Inheritance with at least two derived class

Show Data Abstraction and data Encapsulation

Describe Polymorphism with Example

 

7 comments:

  1. Md. Imam Uddin
    CSE-46th Batch
    ID-201420733

    The prime purpose of C++ programming was to add object orientation to the C programming language, which is in itself one of the most powerful programming languages.

    The core of the pure object-oriented programming is to create an object, in code, that has certain properties and methods. While designing C++ modules, we try to see whole world in the form of objects. For example a car is an object which has certain properties such as color, number of doors, and the like. It also has certain methods such as accelerate, brake, and so on.

    There are a few principle concepts that form the foundation of object-oriented programming:
    Object:

    This is the basic unit of object oriented programming. That is both data and function that operate on data are bundled as a unit called as object.
    Class:

    When you define a class, you define a blueprint for an object. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.
    Abstraction:

    Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.

    For example, a database system hides certain details of how data is stored and created and maintained. Similar way, C++ classes provides different methods to the outside world without giving internal detail about those methods and data.
    Encapsulation:

    Encapsulation is placing the data and the functions that work on that data in the same place. While working with procedural languages, it is not always clear which functions work on which variables but object-oriented programming provides you framework to place the data and the relevant functions together in the same object.
    Inheritance:

    One of the most useful aspects of object-oriented programming is code reusability. As the name suggests Inheritance is the process of forming a new class from an existing class that is from the existing class called as base class, new class is formed called as derived class.

    This is a very important concept of object-oriented programming since this feature helps to reduce the code size.
    Polymorphism:

    The ability to use an operator or function in different ways in other words giving different meaning or functions to the operators or functions is called polymorphism. Poly refers to many. That is a single function or an operator functioning in many ways different upon the usage is called polymorphism.
    Overloading:

    The concept of overloading is also a branch of polymorphism. When the exiting operator or function is made to operate on new data type, it is said to be overloaded.

    ReplyDelete
  2. Md. Imam Uddin
    ID-201420733
    46th Batch

    2. What is abstract class?
    Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods. Let's look at an example of an abstract class, and an abstract method.

    ReplyDelete
  3. Md. Imam Uddin
    ID-201420733
    CSE 46th Batch

    What is the difference between while and do-while loop?

    While:
    1. entry control loop
    2. condition is checked before loop execution
    3. never execute loop if condition is false
    4. there is no semicolon at the end of while statement
    Do-while:
    1. exit control loop
    2. condition is checked at the end of loop
    3. executes false condition at least once since condition is checked later
    4. there is semicolon at the end of while statement.

    ReplyDelete
  4. Md. Imam Uddin
    ID-201420733
    CSE 46th B.

    5. Why main() function is important in C++?

    Because if you donot use main function in c program, the compiler willnot execute the program.C compiler starts execution from main function itself.

    ReplyDelete
  5. Md. Imam Uddin
    ID-201420733
    CSE 46th B.

    6. What is OOP?
    Programming paradigm that views a computer program as a combination of data structures (called objects) which can exchange information in a standardized manner, and can be combined with one another as modules or blocks. Each object is independent (can be changed without affecting other blocks), can run (execute) by itself, and can be interlocked with other objects. Objects interact by passing information among each other, and each object contains information about itself (a property called encapsulation) and the objects it can interact with (a property called Inheritance). Major OOP-oriented languages are C++, Java, and Smalltalk.

    ReplyDelete
  6. a sample program including Inheritance with two derived class is given below:
    #include
    using namespace std;

    class base
    {
    public:
    int z;
    };

    class s : public base
    {
    public:
    int s;
    };

    class t: public base
    {
    public:
    int t;
    };

    class A: public s, public t
    {
    public:
    int A;
    };
    int main()
    {
    A a;
    a.s::z = 8;
    a.t::z = 9;
    cout << a.s::z;
    cout << a.t::z;
    return 0;
    }

    ReplyDelete
  7. Batch-46th
    Id-201420406


    what is pointer?
    The this Pointer: When a function of a class is called by an object of that class, each variable gets an pointer which points to that calling object, meaning that this variable was called by that object or this variable is under that object. This pointer is called this pointer.

    What is abstract class?
    Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods


    What is the difference between while and do-while loop?
    While:
    1. entry control loop
    2. condition is checked before loop execution
    3. never execute loop if condition is false
    4. there is no semicolon at the end of while statement
    Do-while:
    1. exit control loop
    2. condition is checked at the end of loop
    3. executes false condition at least once since condition is checked later
    4. there is semicolon at the end of while statement.

    Why main() function is important in C++?
    ans: All C language programs must have a main() function. It's the core of every program. It's required. The main() function doesn't really have to do anything other than be present inside your C source code. Eventually, it contains instructions that tell the computer to carry out whatever task your program is designed to do. But it's not officially required to do anything.
    What is type casting in C++?
    ans: Type casting is making a variable of one type, such as an int, act like another type, a char, for one single operation. To typecast something, simply put the type of variable you want the actual variable to act as inside parentheses in front of the actual variable. (char)a will make 'a' function as a char.


    ReplyDelete

Comment Here