Question

In: Computer Science

What is the advantage of defining the member functions outside a class rather than defining inside...

What is the advantage of defining the member functions outside a class rather than defining inside a class?

How the following are achieved in C++?

a) static polymorphism.

b) dynamic polymorphism

What will happen if you forget to implement the pure virtual function in the derived class?

How a function templates differs from function overloading?

Solutions

Expert Solution

Now we will see the solution of each question one by one
Let take the first one
1. Functions can be defined or declared inside the class definition. But Many functions have very large defintion that makes it complex to readable.In this case we can define the class outside the class using scope resolution operator.
So the flexiblity of code is the biggest advantages

2. We know that Polymorphism means many form. Now here we have two types of polymorphism
a. Static polymorphism or we can say it as compile time polymorphism. Now this type of polymorphism can be achieved by function overloading and operator overloading.
In function overloading we have multiple function with same name but different parameters.
now in operator overloading we can make single operator to perform multiple operations.

b. Dynamic polymorphism is also called as run time polymorphism. And it can be achieved by function overriding.
In function overriding we have multiple function with same name and same arguments. but they are defined in different classes.

3. If you forget to implement the pure virtual function in the derived class, then derived class becomes the abstract class. while compilation we get a error like this:
  

Compiler Error: cannot declare variable 'variable_name' to be of abstract type 
'Derived'  because the following virtual functions are pure within
'Derived': virtual void Base::function_name() 

4. We know that both funtion overloading and template are the types of Polymorphism.Now template is better if we provide same action on different types.That means template can operate on any data.In function overloading we have multiple functions with same name and different arguments.
That means function overloading is used when multiple functions do similar operations. but in function template multiple functions do identical operation.

In case you face any difficulty for the soution, let me know in the comment section.

Related Solutions

Rather than play outside with friends, Aaron once preferred to sit inside watching TV and munching...
Rather than play outside with friends, Aaron once preferred to sit inside watching TV and munching on chips. As a result, he has become obese. He is now determined to lose excess weight with a reduced-calorie diet. Aaron is likely to have difficulty losing weight while dieting because a. low-calorie diets trigger increased secretions of leptin. b. his resting metabolic rate will increase and cause him to overeat. c. it takes less food intake to maintain fat than it did...
What is the advantage of using max wavelength rather than the wavelength nearby such as 580...
What is the advantage of using max wavelength rather than the wavelength nearby such as 580 nm? This is for the Bradford protein assay where the maximum of the absorbance spectrum is at 595 nm.
What is a major economic advantage of producing therapeutic proteins in plants rather than in bioreactors...
What is a major economic advantage of producing therapeutic proteins in plants rather than in bioreactors filled with microbes or mammalian cells?
If a cell has less concentration of solutes inside than outside, it is in a(n) ___________...
If a cell has less concentration of solutes inside than outside, it is in a(n) ___________ environment. Hypertonic Isotonic Hypotonic Mesotonic
The concentration of CO2 is lower inside a plant cell than in the atmosphere (outside the...
The concentration of CO2 is lower inside a plant cell than in the atmosphere (outside the cell). In your own words, describe how the CO2 levels are kept low inside the plant cell and explain why this is necessary. Assume the outer surface of the leaves of this plant have a waxy layer.
Which of the following is not an advantage of a company using equity rather than debt...
Which of the following is not an advantage of a company using equity rather than debt to finance a project? A. Interest always takes more cash than does paying dividends. B. Dividends do not need to be paid. C. Equity does not need to be repaid whereas debt does. D. Interest and Dividends are tax deductible. A note of caution in interpreting the debt ratio is that A. all debt decreases liquidity ratios. B. financing arrangements, such as leases, may...
class rather than ethnicity is responsible for stratification in the Caribbean.
class rather than ethnicity is responsible for stratification in the Caribbean.
In C++ please Your class could have the following member functions and member variables. However, it's...
In C++ please Your class could have the following member functions and member variables. However, it's up to you to design the class however you like. The following is a suggestion, you can add more member variables and functions or remove any as you like, except shuffle() and printDeck(): (Note: operators must be implemented) bool empty(); //returns true if deck has no cards int cardIndex; //marks the index of the next card in the deck Card deck[52];// this is your...
For this program you will add and test 2 new member functions to the class in...
For this program you will add and test 2 new member functions to the class in //************************ intSLList.h ************************** // singly-linked list class to store integers #ifndef INT_LINKED_LIST #define INT_LINKED_LIST class IntSLLNode { public: IntSLLNode() { next = 0; } IntSLLNode(int el, IntSLLNode *ptr = 0) { info = el; next = ptr; } int info; IntSLLNode *next; }; class IntSLList { public: IntSLList() { head = tail = 0; } ~IntSLList(); int isEmpty() { return head == 0; }...
Instructions Write the definitions of the member functions of the class integerManipulation not given in Example...
Instructions Write the definitions of the member functions of the class integerManipulation not given in Example 10-11. Also, add the following operations to this class: Split the number into blocks of n-digit numbers starting from right to left and find the sum of these n-digit numbers. (Note that the last block may not have n digits. If needed add additional instance variables.) Determine the number of zeroes. Determine the number of even digits. Determine the number of odd digits Also,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT