C++ OOPs concept with interview questions

C++ is a higher version of C language which has a feature of OOPs. - string constant, Numeric constant (Integer ,float ,unsigned, hex, OCT).

C++ OOPs concept with interview questions

Who to write C++ Codes?

  •    In the C++ we come across with the term" using namespace std".
  •    It is basically get used to define all the precast function in CPP environment explicitly.
  •    Iostream: The "iostream" is used to support both the input/output stream of functions to read a stream of character from the keyboard and used to display the output at console.
  •    cin>>:  It is used to provide the input to the program.
  •    Cout<<: It is used to display the output to the console.

Example:

#include <iostream>

using namespace std;

int main(void) {​​​​

  int a, b, sum, sub;

  cout<<"Enter the value of a and b : ";

  cin>>a>>b;

  sum = a+b;

  sub = a-b;

  cout<<"The addition value is  = "<<sum;

  cout<<"The subtraction value is  = "<<sub;

}

Note: 

In C language whenever we are going to provide any value to the program or we are used to take the output from a program then we need to specify the specifier explicitly. But in CPP it is implicitly added. 

Q1- Why the CPP has mainly designed ?

- Procedure based programming. (It is supported by C also).

- Modular programming.( The C language is used to support the Modularity partially so CPP is required).

- Data Abstraction (It is a technique where the developer can able to hide the inner complexity

of the program from the end user. Here the user will avail only the functional prospect).  

- To do the OOPS based programming. 

Q2. Is CPP support the concept of goto same as C?

A goto is basically used for Graphical Programming where we used to have the concept of forward and backward movement of control. Which may br better supported by CPP than C.

statement;

goto x;

statement;

statement;

level x:

statement;

(Forward)

statement;

level x:

statement;

statement;

goto x;

statement;

(backward) 

 

Function:

The function approach in CPP is almost same as C. But the major changes comes when we are used to consider the member function.

 return type function _name (arg1, arg2....);  

Example:

#include <iostream>

using namespace std; 

void square (int a)

{

    int b = a*a;

    cout<< b;

}

int main(void) {

int a;

cout<<"Enter the value of a : ";

cin>> a;

square(a);

}

Object and Class:

What is the Object-oriented Programming?

An object is a "thing" which is used to perform some set of activities. In the set of activity where the behavior of the parental concern is exhibited by Object. A oops is an approach where using the object we try to focus the various activities by preserving the parental behavior.

Q. What is the difference between the OOPS and POP (Procedure oriented Programming)? 

Ans: 

1. In POP , we are used to give the importance to the sequence of thing that we need to do. But in OOPS we give the importance to data.

2. In POP the larger program is divided into functions but In OOPS it is get analysed by Object.

3. In POP the most functions are used to share the global Data but in OOPS the data is private so only the same member of the class can use it.

4. POP is Top-Down approach but the OOPS is Bottom-Up approach. 

Class:

 A class is a ADT (Abstract Data Types):

class student

{​​​​

int rollno;

char name[10];

void get data();

void show data();

}​​​​;

Example;

#include <iostream>    // Program using the scope resolution operator..

using namespace std; 

class student

{​​​​

  char name[30];

  int age;

  public:

  void getdata(void);

  void showdata(void); 

}​​​​; 

void student::getdata(void)

{​​​​

   cout<<"Enter the name and age of the student..";

  cin>>name>>age;

 }​​​​  

Constructor:


 In CPP the constructor is of 4 types.

1. Default constructor

2. Parametric / Argument based Constructor.

3. Copy constructor.

4. Dynamic Constructor.

Read More >> More on C++ Questions

2 Comments

Previous Post Next Post