Friday, August 27, 2010

C++ interview Questions (2)

Question 1-11 see:
C++ interview Questions (1)


12. You’re given a simple code for the class 
Circle. Write the following functions:
 
  • Copy constructor
  • = operator overload
  • == operator overload
  • + operator overload
Class  Circle{
    private:
          double  r;
    public:
          Circle(double r0);
          Circle(const Circle& myCircle); //copy constructor 
  //= operator overload
Circle& operator=(const Circle& myCircle);
//== operator overload 
int operator==(const Circle& myCircle1, const Circle& myCircle2); 
//+ operator overload
Circle& operator+(const Circle& myCircle1, const Circle& myCricle2 );
 }; 
Circle::Circle(double r0){
             r = r0;
}
Circle::Circle(const Circle& myCircle){
     this.r = myCircle.r;
}
Circle& Circle::operator=(const Circle& myCircle)

{

    r = myCircle.r;
    return *this;

}
int Circle::operator==(const Circle& myCircle1, const Circle& myCircle2)

{

    return (myCircle1==myCircle2);

}
Circle& Circle::operator+(const Circle& myCircle1, const Circle& myCircle2)

{

    r = myCircle1.r+myCircle2.r;
    return *this;

}

int main(){
      Circle FirstCircle(2.0);
      Circle SecondCircle=FirstCircle;// this invokes the copy constructor
      return 0;
}
13 What memory part is accessed when you run a program?
heap
 dynamic memory allocation (also known as heap-based memory 
allocation) is the allocation of memory storage for use in 
a computer program during the runtime of that program.
Static memory allocation refers to the process of allocating
memory at compile-time before the associated program is executed.
Stacks in computing architectures are regions of memory 
where data is added or removed in a last-in-first-out manner, 


while heap is first-in-first-out.
stack allocation is very simple and typically faster than
heap allocatio.


14. For an empty class, what method is accessed?
default constructor, copy constructor, destructor

15. binary tree, array, hashed table, which one can be
 random accessed?
array

16. What is default constructor?
What a class is created, default constructor is automatically
called to initialize the class.


17. Which member can be accessed by a derived class?
public member and protected member.
 
18. What is object oriented programming? What is class and object?
What is difference between class and object? 
Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. A class is a definition of an object. Object is an instance of a class.
Every object belongs to a class and every class contains one or more related objects.

18.  Describe C/C++ Standard  Template Library (STL).
The Standard Template Library (STL) is a software library partially included in the C++ Standard Library. It provides containers, iterators, algorithms, and functors. More specifically, the C++ Standard Library is based on the STL published by SGI.
C++ Standard Library

    * ios, iostream, iomanip, fstream, sstream

Standard Template Library

    * vector, deque, list, map, set, stack, queue, bitset, algorithm
    * functional,iterator

C Standard Library

    * cassert, cctype, cerrno,climits, clocale, cmath
    * csetjmp, csignal, cstdarg, cstddef
    * cstdio, cstdint, cstdlib, cstring, ctime

No comments:

Post a Comment