Académique Documents
Professionnel Documents
Culture Documents
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:
// public member function
int f() { return a = 5; };
};
struct Y {
// public by default
int f() { return a = 5; };
private:
// private data member
int a;
};
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;
};
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.
};
integer:: integer (int x, int y)
{
m=x; n=y;
}
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.
A();
A( A const & other );
// ...
};
// Default constructor
// Copy constructor
Waterfall Model:
The waterfall model shows a process, where developers are to follow these phases in
order:
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?
Answer:
A technique for identifying objects within the systems environment and the relationships between
those objects is called OMT.
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?
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
3. Basic of OOPS
1. What are the main oops concepts?
Answer:
Objects
Classes
Inheritance
Data Abstraction
Data Encapsulation
Polymorphism
Overloading
Reusability
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?
Answer:
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?
Answer:
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?
Answer:
1. Single inheritance
2.Multiple inheritances
3. Multi-path inheritance
4.Multi level inheritance
5.Virtual path inheritance
6.Hierarchical inheritance
7.Hybrid inheritance
6.
change.
7. What is the polymorphism?
Answer:
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:
pen_thin(p1)
pen_thick(p2)
Virtual functions
Function name overloading
Operator overloading
Run-time
Compile-time
Ad-hoc polymorphism
Parametric polymorphism
Other types of polymorphism defined:
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 {
public:
base () {};
base (int x = 10) {};
};
main () {
base b;
base b1 (5);
}
Output:
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?
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?
Answer:
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;
delete(b);
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
destructors.
No Virtual Constructors are there
6. What are the differences between pass by pointer and reference?
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.
10. Use singleton pattern to ensure that maximum 5 objects of a class is created.
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?
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.
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?
Answer:
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
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?
Describe.
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:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node
{
int data;
struct node *link;
};
while(temp!=NULL)
{
printf("->%d->",temp->data);
temp=temp->link;
}
break;
case 4:
exit(0);
}
}
2. How do you implement Queue?
5. Implement a singly linked list with basic operations (insert, delete and print).
14. Implement doubly linked list including (insert, delete, reverse) operations.
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
or
gdb <your_app_exe>
gdb> core-file <generated_core_file>
2.
3.
When you are assigned a bug what are the steps you would take to resolve it?
4.
5.
6.
7.
8.
What is exception?
9.
15. How to specify that a function can throw only exceptions of type int?
II.
UNIX Skills
1. Basic Unix Commands
1. How to see all the process running in the system?
Ans:
Type the following ps command to display all running process:
# ps aux | less
ls -l
3. How to kill a process?
Ans:
# kill pid
OR
# kill -9 pid
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?
Answer:
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?
Answer:
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?
Answer:
awk -F\| '{print $3}'
otherwise,
awk -F"|" '{print $3}'
10. How to sort a file?
sort input.txt -t, -k1,1 -k2,2
OR,
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
To show all processes running on your system, at the prompt, type the following:
ps ef
2. How will you list only the empty lines in a file (using grep)?
4. /dev/null means?
6. What is INODE?
Answer:
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?
16. Whats the kill command used for? Whats the difference between kill and kill -9?
18. In shell scripting How to indentify that the previous command was run successfully?
III.
Database Skills
1. Basic SQL
1.
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.
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:
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?
Answer:
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.
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs, SELF JOINs.
OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS
and FULL OUTER JOINS.
6. What is the difference between DELETE TABLE and TRUNCATE TABLE commands?
8. What keyword does an SQL SELECT statement use for a string search?
10. List the entire employee getting salary in between 10000 to 15000.