[Program Comprehension]
Implement three classes with the following requirements:
class Base: a template TTsATs[]s[]s[]TTTTarr[]
3.[Program Comprehension]
Time left 1:57:54 Hide
Implement three classes with the following requirements: class Base:a template<class T>class with the following members:
osetT s[]:a public function assigning values to arr[]with s[] Shallowelement-wisecopy is enough ogetArr:a public function that returms the base address of arr[]
class A is not a template.It (public inherits class Base and specifies T as int with only one member: osetint s[]:a public function assigning values to arr[] stored in class Base with s[] class B is not a template.It (public inherits class Base and specifies T as char with only one member: osetchar s[]:a public function assigning values to arr[] stored in class Base with s[]
Do NOT change any identifiers given above and Do NOT add any extra members You can assume the size of all the arrays are fixed as 5 For simplicity, you can implement all member functions in the class directly
Thenimplementatemplate <class T>function void shortestPalin(T arr(]) to generate the shortest palindrome of a T array by appending suitable patterms at the end of the array. We set the template T as char toexplain more details. In this case, a char array is regarded as a palindrome when the char array reads the same forward and backward, e.g. ffttf andabcba Given a char array,we generate the shortest palindrome by adding zero or several chars at its end as follows If this array is already a palindrome, no zero character needs to be added and the smallest palindrome is itself.For example,levelandare such arrays. If this array is not a palindrome, we add the smallest number of extra characters at its end.For example,the shortest palindrome ofcomeiscomemoc,by addingmoc at the end of the char array "come".
Hint-l: you can first find the longest sub-palindrome starting from the ending of the array to decide what patterms should be appended.
Hint-2: you may define extra functions to generate the shortest palindrome
In Q3O, first choose to enter integers or chars. Then read 5 values to create an object of class A or B.Then utilize the template function implemented above to find and print the shortest palindrome of arr[] stored in the object.
Note: you can directly print the shortest palindrome in function shor te st Pa lin(T arr[ without any returm values. Example-1Inputs are underlined h.in+:2char
Scanned with Cam
Example-1Inputs are underlined h: int; 2:char
Time left 1:57:36Hide
Enter 5 integers: 2345 The shortest palindrome of the given array is: 23454321
Example-2(Inputs are underlined: int;2:char
Enter 5 chars: eoll The shortest palindrome of the given array is: eolloeh