CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
Object Oriented Programming in C++ Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM C++ INTERVIEW QUESTIONS OBJECT ORIENTED PROGRAMMING IN C++ INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

Object Oriented Programming in C++ Interview Questions & Answers - Learning Mode

C++ and Object Oriented Programming. Object Oriented programming is a programming style that is associated with the concept of Class, Objects and various other concepts revolving around these two, like Inheritance, Polymorphism, Abstraction, Encapsulation etc. 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.

Try Object Oriented Programming in C++ Interview Questions & Answers - Exam Mode

1 2 3 Next

Sort By : Latest First | Oldest First | By Rating

Object Oriented Programming in C++ Interview Questions & Answers - Learning Mode
Try Object Oriented Programming in C++ Interview Questions & Answers - Exam Mode
Question: what are the disadvantages of copy constructor??

Answer: Well if we are talking about the default copy constructor, then the disadvantage it suffers from is that i does a shallow copy of the class object.<br>Which means that if the class has some dynamic memory allocated or file pointers, the copied object will also point to the same memory location or files. That is the memory or file is not copied. Source: CoolInterview.com
Question: Write a C++ program that contains a structure named ?Student? having two data members

1) Name

2) CGPA
Declare array of structure ?Student? of size 10 .Populate this array by taking data from file inputFile.txt.File inputFile.txt contains Name and CGPA of the students for current semester. There is a single space between the Name and CGPA.

Display the un-sorted list of students on screen. Compare the CGPAs of all the students and sort Student List with respect to CGPA in ascending or descending order.

Display the sorted list of students, highest CGPA and lowest CGPA on screen and also write the result in File outputFile.txt with tab characters between the Name and CGPA.
Sample InputFile.txt
Ahmer 4.0

Aasim 3.5
Usman 3.4
Maria 2.4
Anila 3.0
Humza 2.6
Junaid 3.0
Talaal 3.8
Haris 3.9
Saira 2.6
Sample OutputFile.txt

Sample outputFile.txt





Name CGPA

===============

Maria 2.4

Humza 2.6

Saira 2.6

Anila 3.0

Junaid 3.0

Usman 3.4

Aasim 3.5

Talaal 3.8

Haris 3.9

Ahmer 4.0

===============

Highest CGPA = 4.0

Lowest CGPA = 2.4

































Sample output of screen:



Unsorted List of Students

Name CGPA

Ahmer 4.0

Aasim 3.5

Usman 3.4

Maria 2.4

Anila 3.0

Humza 2.6

Junaid 3.0

Talaal 3.8

Haris 3.9

Saira 2.6



Sorted List of Students

Name CGPA

===============

Maria 2.4

Humza 2.6

Saira 2.6

Anila 3.0

Junaid 3.0

Usman 3.4

Aasim 3.5

Talaal 3.8

Haris 3.9

Ahmer 4.0

===============

Highest CGPA = 4.0
Lowest CGPA = 2.4


Answer: No answer available currently.
Question: What will happen if I say delete this




Answer: if you say "delete this", you are effectively calling the destructor twice, which could well be a disaster if your class uses heap. The destructor will be called when you say " delete this " and again when that object goes out of scope. Since this is the language behavior, there is no way to prevent the destructor from being called twice. Please refrain from forcibaly calling a destructor or using clause like this. For more information, visit the following link: http://www.parashift.com/c++-faq- Source: CoolInterview.com
Question: All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks.

Q1. A. What is unary operator? List out the different operators
involved in the unary operator.

B. What is an adjust field format flag?

Q2. A. Distinguish between a # include and #define.

B. Can a list of string be stored within a two dimensional array?

Q3. A. Explain how a pointer to function can be declared in C++?

B. List the merits and demerits of declaring a nested class in C++?


Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence?

B. Explain the operation of overloading of an assignment operator.


Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps.

B. Explain how an exception handler is defined and invoked in a Program.


Q6. A. What is a binary file? List the merits and demerits of the binary file usage in C++.

B. Write short notes on Text Manipulation Routines.

C. Write bites in Turbo c++ Header (?Include?) Files.











Answer: unary operator are those which needs only one operand for operations like ++, --, ! these are unary operators. Source: CoolInterview.com
Question: When do we use abstract.h?Give an example with a small program.

Answer: No answer available currently.
Question: A positive integer entered through the keyboard. Write a function to obtain the prime factors of this number.
For example : prime factors of 24 are 2,2,2 and 3,, where as prime factor of 35 are 5


Answer: #include<iostream.h>
#include<conio.h>
void recprime(int n)
{
if (n<2) return;
for(int i=2;i<n;i++)
{
if((n%i)==0)
{
cout<<i<<" ";
n=n/i;
break;
}
}
if ((n>2) && (i<n)) recprime(n); else cout<<n;
}
void main()
{
int n;
clrscr();
do
{
cout<<"
Enter the number :";
cin>>n;
cout<<"
The prime factors of "<< Source: CoolInterview.com
Question: What is an object?

Answer: Object is a software bundle of variables and related methods. Objects have state and behavior. Source: CoolInterview.com
Question: Given an integer N>0,write a recursive c++ function that writes the integer 1,2,.......N ?

Answer: void Display(int nNumber)
{
if(nNumber > 1)
Display(nNumber - 1);
else
printf("
%d", nNumber);
} Source: CoolInterview.com
Question: How can you tell what shell you are running on UNIX system?

Answer: You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You could also do a ps -l and look for the shell with the highest PID. Source: CoolInterview.com
Question: What are the steps involved in designing?

Answer: Before getting into the design the designer should go through the SRS prepared by the System Analyst. The main tasks of design are Architectural Design and Detailed Design. In Architectural Design we find what are the main modules in the problem domains Detailed Design we find what should be done within each module. Source: CoolInterview.com
Question: Hi, I was asked the below question in one interivew.

Imagine you're maintaining a big project which is having 50k+ lines of code and as part of enhancements, you received a request to add a functionality in one of the .cpp files. For this, you need to add a new function. How do you write a new fucntion without adding a prototype to the header file (because, if you add prototype in the headerfile, the compiler has to compile all the other files). So, the requirement is not to touch the header file but add functionality in the cpp file. How do you add?


Answer: u can use virtual fuction which is already in base.

and u dont need to compile whole project u just need remove .o file and complie again by concept of mak in unix. Source: CoolInterview.com
Question: What is the object-oriented design,inheritance and dynamic polymorphism in c++?


Answer: In object oriented design every thing is object that using class to design define members that is object oriented design.<br>Inheritance is to use the existing code to new created class.<br>Dynamic polymorphism is to create a virtual function.That is same name of method in base class and derived class. Source: CoolInterview.com
Question: List out some of the object-oriented methodologies.

Answer: Object Oriented Development (OOD) (Booch 1991,1994).<br>Object Oriented Analysis and Design (OOA/D) (Coad and Yourdon 1991).<br>Object Modeling Techniques (OMT) (Rumbaugh 1991).<br>Object Oriented Software Engineering (Objectory) (Jacobson 1992).<br>Object Oriented Analysis (OOA) (Shlaer and Mellor 1992).<br>The Fusion Method (Coleman 1991). Source: CoolInterview.com
Question: Q1.write C++ program to accept a string and display ascii value letter by letter then display sum of all ascii values.
Q2.write C++ program to accept 20 nos and then display max & min.


Answer: 1. #include<stdio.h>
class str
{
char st[20];
};
void main()
{
str ob=new str();
int asc[20],sumasc=0;
printf("Enter string");
scanf("%s",ob.st);
for (i=0;i<20;i++)
{
asc[i]=toascii(ob.st[i]);
sumasc=sumasc+asc[i];
}
printf("The sum of ascii number is",sumasc);
}

2.Just read 20 numbers using for loop and then use one variable as maximum set to zero and in Source: CoolInterview.com
Question: What is abstraction?

Answer: Abstraction is of the process of hiding unwanted details from the user. Source: CoolInterview.com
Question: What is multithreading?

Answer: Multithreading is the mechanism in which more than one thread run independent of each other within the process. Source: CoolInterview.com
Question: What do you mean by binding of data and functions?

Answer: Encapsulation. Source: CoolInterview.com
Question: Differences of C and C++
Could you write a small program that will compile in C but not in C++ ?


Answer: In C, if you can a const variable e.g.
const int i = 2;
you can use this variable in other module as follows
extern const int i;
C compiler will not complain.

But for C++ compiler u must write
extern const int i = 2;
else error would be generated. Source: CoolInterview.com
Question: How can i create a program in C++
which would input 5 random numbers, then it would arrange them in an ascending order, in descending order, from highest to lowest value and from lowest to highest value?


Answer: #short from descending
#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

void selectionsort(int data[], int first, int n)
{
int small;
int temp;

for (int i = n-1; i>0; i--)
{
small = first;
for (int j = first+1; j <= first + i; j++)
{
if(data[small]> data[j])
small = j;
}
temp = data[first+i];
data[first+i] = data[small];
data[sm Source: CoolInterview.com
Question: How to write a program to read sequences of integer from keyboard.program should sum all even and odd numbers?

Answer: ANSWER IN THE FORM OF A SMALL PROGRAM :
#include<iostream.h>
#define MAX 50
void main()
{
int a[MAX],i,n,seven=0,sodd=0;
cout<<"
How many nos u wish to enter (max=50)";
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
i=0;
while(i!=n)
{
if(a[i]%2==0)
seven=seven+a[i];
else
sodd=sodd+a[i];

i++;
}
cout<<"
RESULT IS :";
cout<<"
Even sum is:"<<seven;
cout<<"
Odd sum is Source: CoolInterview.com

1 2 3 Next



India News Network
Latest 20 Questions
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
"Holiday Packages" announced as an advertisement are an example of _________: (a) Offer (b) Counter Offer (c) Invitation to Offer (d) None of the above
A match fixing contract between a player and a broker is a: (a) Valid Contract (b) Unenforceable Contract (c) Void Contract (d) Illegal Contract
When a bookseller sells a book on cash payment then it is called as ___________: (a) Unilateral Contract (b) Bilateral Contract (c) Executed Contract (d) Executory Contract
____________ agreements are created by situation: (a) Written (b) Oral (c) Void (d) Implied
Cache = 0.015625 Seconds