Vous êtes sur la page 1sur 27


Designing Skills

1. Basic of Design
1. What are the access specifiers in a class?
Ans: Public, Private and Protected.
Public data members and member functions are accessible outside the class.
Protected data members and member functions are only available to derived classes.
Private data members and member functions cant be accessed outside the class. However
there is an exception can be using friend classes.
2. What is the difference between struct and class?
The struct default access type is public. A struct should typically be used for grouping data.
The class default access type is private, and the default mode for inheritance is private. A
class should be used for grouping data and methods that operate on that data.
class X {
// private by default
int a;
// public member function
int f() { return a = 5; };


struct Y {
// public by default
int f() { return a = 5; };
// private data member
int a;

3. What is the difference between struct and union in c++?

All the members of the structure can be accessed at once, where as in an union only one
member can be used at a time.
Another important difference is in the size allocated to a structure and an union.
Structure: The size in bytes is the sum total of size of all the elements in the structure,
plus padding bytes.
Size of in bytes of the union is size of the largest variable element in the union.
union myUnion{
int var1;
long var2;

What is a Structure?
A structure is a convenient tool for handling a group of logically related data items.
Structure help to organize complex data is a more meaningful way. It is powerful concept
that we may after need to use in our program Design.
A structure is combination of different data types. Lets take the example of a book, if we
cant to declare a book we will be thinking about the name, title, authors and publisher of
the book and publishing year. So to declare a book we need to have some complex data
type which can deal with more than one data types.
struct Book
char Name[100];
char Author[100];
char Publisher[80];
int Year;

4. What is a singleton class?

Singleton class:
The singleton pattern is a design pattern that restricts the instantiation of a class to one object.
This is useful when exactly one object is needed to coordinate actions across the system. The
concept is sometimes generalized to systems that operate more efficiently when only one object
exists, or that restrict the instantiation to a certain number of objects.

5. Can you give me an example of a singleton class? Where it is used?

The Singletons are often used to control access to resources such as database connections or
sockets. Suppose we have a license for only one connection for our database. A Singleton
connection object makes sure that only one connection can be made at any time.

6. What is constructor?
A constructor is a special member function whose task is to initialize the object of its class. It
has same name as that of class. It is invoked automatically when the object of that class is created.
It is called constructor because it construct the values of data member of the class NOTE it is the
only function which does not have any return type.

7. What is destructor?
A destructor as name implies, is used to destroy the objects that have been created by a constructor.
Like a constructor the destructor is a member function whose name is the same as the class name
but is preceded by a tilde.
Example: Destructor for class integer: ~integer () {}
A destructor never takes any argument nor does it return any value. It will be invoked implicitly by
the compiler upon exit from the program to clean up the storage that is no longer accessible.

It is required to invoke destructor, because when the pointers to objects go out of scope, a
destructor is not called implicitly.

8. What is copy constructor?

A copy constructor is a method that accepts an object of the same class and copies its data
members to the object on the left part of assignment:
class Point2D{
int x; int y;

public int color;

protected bool pinned;
public Point2D() : x(0) , y(0) {} //default (no argument)
public Point2D( const Point2D & ) ;
Point2D::Point2D( const Point2D & p )
this->x = p.x;
this->y = p.y;
this->color = p.color;
this->pinned = p.pinned;

9. What is parameterized constructor?

It is necessary to initialize the various data elements of different objects with different value.
Passing arguments to the constructor function when the objects are created and the constructors that
can take arguments are called Parameterized constructors.
Class integer
int m, n;
integer(int x, int y); // parameterized constructor

integer:: integer (int x, int y)
m=x; n=y;

10. Can we have "Virtual Constructors"?

Ans: No Virtual Constructors are there.

11. What is virtual destructor?

If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to
a base-class pointer to the object, the base-class destructor function (matching the pointer type) is
called on the object.
There is a simple solution to this problem declare a virtual base-class destructor.

This makes all derived-class destructors virtual even though they dont have the same name as the
base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the
delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate
class is called.

12. When a copy constructor gets called?

Copy constructor is called on three instances;
When instantiating one object and initializing it with values from another object
When passing an object by value.
When an object is returned from a function by value.

13. Why the object is passed as reference in copy constructor?

Otherwise, it will invoke an infinite recursion, calling each object's copy constructor again
and again.

14. Can we overload the constructor?

Although a constructor for a class is a special member function it is still considered a
function and like all functions in C++ its name can be overloaded.
Now a class constructor is used to create instances of that class, and is a special (instance)
member function having the same name as the class whose types it is to create. If a class
has no explicitly defined constructors then the compiler will generate default constructor
implementation for the class. These are a default constructor that takes no parameters at all
and does nothing, and a copy constructor that creates a new instance from an existing one
by copying the bits of the existing instance to the new instance. So even if you define no
constructors you have two ways to create a class instance.
Overloading constructors, like overloading other function names, is just the practice of
defining more than one constructor for a class, each taking a different set of parameters:
class A

A( A const & other );
// ...

// Default constructor
// Copy constructor

15. Can we overload the destructor?

No. Destructors never have parameters or return values. And you're not supposed to call
destructors explicitly, so you couldn't use parameters or return values anyway.
You can have only one destructor for a class Fred. It's always called Fred::~Fred(). It
never takes any parameters, and it never returns anything.
You can't pass parameters to the destructor anyway, since you never explicitly call a
destructor (well, almost never).

2. Understanding Requirements, Architecture / Design


How will you capture requirements to design a new system?


Waterfall Model:
The waterfall model shows a process, where developers are to follow these phases in
1. Requirements specification (Requirements analysis)
2. Software design
3. Implementation and Integration
4. Testing (or Validation)
5. Deployment (or Installation)
6. Maintenance
2. What object modeling techniques will you use?
A technique for identifying objects within the systems environment and the relationships between
those objects is called OMT.

UML Modeling Tools

OMT is a predecessor of the Unified Modeling Language (UML). Many OMT modeling
elements are common to UML.

Functional Model in OMT: In brief, a functional model in OMT defines the function of the
whole internal processes in a model with the help of "Data Flow Diagrams (DFD's). It
details how processes are performed independently.
3. How will you find objects?

Objects can be accessed via object references. To invoke a method in an object, the object
reference and method name are given, together with any arguments.
A collection of objects or classes through which a program can be examine and manipulate
some specific parts of its world. In other words, the object-oriented interface is to some of
the service or system. Such an interface is said to be the object model of the represented
service or system.
4. What is use case, sequence, class collaboration diagrams?

5. How will you design a class?

6. How will you estimate amount of effort required to develop a module?

7. How will objects of different classes communicate?

8. How will you decide class hierarchy?

9. How will you decide object association, aggregation & composition?

10. What are meta classes in C++?

A Meta Class is a Class of a Class. i.e the objects of this class can act as classes for
themselves .
A Meta-Class is a class' class. If a class is an object, then that object
must have a class (in classical OO anyway). Compilers provide an easy way to

picture Meta-Classes. Classes must be implemented in some way; perhaps with

dictionaries for methods, instances, and parents and methods to perform all
the work of being a class. This can be declared in a class named "Meta-Class".
The Meta-Class can also provide services to application programs, such as
returning a set of all methods, instances or parents for review (or even

11. What are design patterns?

12. What are the different types of design patterns?

13. How will you decide which design pattern to use?

14. How will you evaluate your peers design?

15. What is class generation?

3. Basic of OOPS
1. What are the main oops concepts?

The concepts of Object oriented programming. Some of the important object

oriented features are namely:



Data Abstraction

Data Encapsulation




2. What is the data encapsulation?


Data Encapsulation combines data and functions into a single unit called Class.
When using Data Encapsulation, data is not accessed directly; it is only accessible
through the functions present inside the class. Data Encapsulation enables the
important concept of data hiding possible.
3. What does abstraction mean?

Abstraction is another good feature of OOPS. Abstraction means to show only the
necessary details to the client of the object. Lets say you have a method
"CalculateSalary" in your Employee class, which takes EmployeeId as parameter and
returns the salary of the employee for the current month as an integer value. Now if
someone wants to use that method. He does not need to care about how Employee
object calculates the salary? An only thing he needs to be concern is name of the
method, its input parameters and format of resulting member, Right?
So abstraction says expose only the details which are concern with the user (client)
of your object. So the client who is using your class need not to be aware of the inner
details like how you class do the operations? He needs to know just few details. This
certainly helps in reusability of the code.
4. What is the inheritance?

Inheritance is the process of forming a new class from an existing class or base class.
The base class is also known as parent class or super class. The new class that is
formed is called derived class. Derived class is also known as a child class or sub
class. Inheritance helps in reducing the overall code size of the program, which is an
important concept in object-oriented programming.
5. What are the types of inheritance?

1. Single inheritance
2.Multiple inheritances
3. Multi-path inheritance
4.Multi level inheritance
5.Virtual path inheritance

6.Hierarchical inheritance
7.Hybrid inheritance

What is the difference between object and class?

Classes and objects are separate but related concepts. Every object belongs to a class and
every class contains one or more related objects.
- A Class is static. All of the attributes of a class are fixed before, during, and after the
execution of a program. The attributes of a class don't change.
- The class to which an object belongs is also (usually) static.
If a particular object belongs to a certain class at the time that it is created then it almost
certainly will still belong to that class right up until the time that it is destroyed.
- An Object on the other hand has a limited lifespan. Objects are created and eventually
destroyed. Also during that lifetime, the attributes of the object may undergo significant

7. What is the polymorphism?
This ability of different objects to respond, each in its own way, to identical messages is
called polymorphism.
The names assigned within a class definition won't conflict with names assigned anywhere
outside it. This is true both of the instance variables in an object's data structure and of the
object's methods:
The main benefit of polymorphism is that it simplifies the programming interface. It permits
conventions to be established that can be reused in class after class. Instead of inventing a
new name for each new function you add to a program, the same names can be reused. The
programming interface can be described as a set of abstract behaviors, quite apart from the
classes that implement them.
class pen:
void draw(int x, int y)
class pen_thin extends pen:
void draw(int x, int y) { color(x, y) = green; }
class pen_thick extends pen:
void draw(int x, int y) { color(x, y) = green;
color(x, y+1) = green; }
and two objects:

8. How many types of polymorphism C++ have?

Answer: These are the 4 types of Polymorphism.

Virtual functions
Function name overloading
Operator overloading
Ad-hoc polymorphism
Parametric polymorphism
Other types of polymorphism defined:

9. What is the difference object base and object oriented programming?

4. Basics of C++
1. Constructors are defined with default constructor, constructors with one default
parameter and single argument constructor. What will be the output?
class base {
base () {};
base (int x = 10) {};
main () {
base b;

base b1 (5);
Compilation error: call of overloaded base () is ambiguous
Candidates are: base ::base(int)
2. Is it possible to overload the function with return type alone? What is the expected
consequence if we want to overload the function with return type alone?

3. How do you allocate memory for a double pointer?

Int **p1;
P1=new int*[size];
4. What is shallow copy and deep copy?

A shallow copy of an object copies all of the member field values. This works well if
the fields are values, but may not be what you want for fields that point to
dynamically allocated memory. The pointer will be copied, but the memory it points
to will not be copied -- the field in both the original object and the copy will then
point to the same dynamically allocated memory, which is not usually what you
want. The default copy constructor and assignment operator make shallow copies.
A deep copy copies all fields, and makes copies of dynamically allocated memory
pointed to by the fields. To make a deep copy, you must write a copy constructor and
overload the assignment operator; otherwise the copy will point to the original, with
disastrous consequences.
5. What is virtual destructor? Why it is required? Can we have a virtual constructor?

Any class that may act as the base of another class should have a virtual destructor.
This ensures that when an object of the derived class is destroyed that the derived
class dtor will be invoked to destroy it. If the destructor is not virtual, under some
common circumstances, only the base class' destructor will be invoked, regardless of
the class actually being destroyed. For practical purposes this means that a class
which does, could or should have virtual member functions, should also have a
virtual destructor.
base *b=new derived;

The purpose of virtual destructor (i.e. the purpose of making a destructor virtual) is
to facilitate the polymorphic deletion of objects through delete-expression. If your
design does not call for polymorphic deletion of objects, you don't need virtual
No Virtual Constructors are there
6. What are the differences between pass by pointer and reference?

7. Is it possible to do the copy constructor without reference? Explain


Because if it's not by reference, it's by value. To do that you make a copy, and to do that
you call the copy constructor. But to do that, we need to make a new value, so we call the
copy constructor,

8. What is meant by mutable key word? Explain explicit keyword and its usage also.

9. What is the difference between int* const i and const int* i

10. Use singleton pattern to ensure that maximum 5 objects of a class is created.

11. What is dynamic polymorphism? Explain a scenario where this is used.

12. What is dynamic_cast, static_cast, reinterpret_cast, const_cast?

13. How to create a user defined exception class? What is the result of the code scenario?
Class myException: public exception
Int fun1 ()
try {
Catch (exception &e)
Catch (myException &e)
14. What will happen when exception is not caught? What is a default catch all
exceptions type construct?

15. What is a friend class?


As the name suggests, the function acts as a friend to a class. As a friend of a class, it
can access its private and protected members. A friend function is not a member of
the class. But it must be listed in the class definition.

16. What is multiple inheritances and virtual inheritance?

17. Show an example of abstract base class.

18. How do you overload the default method of handling an exception that the program is
unable to handle?

19. How do you overload the default method of handling an exception that the program is
unable to handle?

20. Implement your own smart pointer.

Smart pointer (as opposed to a "dumb" or "raw" pointer) is a C++ structure that
behaves almost identically to a common C pointer but it also includes some other
capabilities, e.g. throws an exception when it's NULL and someone tries to
dereference it, or it destroys its contents automatically when it goes out of scope.
What are the basic implementation schemes for smart pointers?
In order to increase a pointer's IQ, you need to maintain somewhere some extra data
about the object that it points to. There are only 3 places that this data may be stored:
a) in the object itself
b) in the pointer
c) in some central depository

template <class T> class auto_ptr

T* ptr;
explicit auto_ptr(T* p = 0) : ptr(p) {}
{delete ptr;}
T& operator*()
{return *ptr;}
T* operator->()
{return ptr;}
// ...

21. What is the size of a blank class? Explain your answer.

22. Compare between vector and list in C++.


Vector: Dynamic array of variables, struct or objects. Insert data at the end.
List: Linked list of variables, struct or objects. Insert/remove anywhere.

23. What is a template function? Write an example. Will it work with class objects?

5. Data Structures Design & Usage

1. How do you implement Stack?

What identifies the data structure as a stack in either case is not the implementation
but the interface: the user is only allowed to pop or push items onto the array or
linked list
Program of Stack implementation:
struct node
int data;
struct node *link;

struct node *top=NULL,*temp;

void main()
int choice,data;
while(1)//infinite loop is used to insert/delete infinite
number of nodes
printf("\nEnter ur choice:");
case 1:
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter a node data :");
case 2:
printf("The poped element is %d",top->data);
printf("\nStack Underflow");
case 3:
printf("\nStack is empty\n");

case 4:

2. How do you implement Queue?

3. Implement a stack using linked list.

4. Implement a queue using linked list.

5. Implement a singly linked list with basic operations (insert, delete and print).

6. Reverse the linked list.

7. Finding loop in the linked list.

8. Finding middle node in the linked list.

9. Implement sorted linked list.

10. How to insert a node in the sorted linked list.

11. Implement a circular linked list.

12. Find the linked list is a circular list or not.

13. How to Merge two linked list.

14. Implement doubly linked list including (insert, delete, reverse) operations.

15. Implement binary search tree.

6. Debugging Skills and Exception Handling


How did you debug your program for errors (experience-specific)?

You can use gdb to get a backtrace of your program at the point where it segfaults
even though you did not build your application with the debug flags. This will at least
give you an idea where your application segfaults.
gdb <your_app_exe>
gdb> run
gdb> backtrace

gdb <your_app_exe>
gdb> core-file <generated_core_file>


What utilities/tools you used for debugging?


When you are assigned a bug what are the steps you would take to resolve it?


Viewing log file.


How did you analyze the memory dumps (experience-specific)?


How do you review your source code?


What are the components of make file?


What is exception?


How to throw an exception?

10. How to handle a thrown exception?

11. What is the default handler for handling all the exception?
12. In what order catch blocks should be designed?
13. What should you do when new memory is returning null?
14. How to specify that a function cannot throw any exception at all?

15. How to specify that a function can throw only exceptions of type int?


UNIX Skills
1. Basic Unix Commands
1. How to see all the process running in the system?
Type the following ps command to display all running process:
# ps aux | less

2. How to see all the files and directories?


ls -l
3. How to kill a process?
# kill pid
# kill -9 pid

Another method of killing a process is as follows:

# ps aux | grep name_of_process
At the command line type: kill -9 PID_Number_Here
You can also type:
# killall -9 name_of_process which will kill any process with
that name.
4. How to find a file, given its name?
Ans: ls file name
5. Cmd to find if a word is present or not in a file(s)
Answer: grep command
grep word_name file_name.txt

6. Cmd to replace a word present in the file.


To replace only the first instance of a word in a sentence the command looks like this
sed -i s/original_word/new_word/ file.txt
To change all instances of a word in a file the command is
sed -i s/original_word/new_word/g file.txt
7. What is hard link?

A hard link is essentially a label or name assigned to a file. Conventionally, we think

of a file as consisting of a set of information that has a single name. However, it is
possible to create a number of different names that all refer to the same contents.

Commands executed upon any of these different names will then operate upon the
same file contents.
To make a hard link to an existing file, enter:
Ln oldfile newlink
8. What is soft link?

Soft links (symbolic links): A soft link, also called symbolic link, is a file that
contains the name of another file. We can then access the contents of the other file
through that name. That is, a symbolic link is like a pointer to the pointer to the file's
contents. For instance, supposed that in the previous example, we had used the -s
option of the ln to create a soft link:
% ln -s a-file.txt b-file.txt

To make links between files you need to use ln command. A symbolic link (also
known as a soft link or symlink) consists of a special type of file that serves as a
reference to another file or directory. Unix/Linux like operating systems often uses
symbolic links.
9. How to print 3rd column of a file?
awk -F\| '{print $3}'
awk -F"|" '{print $3}'
10. How to sort a file?
sort input.txt -t, -k1,1 -k2,2

sort [options]... [file]
sort -r file.txt (Sort the file, file.txt in reverse order.)
11. How to find no. of lines in a file?
wc [-c | -m | -C ] [-l] [-w] [ file ... ].
wc -l (Count no. of lines in the file)
wc l < file.txt
12. How to find no. of words and characters in the file?
wc -w(Count no. of words in the file)
wc -m(Count no. of Character in the file)
wc -C(Count no. of Character in the file)
wc m < file.txt

13. How to delete blank lines in the file?

$ sed '/^$/d' input.txt > output.txt
$ grep -v '^$' input.txt > output.txt

14. How to see the status of all the processes?

To show all processes running on your system, at the prompt, type the following:
ps ef

Type the following ps command to display all running process:

# ps aux | less

15. How to display a file in the screen?

vi editor
$ cat view_this

2. Basic Scripting knowledge

1. What does $* stand for?

2. How will you list only the empty lines in a file (using grep)?

3. What are the different kinds of loops available in shell script?

4. /dev/null means?

5. How to check which shell we are using?

6. What is INODE?

Each file in UNIX has a unique number called as an inode. Using this number the
file information like user, group, ownership and access mode information can be
found. A files inode number can be found using the following command:

Ls i
If the inode number is known, the following command can be used to get details of
the file:
Ls l
7. How do you open a read only file in UNIX?

8. What is difference between thread and fork?

9. What is this line in the shell script do #!/bin/ksh?

10. What does $$ stand for?

11. How to extract the second row of a text-file?

12. How to compress files by using shell scripting?

13. How to receive command line arguments in shell script?

14. Whats the "nice" command used for?

15. What does $# stand for?

16. Whats the kill command used for? Whats the difference between kill and kill -9?

17. Explain nohup with an example?

18. In shell scripting How to indentify that the previous command was run successfully?


Database Skills
1. Basic SQL


What is SQL?
SQL: - Structured Query Language.
SQL is a special-purpose programming language designed for managing data in relational
database management systems (RDBMS), its scope includes data insert, query, update and
delete, schema creation and modification, and data access control.

2. What is the difference between DDL, DML?

Data Definition Language (DDL) statements are used to define the
database structure or schema. Some examples: CREATE - to create objects

in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for the
records are removed
COMMENT - add comments to the data dictionary
RENAME - rename an object
Data Manipulation Language (DML) statements are used for managing
data within schema objects. Some examples:

SELECT - retrieve data from the a database

INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain
MERGE - UPSERT operation (insert or update)
CALL - call a PL/SQL or Java subprogram
EXPLAIN PLAN - explain access path to data
LOCK TABLE - control concurrency

3. What is primary key & unique key? What is the difference between them?

The column holding the primary key constraint cannot accept null values. Whereas
column holding the unique constraint can accept null values assume that t3 is a table with
two columns t1 having primary key constraint and t2 having unique constraint if u try to
insert null into t2 it will accept that values whereas column t1 will not accept null.
Primary key does not allow null value but unique key allows null value. We can declare
only one primary key in a table but a table can have multiple unique key(column assign).
4. What is foreign key?

A foreign key is a field (or fields) that points to the primary key of another table. The
purpose of the foreign key is to ensure referential integrity of the data. In other words, only
values that are supposed to appear in the database are permitted.
5. What is join? Explain different types of join.

Joins are used in queries to explain how different tables are related.
Joins also let you select data from a table depending upon data from another table.
6. What is the difference between DELETE TABLE and TRUNCATE TABLE commands?

7. How do you get first 10 rows from a table?

8. What keyword does an SQL SELECT statement use for a string search?

9. Write a query to find max value of a column from a table.

10. List the entire employee getting salary in between 10000 to 15000.

11. Count the number of employees in IT department.

12. Use of distinct in queries.

13. How to sort a result based on a specified column.

14. Write a query to find the average value of a numeric column.

15. Find the Last value of a selected column.