30 ديسمبر 2020
26 ديسمبر 2020
Programing IN C++ : part 6
Programing IN C++
What is an explicit constructor?
A conversion constructor declared with the explicit keyword.
The compiler does not use an explicit constructor to implement an implied
conversion of types. Its purpose is reserved explicitly for construction.
What is the Standard Template Library?
A library of container templates approved by the ANSI
committee for inclusion in the standard C++ specification.
An applicant who then launches into a discussion of the
generic programming model, iterators, allocators, algorithms, and such, has a
higher than average understanding of the new technology that STL brings to C++
programming.
Describe run-time type identification.
The ability to determine at run time the type of an object
by using the typeid operator or the dynamic_cast operator.
What problem
does the namespace feature solve?
Multiple providers of libraries might use common global
identifiers causing a name collision when an application tries to link with two
or more such libraries. The name-space feature surrounds a library’s external
declarations with a unique namespace that eliminates the potential for those
collisions.
This solution assumes that two library vendors don’t use the
same namespace, of course.
Are there any
new intrinsic (built-in) data types?
Yes. The ANSI committee added the bool intrinsic type and
its true and false value keywords and the wchar_t data type to support
character sets wider than eight bits.
Programing IN C++: part 5
Programing IN C++
What are the access privileges in C++ ? What is the
default access level ?
The access privileges in C++ are private, public and
protected. The default access level assigned to members of a class is private.
Private members of a class are accessible only within the class and by friends
of the class. Protected members are accessible by the class itself and it’s
sub-classes. Public members of a class can be accessed by anyone.
What is data encapsulation ?
Data Encapsulation is also known as data hiding. The most
important advantage of encapsulation is that it lets the programmer create an
object and then provide an interface to the object that other objects can use
to call the methods provided by the object. The programmer can change the
internal workings of an object but this transparent to other interfacing
programs as long as the interface remains unchanged.
What is inheritance ?
Inheritance is the process of deriving classes from other
classes. In such a case, the sub-class has an ‘is-a’ relationship with the
super class. For e.g. vehicle can be a super-class and car can be a sub-class
derived from vehicle. In this case a car is a vehicle. The super class ‘is not
a’ sub-class as the sub- class is more specialized and may contain additional
members as compared to the super class. The greatest advantage of inheritance
is that it promotes generic design and code reuse.
What is multiple inheritance ? What are it’s
advantages and disadvantages ?
Multiple Inheritance is the process whereby a sub-class can
be derived from more than one super class. The advantage of multiple
inheritance is that it allows a class to inherit the functionality of more than
one base class thus allowing for modeling of complex relationships. The
disadvantage of multiple inheritance is that it can lead to a lot of confusion
when two base classes implement a method with the same name.
How is memory allocated/deallocated in C ? How about
C++ ?
Memory is allocated in C using malloc() and freed using
free(). In C++ the new() operator is used to allocate memory to an object and
the delete() operator is used to free the memory taken up by an object.
Programing IN C++ : part 4
Programing IN C++
What is a
conversion constructor?
A constructor that accepts one argument of a different type.
The compiler uses this idiom as one way to infer conversion
rules for a class. A constructor with more than one argument and with default
argument values can be interpreted by the compiler as a conversion constructor
when the compiler is looking for an object of the type and sees an object of
the type of the constructor’s first argument.
=--------------------------------------------------------------------------------
What is the
difference between a copy constructor and an overloaded assignment operator?
A copy constructor constructs a new object by using the
content of the argument object. An overloaded assignment operator assigns the
contents of an existing object to another existing object of the same class.
First, you must know that a copy constructor is one that has
only one argument, which is a reference to the same type as the constructor.
The compiler invokes a copy constructor wherever it needs to make a copy of the
object, for example to pass an argument by value. If you do not provide a copy
constructor, the compiler creates a member-by-member copy constructor for you.
You can write overloaded assignment operators that take
arguments of other classes, but that behavior is usually implemented with
implicit conversion constructors. If you do not provide an overloaded
assignment operator for the class, the compiler creates a default
member-by-member assignment operator.
-------------------------------------------------------------------------------
What is a
virtual destructor?
The simple answer is that a virtual destructor is one that
is declared with the virtual attribute.
The behavior of a virtual destructor is what is important.
If you destroy an object through a pointer or reference to a base class, and
the base-class destructor is not virtual, the derived-class destructors are not
executed, and the destruction might not be complete.
-------------------------------------------------------------------------------
When is a template a better solution than a base
class?
When you are designing a generic class to contain or
otherwise manage objects of other types, when the format and behavior of those
other types are unimportant to their containment or management, and
particularly when those other types are unknown (thus the genericity) to the
designer of the container or manager class.
Prior to templates, you had to use inheritance; your design
might include a generic List container class and an application-specific
Employee class. To put employees in a list, a ListedEmployee class is multiply
derived (contrived) from the Employee and List classes. These solutions were
unwieldy and error-prone. Templates solved that problem.
-------------------------------------------------------------------------------
What is the difference between C and C++ ? Would you
prefer to use one over the other ?
C is based on structured programming whereas C++ supports
the object-oriented programming paradigm.Due to the advantages inherent in
object-oriented programs such as modularity and reuse, C++ is preferred.
However almost anything that can be built using C++ can also be built using C.
Programing IN C++ : Part 3
Programing IN C++
Compare and
contrast C and C++.
Comparison: C++ is an extension to the C language. When C++
is used as a procedural language, there are only minor syntactical differences
between them.
Contrast: When used as a procedural language, C++ is a
better C because:
It vigorously enforces data typing conventions.
It allows variables to be defined where they are used.
It allows the definition of real (semantically significant)
constants.
It allows for automatic pointer dereferencing.
It supports call-by-reference in addition to call-by-value
in functions.
It supports tentative variable declarations (when the type
and location of a variable cannot be known before hand.
As an object oriented language, C++ introduces much of the
OOP paradigm while allowing a mixture of OOP and procedural styles.
------------------------------------------------------------------------------------
What is
operator overloading?
It is the process of, and ability to redefine the way an
object responds to a C++ operator symbol. This would be done in the object’s
class definition.
v---------------------------------------------------------------------------------
What is cin and
cout?
They are objects corresponding to a program’s default input
and output files.
---------------------------------------------------------------------------------
What are the
differences between a C++ struct and C++ class?
The default member and base class access specifiers are
different.
This is one of the commonly misunderstood aspects of C++.
Believe it or not, many programmers think that a C++ struct is just like a C
struct, while a C++ class has inheritance, access specifiers, member functions,
overloaded operators, and so on. Some of them have even written books about
C++. Actually, the C++ struct has all the features of the class. The only
differences are that a struct defaults to public member access and public base
class inheritance, and a class defaults to the private access specifier and
private base class inheritance. Getting this question wrong does not
necessarily disqualify you because you will be in plenty of good company.
Getting it right is a definite plus.
---------------------------------------------------------------------------------
What is a
default constructor?
A constructor that has no arguments or one where all the
arguments have default argument values.
If you don’t code a default constructor, the compiler
provides one if there are no other constructors. If you are going to
instantiate an array of objects of the class, the class must have a default
constructor.
---------------------------------------------------------------------------------
-
🖊🖊ગુજરાત ની 8 મહાનગર પાલિકાઓ યાદ રાખવા ની ચાવી:🖊🖊 "રાજુભા અમે જાસુ ગાંવ. રા= રાજકોટ ...
-
આપણો શબ્દવૈભવ * લોચન :-ચક્ષુ, આંખ, નયન, નેણ, દગ, નેત્ર, આંખ્ય, ઈક્ષણ , લિપ્સા, ચાક્ષુસ, આર્ક્ષ,નેન અવાજ :-રવ, ધ્વની, નિનાદ, શોર, ઘોઘાટ, ઘો...
-
▪️પ્રથમ એન્ગ્લો મૈસૂર વિગ્રહ ✔️અંગ્રેજો vs હૈદરઅલી ✔️પરિણામ: હૈદરઅલી નો વિજય ( મલબાર સંધી) ▪️દ્વિતીય એન્ગ્લો મૈસૂર વિગ્રહ ✔️અંગ્રેજો vs ...