Rational Rose Tools Interview Questions
..
..
aa
Differentiate the following functions as used in C++ programming language
Realloc() and free().
The free function free() is the function used to free a block of memory which has been allocated by the malloc() function. In event that we have non valid pointer parameter, we will end up having undefined results and should we leave a pointer parameter value as null value, then we should expect no action to occur.
The realloc() is used to change the sizes of the memory blocks which the pointer parameters are pointing into the number of bytes which have been specified by the size parameter and then returns a new pointer to the specified block. It is necessary that the pointer specified by the given pointer parameter be created with either the calloc(), malloc() or the realloc() subroutines and not have been deallocated by the free() or the realloc subroutines. As usual, we expect an undefined result error to occur in an event that the pointer parameter fails to be a valid pointer.
Describe what you understand by the term virtual constructors and destructors.
i) The virtual destructors - In event that an object which is having a non-virtual destructor is destroyed in an explicit manner by applying the delete operator on the base-class pointer regarding the object, the result is that the base class destructor function which matches the pointer type will be called on the object.
A simple solution exist regarding this, one is simply expected to declare the given the given base class as a destructor thereby yielding a scenario whereby all the derived – class destructors become virtual disregard the fact that they may not have the same name as the base class destructor. Then should an object in the hierarchy be destroyed in an explicit manner by application of the delete operator to the said base-class pointer to the object of the derived class, there arises a calling of the destructor for the given appropriate class.
ii) The virtual constructors: Constructors can never be virtual and an attempt to declare a constructor virtual arises in a syntax error.
Describe the advantages of inheritance in the object oriented programming, particularly C++
Allows for the code reusability which is the process by which a given code once used in a given program can be used in several other programs as well thus saving the programmers and designers time as well as allowing them to produced quality work as a tested code is used more than once thus testing time and efforts are reduced.
State the difference between definition and declaration in functions as used in C++ programming language.
The difference is that the declaration is used to pass information to the compiler that it should anticipate a definition of the given function, i.e. prepare it.
The following code can be used to illustrate what I am communicating.
Void stars() // this is a function declaration and it prepares the compiler that we are going to define the function soon.
The definition on the other hand consists of the entire implementation of the given function. Below is how it would be:
void stars () // This line is meant to declare the given function
{
for(int j=10; j>=0; j--) //this now
constitutes the function body
cout<<?*?;
cout<<endl;
}
It is important to notice that the function definition contains both the function header as well as the function body.
Differentiate between a class and an object.
There exist a small difference between a class and an object. This difference comes about by virtue that classes are static unlike the objects which are not static, one can observe that a given class has all its attributes fixed before the time of execution, during the time of execution and after the time of execution i.e. these attributes do not change.
It is also worth noting that objects are usually defined by some books as the variables of the datatype class or struct. Each and every object belongs to at least a given class and at the same time, each and every class contains at least one object.
The class in which these object belongs is always static under usual circumstances.
In an event that a particular object happens to belong to a particular class during the time of its creation, then chances are very high that this object will keep belonging to this class until the time when it will be destroyed.
It is also worth noting that an object usually bears a limited lifespan as they can be created, and destroyed eventually at any time, also their attributes do change significantly under normal circumstances unlike the classes whose attributes are always static.
What do you understand by the word namespace as used in C++ programming language?
Namespace is a feature in C++ programming language which allows users to group a given set of global classes, functions, objects or any other programming paraphernalia under one name, thus serving as a means for dividing the global scope into sub scopes which are as a result also referred to as the namespaces.
The following is the syntax for using the namespace
Namespace identifier
{
The body of the given namespace
}
Here, the term identifier is any identifier for as long as it is valid under the C++ programming language naming rules and the body of the given identifier is the group of classes, functions and even objects to be identified by the given namespace
The following is an example regarding what we are discussing here.
Namespace general
{
int d, e
}
In this example, d and e constitute normal variables which have been integrated within the general namespace. For one to get access to these variables while outside the given namespace, it is necessary that he uses the scope operator (::)
For instance to access the previous variable, we would proceed as follows:
general::d
general::e
The use of namespaces is always conspicuous in the cases where it is possible that particular global objects or functions have a common name with another one thus leading to redefinition errors
Describe what is meant by the term inline function.
The inline function is similar to the macros in C programming language. These are functions which are expanded in the line at which it is invoked during the compilation. It is essential that these functions include no loops or the any static members inside them and also they should not constitute of recursive functions. These functions should never return a value; they are used in the bid to avoid time wasting thus their advantage.
Here, the stack as well as the register operations is done at the time when the function is called and the keyword “inline” is usually included in its function definition.
The following example can be used as an illustration to what we are discussing here:
inline int add(int c,int d)
{
return c+d;
}
void main()
{
int u=5;
int v=10;
cout<<?The sum is : ?<<add(u,v);
}
Give a brief description regarding a structure and a class as used in C++ Programming Language.
In The C programming language, out of which the C++ programming language was derived, the type struct was used as a kind of datatype to bundle a collection of separate other datatypes together so as to be used to perform a certain function, for example they could be used to make a student record which could consist of the names of datatype char, the age of datatype int as well as the marital status which can be of datatype bool.
This was a very convenient way of coming up with such a solution, C++ now extends this notion to include functions as well and thus the sole difference between a class and a structure is that the type class contains both the functions as well as the data where as the struct (structure) datatypes contains data only thus the type class forms the basis of a new computer programming paradigm, the Object Oriented Programming whereby the Objects are defined in many books as the variables of the type class, hope you know how powerful this paradigm or technology is if at all you are a guru in computer programming, for the rest, just take it easy, this is the concept on which the powerful programming languages such as Java, C++, or any other language you hear people saying is based on Object Technology is based on, am not sure of PHP but I suspect as it is also derived from C programming language like Java and C++.
It is thus observable that the type class is a successor of the type struct and by default, all the members of the type class are private, I mean the access specifier, this can then be changed by the programmer to become either public or protected
Here is an explanation regarding these terms
1) Private – this access specifier tells that the proceeding members can only be accessed by the member functions in that particular class only thus helps in protecting the given data. This gives rise to another concept referred to as data abstraction which we will not discuss in this paragraph.
2) Public – this access specifier orders that the given underlying members be accessible even to members outside the class.
3) The protected access specifier is the kind of specifier used to allow only friend classes to access the member functions and data of a given class
Describe what you understand by the word template as used in the C++ programming language.
Templates are features in C++ which allow the programmers to create generic functions that can admit any datatype be its parameter and still return a value without having to wait for the use of functions overloaded with a combination of all the possible datatypes. They tend to fulfill the functionality of a macro at some level and can bear any of the following g as a prototype
template <class indetifier> function_declaration
or
template <typename indetifier> function_declaration;
Note that the difference between these prototypes is only the use of the keyword, either class or typename though they are used indistinctively as both expressions bear a similar meaning and exhibits common behavior.
What do you understand by the term RTTI as used in C++ programming language?
In C++ programming language, the term RTTI is used as an abbreviation of the term Runtime Type Information and sometimes even to refer to the term Runtime Type Identification which implies the innuendo of tracking information regarding data of a given object in the memory during the runtime, this runtime type of information can be regarding simple datatypes such as the int, char or even generic objects.
When objects are involved, some of the implementations are usually limited to maintaining the inheritance tree and others help contain the information regarding the methods and attributes of the given object.
The RTTI technique is available in many computer programming languages, RTTP as a term is used particularly in C++. The RTTI must be enabled so that the typeid operator, the dynamic_cast<> operation or the exceptions to operate properly in C++
Define Encapsulation as a term used in C++ programming language.
Encapsulation as used in C++ programming language is a form of protective wrapper used in protecting the data from access to codes that are outside the particular wrapper and requires that the given code in that particular wrapper be accessed using a well defined and approved interface. An example include a class which is usually a protective wrapper that helps in binding the data as well as functions together so that they are accessible only through a well defined interface which usually is an object of the given class
Describe what you understand by the term pure virtual functions as used in the C++ programming language.
The term pure virtual function refers to the functions for which we cannot create objects. These are functions which are usually declared in the base class and then equated to zero and thus can be defined only in derived classes and never in any base class. Abstract class is a class which contains virtual functions.
Below is an example:
class base
{
public:
void disp()=0;
};
class derivedOne : public baseOne
{
public:
void disp()
{
}
};
What do you understand by the term Scope Resolution Operator as used in C++ programming language?
This is the operator (:) and is used to define a member function of a given class outside the particular class.
Describe what you understand by the term polymorphism as used in the C ++ programming language or any other object oriented programming language.
As usual and with no exception, poly means many and morph is the word synonymous to form, most likely in Greek and thus the combination has an obvious meaning, many forms and this transferred literally to C++ as a programming language. This implies the ability of a given object or a reference to either assume or be replaced by or just become many different other forms of the same object. Example is the case of function overloading or the case of function overriding or even the case of virtual functions, another example of polymorphism is the use of a plus (+) which can take the form to represent addition of two integers and in other occasions take the form to imply the concatenation of two strings depending on of how appropriately it is used.
Explain the use of the word object as used in the C++ programming language.
An object is a representation of a real life entity in C++ which contains both the data and the functions to act on that data. It is sometimes described as the variables of the class datatype.
Describe the terms operator overloading and function overloading as used in C++ programming language.
i) Function overloading in C++ is the feature which enables a set of functions having the same name to be defined provided these functions have a separate set of parameters regarding at least on of the following - the datatypes or the number of arguments to be used. This is the capability referred to as function overloading and in an event that an overloaded function is called, the compiler is charged with the task of selecting the appropriate function basing on the types of the given arguments as well as the given order of the provided arguments. This attribute is used to create different functions having the same name that are capable of performing similar tasks but on different datatype.
ii) Operator overloading on the other hand allows existing C++ operators to be redefined so as to perform specific tasks in objects in user defined classes. These can always be considered syntactic sugar for the given equivalent function calls as they simply form a relatively pleasant façade which adds nothing fundamental to the language apart from improving the code readability thus making the code maintenance easier
Describe the terms constructor and destructor as used in C++ programming language.
In C++ programming language, the word constructor is used to refer to a function which bears the same name as the given class and generally returns no type as it is a special form of a function. This function is usually automatically invoked in an event of a creation of an object of the said class and thus automatically initializing the objects or the object variables.
The term destructor also do bear the same name as the class but is usually preceded by a tilda (~) symbol and it is used to destroy or just free the memory which had been allocated previously in event that the said object is destroyed.
It is also called automatically when the given object is destroyed.
Describe the meaning of the term inheritance as used in object oriented programming languages such as C++.
The term inheritance as used in object oriented programming languages including C++ has an analogy to the real life inheritance where a decedent gets a given property from a parent. In Programming language such as C++, this term implies or refers to the process of creating new classes referred to as the derived classes from some other existing classes, which are eferred to as the base classes. These so called derived classes do inherit the capabilities of the existing or base class and can then add a few other embellishments as well as its own refinements.
Describe what you understand by the term virtual function.
A virtual function is a special type of function in C++ which gives the capability to derived functions to replace the implementation that the base classes provide. The compilers are always there to make sure that the said replacement is called each and every time the given object has been confirmed to be of the derived class even in the situations where the object has been accessed via the base pointer as opposed to the derived pointer thus allowing the algorithms in the base class to be replaced by those in the derived class even in a situation where the programmer has got no information regarding the derived class.
Describe the terms friend class and the term virtual class.
Friend classes are classes used in C++ in a situation whereby two or more classes have been designed which need to work together thereby accessing one another’s implementation in a unique manner that other classes are not allowed to thus the two share private information that other classes are not thus still keeping private information private but public only between the two of them. An example is the application to implement a situation where a class, says, DatabaseCursor class is to be set to have more privileges regarding the access of the private parts of another class in the Database than the main() should access, hope this explanation is satisfactory.
Give the difference between the terms delete and Destructor as used in C++ programming language.
The delete can be used to deallocate memory of objects created using the new operator while the destructor can delete any object as long as the life of the given object has ended which usually occurs when the program ends.
Describe the following terms as used in C++ programming language regarding the access specifiers – Public, Protected and Private.
i) Public is the access specifier whose data members and functions can be accessed outside the given class.
ii) Protected access specifier offers access to the member data and function only to the derived classes.
iii) Private access specifier provides no access to member functions and data outside the given classes. The only exception to this rule is with the friend classes which can access the friend class’ private functions
Describe the term abstraction as used in C++ programming language.
Abstraction is essentially the process or the outcome of hiding unnecessary details to any given user or programmer. This is used to assist the programmer use some predefined objects without the need to know the implementation as long he is aware of the interface and thus saves time as the programmer needs not to spend so much time learning the implementation of the objects which are already in the market which will not add an inch to his competency as the most important thing is to come up with a working system under optimal design and also the use of these abstraction allows the programmer direct his efforts to more complicated details of the project other than doing what other people have already done and hence been paid for thus redesigning the wheel is avoided
Is it possible for one to make a C++ program without the use of any header file?
Write the shortest program in C++.
It is worth noting that a C++ program cannot run without a header file being included, this panorama is left for the C Programming Language as it is the language that can execute without a header file.
The shortest C++ program could be
#include<iostream.h>
int main()
{
return 0;
}
Note that this program runs and performs just nothing a normal human being can benefit from.
Where do we use pointers and where do we use pointers? State the difference between the two.
The above tow questions are answered in the following lines
1) Unlike a pointer, a reference is a constant and once initialized can not be bound to any other different object
2) Pointers do not have to be initialized whereas the reference have to be initialized
3) It is mandatory that a reference points to a valid object unlike a pointer which can point to a null object
4) Under normal circumstances, a reference will be automatically be dereferenced unlike a pointer which one has to use the dereference operator (*) to dereference it.
5) One can not create a reference to another reference whereas a pointer can be created to point to another pointer
6) As opposed to a pointer, a reference is usually used like there is an object bound to it thus the particular member under reference is accessed using the dot operator.
photo