CPP Important Question Answer For BCA 3rd Semester

CPP Important Question Answer For BCA 3rd Semester

C++ Important Question Answer For BCA 3rd Semester: – this post is very helpful for BCA 3rd semester students. in this post, we will learn about all the most important questions for BCA 3rd semester. that’s very important for examination purposes. if this post is helpful for you please share this post to your all friends. thanks. if you want to another subject BCA important question and BCA notes you can go this link. BCA Notes

CPP Important Question Answer For BCA 3rd Semester

(Section – A)

1). Explain difference between c and c++?

Ans: – There are some difference between c and c++ given below

S. No C C++
1 C language does not provide security. C++ Provides Security Because it uses the OOPS concept.
2 C langue focuses on the statement. C++ focus on the data.
3 C is procedural language. C++ follow procedural and object-oriented programming concept.
4 C does not support function overloading and overriding. C++ support function overloading and overriding.
5 C does not support Inheritance. C++ support inheritance (single level, muti-level, multiple level, hybrid level).
6 C follows top-down approach. C+ follows bottom-up approach.
7 C does not support namespaces. C++ support namespace.
8 C not support exception handling. C++ supports exception handling.
9 C language is a middle level language. C++ is a high level language.

 

2). what is the class and objects?

Ans: – Class: – class is a user defined data types. The class have own member data and member function which are wrapped into a single unit. The class default access specifier is private. The private member data and member function cannot be used outside the class. The class does not take any memory.

Objects: – the object is instance/Behaviour of class. We can say that the object is a variable of the class. And the object does take some memory.

3). Explain constructor and destructor?

Ans: – Constructor: – it is a special type of member function. It called automatically when the object is allocated/initialize the memory by the class object. The constructor have no any return type.

Destructor: – the destructor is a special type of member function which are called automatically when the object memory is deallocated/released/deleted. The memory allocated by the object.

4). what is the access specifier?

Ans: access specifier: inside the class, the access specifier used to decide the accessibility of the class member data and member function. It decided, where can from access the class data member and data function. There are there access specifiers such as:

Access Specifier Accessibility of the Access specifier
Private Class, Friend, class itself,
Public Anywhere
Protected Inherit class, friend, class itself,

 

5). Explain the given are –

  • Function overloading
  • Function overriding

Ans: Function Overloading: Function overloading means, multiple function is same name but different signature/parameters. The function overloading is decide at the program execution time/ compile time. In other words, it known as a static polymorphism/compile time polymorphism. And it is a part of polymorphism.

Function Overriding: – Function overriding means, they have multiple function with same name, same return type and same signature. When the derived class inherit from base class. The base class and derived class have two function same name, same return type and same signature. The derived class object is hidden functionality of base class.

6). what is an exception handling? Why it’s need?

Ans: Exception handling: exception is an error, it created by the user. And the exception handling is a technique of solving error. Let one example to be clearer what exception handling needed.

Example: we are created one program. That divide one number to another. And both number are entered by the user. Suppose the user entered denominator zero. It cannot be solved by the program. Here this problem solved using exception handling. Using try, catch, throw.

7). what is the pointer? How it different from variable.

Ans: pointer: pointer is a special type of variable. The pointer is stored another variable address.

Pointer How different from variable.

The variable is store value and the pointer stored another variable address.

8). what is namespaces?

Ans: Namespace: namespace is keyword in c++. Namespaces is group of declaration. Inside the namespace we can declare anything like function, class, struct union, enum and etc. we’re declare namespace in our source code and library. The benefit of namespace is, when we have two function with same name, same return type and same parameters. The namespaces solve ambiguity founded by the identifiers.

9). what is generic classes.

Ans: Generic Classes: generic class means define one class for all the data types with the help of templates function. And this generic class also work for all the data types like int, float etc.

10). what is ambiguity?

Ans: in c++ the ambiguity is a problem, in ambiguity the compiler will be confused which function is called. This is an error. And this error is fixed by the virtual keyword.

How get ambiguity

This ambiguity come when they have two base class and one derived class. Derived class inherit from both classes. And both base class have two different function with same name, same return type, and same parameters. When the derived class object call any one function the compiler will confused which function called, so compiler given an ambiguity.

Solved: if we want to solve this ambiguity used virtual keyword. They are many methods of solving this ambiguity.

(Section – B)

1). what is encapsulation?

Ans: Encapsulation: – encapsulation is the part OOP’s and it is the first pillar of the object oriented programming. Encapsulation is aim to hide the sensitive data from the user. In encapsulation, inside the class the data member and data function are wrapped into a single unit. And all member data are private. Only function are public. The encapsulation provide high security. The private member data cannot be accessible by outside the class. These private member data only used by the class member function.

2). what is abstraction?

Ans: Abstraction: – Abstraction is the part of the OOP’s and it is the second pillar of the object oriented programming. In abstraction the only showing necessary details to the user and hide to all details in class background/private.

Data Abstraction can be achieved in two ways.

Abstraction Using Class: in class abstraction we’re create a class and only showing the necessary details and hide the all other details into private.

Abstraction in Header Files: in header file abstraction, if we are using any header file in c++ we cannot see own algorithm and coding. We’re are only used them.

3). what is polymorphism?

  • Static (compile time polymorphism)
  • Dynamic (runtime polymorphism)

Ans: Polymorphism: polymorphism is a third pillar of object oriented programming. The polymorphism means many forms. We can say that one name and many forms. It called polymorphism.

There are two types of polymorphism:

Static polymorphism/ compile time polymorphism/ early binding: in static polymorphism means the compiler already known which function are called. And compiler it decide at the program compilation time.

  • Function Overloading:
  • Operator Overloading:

Dynamic Polymorphism/ Run time polymorphism/ late binding: the dynamic polymorphism is the process of which is solved the function overriding. We’re binding the object and function at the run time or after program execution time.

Virtual Function: before, know about the virtual function, you know what the function is overriding.

  • Function overriding: function overriding is the process of when derived class inherit from base class. They have two same function that same name, same return type, and same parameters. When we’re are created base class pointer *obj. and called the function, this will call derived class function which are right. But when we are create derived class obj2 and this obj2 address stored to the *obj. then we’re called function using *obj, they are calling base class function not derived class. In this the derived class function hide the functionality of the derived class. It’s called function overloading.

When we’re using virtual keyword before base class function. This will be fixed overridden problems.

4). what is inheritance?

Ans: Inheritance: inheritance is fourth pillar of the object oriented programming. The inheritance is the very important concept in OOP’s. Inheritance is the process of reused the properties of one class into other class. The inheritance is support code reusability. We’re are include another class properties and modified its.

There are some types of inheritance which are

  • Single inheritance: in singly inheritance one base class A and one derive class B. Derive class B inherit form base class A. this types of inheritance known single level inheritance.
  • Multi inheritance: in multi inheritance class A, Class B, Class C. the class c inherit from class b and class b inherit from class A. this types of inheritance known as multi inheritance.
  • Hierarchal Inheritance: in hierarchal inheritance class A, class B, class C and class D. and the class B, C, and D inherit form class A. this type of inheritance known as hierarchal inheritance.
  • Multiple Inheritance: in multiple inheritance class A, class B and class C. and the class C inherit form class A and Class B. this type of inheritance is known as multiple inheritance.
  • Hybrid Inheritance: in hybrid inheritance class A, class B, class C and class D. and the class D inherit form class b and class C. and the class B and class C inherit from class A. this type of inheritance in known as Hybrid Inheritance.

5). what is the approach of oops?

Ans: Programming Approach: C++ follows a bottom-up approach to programming. In this, we start with low-level design or coding and then build on the low-level design to get a high-level solution.

6). what is the constructor and its types.

Ans: Constructor: it is a special type of member function. It called automatically when the object is allocate/initialize the memory by the class object. The constructor have no any return type.

There are three types of contractor:

  • Default contractor: – the default constructor not taking any parameters.
  • Parametrize constructor: – the parametrize constructor is take one or more parameters.
  • Copy Constructor: – that takes an object as an argument and is used to copy the values of data members of one object to another.

7). Explain new and delete.

Ans: New: new is keyword in c++. Which are used to dynamic allocate memory. The new keyword is used to pointer types of object or variable. There are two works of new keyword. First allocate the memory in dynamic and second return the address.

Delete: delete is keyword in c++. Which are used to deallocate memory created by the new keyword.

(Section – C)

1). Explain the features of c++. Explain for, while, do while, loops.

Ans: Features of C++: there are some features of c++ which are given below:

  • Namespaces
  • Template
  • High Level
  • Rich Library
  • Storage Classes
  • Object Oriented
  • Data Hiding
  • Program Reusability
  • Function overloading
  • Close to hardwire

Loops: when, we’re are repeat same condition in multiple time. One think is we’re write randomly but it’s not good practice, so we’re used loops. The loop is run according to their condition. If the condition is true then run otherwise the condition is false not work.

There are two types of loops.

i). Entry Control Loops: In this type of loops first check the condition. If the condition is true then run otherwise exit.

  • For Loop:
  • While Loop:

ii). Exit Control Loop: in this type of loops first run and second check the condition. Not if this type of loops

  • do while loop:

2). Explain (abstraction, polymorphism, inheritance, and encapsulation).

Ans: seen the section – B answer no. 1,2,3,4.

3). what is template? Give the suitable example.

Ans: Template: They keyword template is used to define function template and class template. In template, we’re make our class or function is generic it’s also work for all the data types.

To understand the concept of template take an example.

Ex: we will create a one function which are print sum of two digit, the function is work for all data types like – int, float, other. One think, I created more than one function for all types. But it’s not good practice. Second think is I’m using template.

Types of templates

  • Function template: when we’re using this template into our function. And make our function is generic. Generic means our function is capable for all data types.
  • Class templates: when we’re using this template into our class. And make our class is generic class. Generic means our class is capable for all data types.

4). Write a program to check string is palindrome or not.

Ans:

#include<iostream>
using namespace std;
int str_len(char str[]){
    int i =0;
    while(str[i]!='\0'){
        i++;
    }
    return i;
}
int main(){
    char str[100];
    int lenth, templenth,i=0,flag=0;
    cout<<"\nEnter an string: "<<endl;
    cin>>str;
    lenth = str_len(str);
    templenth = lenth-1;
    while(i<lenth){
        if(str[i]!=str[templenth]){
            flag = 1;
            break;
        }
        i++;
        templenth--;
    }
    if(flag==1){
    cout<<"\n string Not palindrone ";
    }
    else{
    cout<<"\n string Is palindrone ";
    }
    return 0;
}

5). Explain in detail User defined function. What is the parameters passing in function?

Ans: User defined function: the user defined function which function declare by the user according to their need. There are some step to declare user defined function.

There are 3 step to declare and use user defined function in c++

  • Function prototype/declaration: in this step we will tell our function which value return and how many parameters are received. In this step we will write before main function in our program.
  • Function definition: in user defined function, it means our function what will be done, inside this we write down the working of our function.
  • Function Calling: in this step, simply we are calling our user defined function and used it.

Parameters Passing

  • Parameters / Formal Parameters: – when the user defined function receive value from the actual parameters/arguments. They are can be call by reference (passed the address) or call by value (send copied value).
  • Arguments / Actual Parameters: – when we’re are passed the value at the function calling time called argument/ actual parameters. In this argument passed value to the parameters.

6). write a program to reverse a number. The number entered by the user.

Ans:

#include<iostream>
using namespace std;
void reverse_digit(int x){
    int rev=0,rem;
    while(x!=0){
        rem =  x%10;
        rev = rev*10+rem;
        x =x/10;
    }
    cout<<"rev: "<<rev;
}
int main(){
    int num;
    cout<<"Enter a number: "<<endl;
    cin>>num;
    reverse_digit(num);
    return 0;
}

7). Explain friend function and friend class.

Ans: Friend Function: Friend functions are those functions that have the right to access the private data of members of the class.

Friend Class: Friend class are those classes that have the right to access the private data of members of the class.

—————————————- Thanks ——————————————

YouTube Channel

Please Subscribe

Dream Topper

URL: https://www.youtube.com/dreamtopper

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top