3) Given that a class will have a pointer to memory that is allocated at run tim
ID: 3856054 • Letter: 3
Question
3)
Given that a class will have a pointer to memory that is allocated at run time, what
member methods
and/or operators will be needed to be written
(as a minimum)
and why?
4)
How does a programmer create
a function in C++ that will have default values for
parameters?
5)
Explain the uses of the “public”
and “private” key
words in class definitions (i.e.
what do each of the sections mean).
6)
Explain how to create and use a “template” class.
7)
Explain function over
loading.
8)
Explain the limitations of operator overloading.
9)
Explain the use of the keyword “explicit” in C++.
Explanation / Answer
1.Just the pointer will be in the part information area. Dynamic memory won't be physically in the protest,yet just connected by the part information pointer
#include <iostream>
using namespace std;
int main () {
double* pv = NULL;
pv = new double;
*pv = 66648.33;
cout << "Value of pv : " << *pv << endl;
delete pv;
return 0;
}
2.
In C++ programming, you can give default esteems to work parameters.
The thought behind default contention is basic. In the event that a capacity is called by passing contentions,those contentions are utilized by the capacity.
In any case, if the contentions are not passed while conjuring a capacity at that point, the default esteems are utilized.
Default esteems
Example:
void t(int=8,float=10.10)
int main(){
t(6);
}
void t(int i,float f){
some code here
}
5.
1.Public, implies all the class individuals proclaimed under open will be accessible to everybody. The information individuals and part works announced open can be gotten to by different classes as well. Consequently there are chances that they may transform them. So the key individuals must not be announced open
2.Private, implies that nobody can get to the class individuals proclaimed private outside that class. On the off chance that somebody tries to get to the private part, they will get an accumulate time mistake. As a matter of course class factors and part works are private.
6.Templates are a method for making your classes more theoretical by giving you a chance to characterize the conduct of the class without really realizing what datatype will be taken care of by the operations of the class. Generally, this is what is known as non specific programming; this term is a valuable approach to consider layouts since it reminds the developer that a templated class does not rely upon the datatype it manages. To a substantial degree, a templated class is more centered around the algorithmic idea instead of the particular subtleties of a solitary datatype. Formats can be utilized as a part of conjunction with dynamic datatypes to enable them to deal with an information. For instance, you could make a templated stack class that can deal with a pile of any datatype, as opposed to creating a stack class for each extraordinary datatype for which you need the stack to work. The capacity to have a solitary class that can deal with a few diverse datatypes implies the code is less demanding to keep up, and it makes classes more reusable.
The essential sentence structure for proclaiming a templated class is as per the following:
template <class a_type> class a_class{
}
7.
You can have various definitions for a similar capacity name in a similar extension. The meaning of the capacity must vary from each other by the sorts as well as the quantity of contentions in the contention list. You can not over-burden work announcements that vary just by return sort.
Following is the example where same function p() is being used to print different data types:
#include <iostream>
using namespace std;
class printData {
public:
void p(int l) {
cout << "Print int: " << l << endl;
}
void p(double k) {
cout << "Print flo: " << k << endl;
}
void p(char* m) {
cout << "Print char: " << m << endl;
}
};
8.
The limitations of operator overloading
::
->
.*
sizeof()
9.
The compiler is permitted to make one verifiable transformation to determine the parameters to a capacity. This means the compiler can utilize constructors callable with a solitary parameter to change over starting with one write then onto the next keeping in mind the end goal to get the correct sort for a parameter.
Here's a case class with a constructor that can be utilized for understood transformations::
class Ftt
{
public:
// i am showing the single parameter constructor,which can be can be use as implicit conversion
Fot (int ftt) : m_ftt (ftt)
{
}
int GetFtt () { return m_ftt; }
private:
int m_ftt;
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.