(Note-The solutions of the various programmings of this question bank are available at related topic content or 'c++ programming also object oriented programming in c++' page)
BASICS
Difference between c anf c++.
Different batween procedural and Object Oriented Programmimg
Briefly discuss different data types in c++.
Escape sequence
constant
void data types
operator
identifiers
modifiers
character constant and string constant
Discuss the basic data types of C++.Suggest appropriate data type for the following:
(1)Someone's height in meters
(2)An exclamation mark
(3)The number of students in a university
Write a C++ program to find the sum of the series
1+3+5+......+n.
Discuss conditional,logical and increment operators with example.
CONTROL STATEMENT
Discuss the significance of break statement in switch case construct with an example.
Compare and contrast while,do-while and for loop with example.
Explain nested switch() case statrment with an example.Show outputs.
Explain branching statements used in C++ with example.
Syntactically explain nested "if-else" statement in c++.
POINTER AND STRING
Write the expressions to present the following:-
(1) p is a function whose argument is a pointer to an array of characters and which returns a pointer to an integer.
(2) p is a function whose argument is a pointer to character and which returns a pointer to an array of ten integers.
Define string.How does a string type differ from C type string?
WAP to reads a particular string and display the frequency of each character in the string.
WAP in C++ using array of pointers to accept desired number of integers and display their sum.
Explain 'this' pointer,void pointer,wild pointer.
CLASS AND OBJECT
Define class and object.Write a program to calculate factorial of a no. using class and object.
Differentiate Private,Public,Protected data members of the class using example.
SPECIAL MEMBER FUNCTION
What is the diff. between zero argument constructor and parameterized constructor?Explain with example.
Create a class complex and implement the following:
(1)Define suitable constructor and destructors
(2)Overload the operators + and -
(3)Write a friend function sum which adds.the real and imaginary parts of a complex object
Explain concept of destructor in a class.
What is its role in terms of cleanup of unwanted objects?
What is an inline function?In which situations would you make a function inline?
Give two examples of inline function.Its advantages and disadvantages.
Design and implement a class string using an array.with a maximum size of 20 characters.The class should contain the necessary constructors,destructor,
overloaded assignment opetator and a friend function for concatenation of two strings.
Make suitable assumptions if required.Also write main() for the above.
Write a program that defines a shape class with a constructor that gives value to width and height. Then define two sub-classes triangle and rectangle, that calculate the area of the shape area().In the main, define two variables a triangle and a rectangle and then call the area() function in this two variables.
Define copy constructor.Explain its significance.Under which conditions is it invoked?Support your answer with an example.
Write a C++ program for linear search using recursive function.
Write a C++ program to find Armstrong number.
Given the C++ code
class A{
public:
A(){a=new int[3];for(int i=0i<3;i++)a[i]=i;}
~A()
{
delete[] a;}
private:
int *a;
};
void int(A &x) //sets elements of x.a to 0,1,2
{
A y; //fresh object
x=y;
}
int main()
{
A p;
…
init(p);
…
}
You might notice that as the program runs following the call init(p),the values stored in p.a stary changing unpredictably.What might be happening?Fix this problem.
VERTUAL FUNCTION ,INHERITANCE,OVERLOADING FUNCTIONS,TEMPLATES
List out the advantages and disadvantages of inheritance.
What is the virtual mamber function in C++?Describe the rules for declaring virtual functions.
What is virtual destructor?How virtual functions call up is maintained?
What heppens if you leave the virtual keyword off the declaration of the member function?Is there an equivalent of a non vertual mamber function.
Diff. between overload function and function templates.
Inheritance and its types.
WAP to demonstrate use of vertual functions.
Explain the constructor and destructor with multi-level inheritence using C++ program.
Define a simple C++ class template myobj,parameterized by a single type,such the following code will work:
myobj<int>s1,s2;
myobj<int>s3=sum(s1,s2,s2);
Make the myobj template as simple as you like.
Write a simple C++ class A that overloads its operators==() method such that the following procedure will work:
void f(A &p,A &q)
{
if(p==q)
{
cout<<"yes\n";
else
cout<<"No\n";
}
Suppose class B was derived from class A such that B de_ned an operator==() to compare two objects of class B,as in
class B:public A{
bool operator==(B &x);
}
Note,though,that in,
int main()
{A a1;
A a2;
B b1;
B b2;
f(a1,a2);//uses A's==operator
f(b1,b2);//also uses A's==operator
Turn the C++ definition
int sum(int a,int b,int c)
{
return a+b+c;
}
into a function template that can be used to work on any type that supports +,instead of just int.Be sure that the template will work for objects that implement the + operator,so that dynamic dispatching of + will occur where possible.
What is operator overloading in C++?Explain with suitable example.Also list operators which cannot be overloaded.
Differentiate between Operator and Function overloading with the help of suitable example.
With relevant examples ,explain:-
(1) multilevel inheritance
(2) hybrid inheritance
What is the output of the following code:-
#include<iostream>
class A{
public:
void f()
{
std::cout<<"A::f"<<std::endl;
}
virtual void g()
{
std::cout<<"A::g"<<std::endl;
}
};
class B:
publicA
{
public:
void f()
{
std::cout<<"B::f"<<std::endl;
}
virtual void g()
{
std::cout<<"B::g"<<std::endl;
}
};
int main(int aegc,char** argv)
{
A a;
B b;
A* aPtr=&a;
A*bPtr=&b;
aPtr->f();
aPtr->g();
bPtr->f();
bPtr->g();
return 0;
}
Is there anything to be noticed?Explain it.
How can a common friend function to two different classes be declared?
Define the following:
Polymorphism
Typecasting
Class and instance
Containership
Abstract class
SEARCH TOPIC FOR ANSWERS
-----------
PLEASE WRITE COMMENTS IN COMMENT BOX
-----------
BASICS
Difference between c anf c++.
Different batween procedural and Object Oriented Programmimg
Briefly discuss different data types in c++.
Escape sequence
constant
void data types
operator
identifiers
modifiers
character constant and string constant
Discuss the basic data types of C++.Suggest appropriate data type for the following:
(1)Someone's height in meters
(2)An exclamation mark
(3)The number of students in a university
Write a C++ program to find the sum of the series
1+3+5+......+n.
Discuss conditional,logical and increment operators with example.
CONTROL STATEMENT
Discuss the significance of break statement in switch case construct with an example.
Compare and contrast while,do-while and for loop with example.
Explain nested switch() case statrment with an example.Show outputs.
Explain branching statements used in C++ with example.
Syntactically explain nested "if-else" statement in c++.
POINTER AND STRING
Write the expressions to present the following:-
(1) p is a function whose argument is a pointer to an array of characters and which returns a pointer to an integer.
(2) p is a function whose argument is a pointer to character and which returns a pointer to an array of ten integers.
Define string.How does a string type differ from C type string?
WAP to reads a particular string and display the frequency of each character in the string.
WAP in C++ using array of pointers to accept desired number of integers and display their sum.
Explain 'this' pointer,void pointer,wild pointer.
CLASS AND OBJECT
Define class and object.Write a program to calculate factorial of a no. using class and object.
Differentiate Private,Public,Protected data members of the class using example.
SPECIAL MEMBER FUNCTION
What is the diff. between zero argument constructor and parameterized constructor?Explain with example.
Create a class complex and implement the following:
(1)Define suitable constructor and destructors
(2)Overload the operators + and -
(3)Write a friend function sum which adds.the real and imaginary parts of a complex object
Explain concept of destructor in a class.
What is its role in terms of cleanup of unwanted objects?
What is an inline function?In which situations would you make a function inline?
Give two examples of inline function.Its advantages and disadvantages.
Design and implement a class string using an array.with a maximum size of 20 characters.The class should contain the necessary constructors,destructor,
overloaded assignment opetator and a friend function for concatenation of two strings.
Make suitable assumptions if required.Also write main() for the above.
Write a program that defines a shape class with a constructor that gives value to width and height. Then define two sub-classes triangle and rectangle, that calculate the area of the shape area().In the main, define two variables a triangle and a rectangle and then call the area() function in this two variables.
Define copy constructor.Explain its significance.Under which conditions is it invoked?Support your answer with an example.
Write a C++ program for linear search using recursive function.
Write a C++ program to find Armstrong number.
Given the C++ code
class A{
public:
A(){a=new int[3];for(int i=0i<3;i++)a[i]=i;}
~A()
{
delete[] a;}
private:
int *a;
};
void int(A &x) //sets elements of x.a to 0,1,2
{
A y; //fresh object
x=y;
}
int main()
{
A p;
…
init(p);
…
}
You might notice that as the program runs following the call init(p),the values stored in p.a stary changing unpredictably.What might be happening?Fix this problem.
VERTUAL FUNCTION ,INHERITANCE,OVERLOADING FUNCTIONS,TEMPLATES
List out the advantages and disadvantages of inheritance.
What is the virtual mamber function in C++?Describe the rules for declaring virtual functions.
What is virtual destructor?How virtual functions call up is maintained?
What heppens if you leave the virtual keyword off the declaration of the member function?Is there an equivalent of a non vertual mamber function.
Diff. between overload function and function templates.
Inheritance and its types.
WAP to demonstrate use of vertual functions.
Explain the constructor and destructor with multi-level inheritence using C++ program.
Define a simple C++ class template myobj,parameterized by a single type,such the following code will work:
myobj<int>s1,s2;
myobj<int>s3=sum(s1,s2,s2);
Make the myobj template as simple as you like.
Write a simple C++ class A that overloads its operators==() method such that the following procedure will work:
void f(A &p,A &q)
{
if(p==q)
{
cout<<"yes\n";
else
cout<<"No\n";
}
Suppose class B was derived from class A such that B de_ned an operator==() to compare two objects of class B,as in
class B:public A{
bool operator==(B &x);
}
Note,though,that in,
int main()
{A a1;
A a2;
B b1;
B b2;
f(a1,a2);//uses A's==operator
f(b1,b2);//also uses A's==operator
Turn the C++ definition
int sum(int a,int b,int c)
{
return a+b+c;
}
into a function template that can be used to work on any type that supports +,instead of just int.Be sure that the template will work for objects that implement the + operator,so that dynamic dispatching of + will occur where possible.
What is operator overloading in C++?Explain with suitable example.Also list operators which cannot be overloaded.
Differentiate between Operator and Function overloading with the help of suitable example.
With relevant examples ,explain:-
(1) multilevel inheritance
(2) hybrid inheritance
What is the output of the following code:-
#include<iostream>
class A{
public:
void f()
{
std::cout<<"A::f"<<std::endl;
}
virtual void g()
{
std::cout<<"A::g"<<std::endl;
}
};
class B:
publicA
{
public:
void f()
{
std::cout<<"B::f"<<std::endl;
}
virtual void g()
{
std::cout<<"B::g"<<std::endl;
}
};
int main(int aegc,char** argv)
{
A a;
B b;
A* aPtr=&a;
A*bPtr=&b;
aPtr->f();
aPtr->g();
bPtr->f();
bPtr->g();
return 0;
}
Is there anything to be noticed?Explain it.
How can a common friend function to two different classes be declared?
Define the following:
Polymorphism
Typecasting
Class and instance
Containership
Abstract class
SEARCH TOPIC FOR ANSWERS
-----------
PLEASE WRITE COMMENTS IN COMMENT BOX
-----------
No comments:
Post a Comment