2. (Extending the PBD Design of Section 9.3.3) We ask some questions regarding the code in Section...
Question:
2. (Extending the PBD Design of Section 9.3.3)
We ask some questions regarding the code in Section 9.3.3. The objective is to extend and modify the code in order to get hands-on experience with a small system before moving to more complex applications in computational finance that we discuss in later chapters.
Answer the following questions:
a) Generalise the code so that it works with any data type and not just with strings. Furthermore, the input data type T1 is not necessarily the same as the output data type T2 and hence the converter becomes a class that maps instances of T1 into instances of T2. You will need to use template–template parameters:
template
class SUD : private Source
{ // System under discussion
// TBD
}
Implement the code and test it with scalar and composite data types.
b) In this part we implement the converter using a universal function wrapper that will be a data member of the SUD, namely an instance of std::function
Implement the code. Is this a more flexible solution than in part
a) and if so in what respect? In particular, implement the converter functionality using free functions, lambda functions, static member functions, function objects and binded member functions.
c) Modify the original code to support a new requirement: system S1 opens a file and processes each of its records, system S3 converts the record’s strings to trimmed uppercase strings and system S4 writes the strings into a new file. (Refer to Figure 9.4; you can ignore systems S2 and S5 for the moment.)
Step by Step Answer: