1)
What is Class in C++?
Ans:- Class in C++ can be
defined as a collection of member function and related data under a single
name. By creating object we can access function and data in the class.
2)
What is member function in C++?
Ans:- The member function
regulates the behavior of the class. It provides a definition for
supporting various operations on data held in the form of an object.
3)
What are the various basic data type available in C++?
Ans:- Char, int,
float,double,Bool.
4) How
Functions are classified in C++?
Ans:- User defined
Function, Predefined Function
5)
How many types of User defined functions in C++?
Ans:-
Function with no argument and no return value.
Function with no argument but return value.
Function with argument but no return value.
Function with argument and return value.
6)
What is the difference between Function declaration and Function Prototype?
Ans:- A function definition
cannot be called unless the function is declared. The function prototype and
the function definition must agree exactly on the return type, the name, and
the parameters.
7)
What is the difference between late binding and early binding?
Ans:- The early binding
(static binding) refers to compile time binding and late binding (dynamic
binding) refers to runtime binding.
8)
Write a C++ Program to calculate a Armstrong number.
Ans:-
int main()
{
int origNum, num, rem, sum = 0;
cout << "Enter a positive integer: ";
cin >> origNum;
num = origNum;
while(num != 0)
{
rem = num % 10;
sum += rem * rem * rem;
num /= 10;
}
if(sum == origNum)
cout << origNum << " is an
Armstrong number.";
else
cout << origNum << " is
not an Armstrong number.";
return 0;
}
9) What are Virtual Functions?
Ans:- If a function with same name exists in base as
well as parent class, then the pointer to the base class would call the
functions associated only with the base class. However, if the function is made
virtual and the base pointer is initialized with the address of the derived
class, then the function in the child class would be called.
10) What is Pure Virtual Function?
Ans:- Pure
Virtual Function does not have a implementation part, but it’s declared as ‘0’
in the declaration Part.
11) Name some of the commonly used
manipulators in C++?
Ans:- Setw,setprecision,setf,endl
12) Can we define a Class without
creating Constructor?
Ans:- Yes
we can create a Class without creating Constructor.
13) Explain the advantages of using
Friend Classes?
Ans:- When private data members need to be accessed and
used by 2 classes simultaneously. In these kind of situations we will use
friend functions which have an access to the private data members of both the
classes. Friend functions need to be declared as ‘friend’ in both the classes.
14) Write a C++ program to
remove all characters except alphabets?
Ans:-
#include <iostream>
void main() {
string line;
cout << "Enter a
string: ";
getline(cin, line);
for(int i = 0; i <
line.size(); ++i)
{
if (!((line[i] >= 'a'
&& line[i]<='z') || (line[i] >= 'A' && line[i]<='Z')))
{
line[i] = '\0';
}
}
cout << "Output
String: " << line;
}
15)Write a C++
Program to find the largest among ‘N’ numbers.
Ans:-#include <iostream>
void main()
{
int i,n,m;
cout <<"Enter the total number \n";
cin >>n;
cout <<"The total number of array is \n"<<n;
for(i=1;i<=n;i++)
cin >>a[i];
cout <<"The entered array is \n";
for(i=1;i<=n;i++)
cout <<"\n"<<a[i];
m = a[1];
for(i=2;i<=n;i++)
{
if(m<a[i])
m = a[i];
}
cout <<"The largest number is \n"<< m;
getch()
}
16)Write a C++
Program to Calculate Factorial of a number using Recursion
Ans:-
#include<iostream>
int factorial(int n);
void main()
{
int n;
cout <<
"Enter a positive integer: ";
cin >> n;
cout <<
"Factorial of " << n << " = " <<
factorial(n);
}
int factorial(int n)
{
if(n > 1)
return n *
factorial(n - 1);
else
return 1;
}
17)
What is the difference
between "calloc" and "malloc"?
Ans:- calloc and malloc are used for dynamic memory
allocation. Calloc initializes the memory locations to zero by default but
malloc memory contains garbage values.
18)
What is a pointer?
Ans:-Pointers are variables which stores the address of another
variable.
19) What are the uses of a pointer?
Ans:-Pointer is used in the following cases
It is used to access
array elements.
It is used for dynamic memory allocation.
It is used in Call by
reference.
It is used in data structures like trees,
graph, linked list etc
20)
Does C++ support multilevel and multiple inheritance?
Ans:- Yes