Base on the following: Class template : class EBase{ //class defination }; class
ID: 3837869 • Letter: B
Question
Base on the following:
Class template :
class EBase{
//class defination
};
class E1 : public EBase {
//class defination
};
class E2 : public EBase {
//class defination
};
template <class T>
class CT {
T E;
//STL and other codes
};
Mian function :
void main(){
CT<E1> CT1;
CT<E2> CT2;
}
_____________________
answer:
Objective: Generic Algorithms
A) This part will add an additional method to both C1 and C2, and also to CT. The method will wrap one of the Generic Algorithms, find or search - the signature will be provided, or can be looked up at cplusplus.com. As you recall, Generic Algorithms rely on the Iterator concept, but often only implicitly by making use of being()and end() methods attached to the container they operate on. [3-5 lines of code to write in C1 and C2]
B) Add a matching method to CT class template [3-5 lines of code in CT]
C) The success of the Generic Algorithm find depends on what operation being present in the objects held in the container? What about search?
D) Write code for this operation. (Hint: this code can live in the base class EBase)
Explanation / Answer
The specification of a generic package:
generic
type Elem is private; -- parameter
package Stacks is
type Stack is private;
procedure Push (X : Elem; On : in out Stack);
…
private
type Cell;
type Stack is access Cell; -- linked list representation
type Cell is record
Val : Elem;
Next : Ptr;
end record;
end Stacks;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.