(SP4E 2018, Homework 2)<br/> Authors: Sajjad Azimi, Alessia Ferraro
The main.cc program is written to compute numerical series, arithmetic and pi series, and write the results either on the screen or on a specified file. the project makes use of the OOP concepts like encapsulation, modularity and inheritance and it consists of two interfaces and four derived classes:
- Series: Numerical interface for the computation of a generic series. It is an abstract class containing virtual methods,
whose only effective task is to add terms.
- ComputeArithmetic: Class for the computation of arithmetic series. It derives from the interface Series and contains
the specific implementation for the terms'evaluation.
- ComputePi: Class for the computation of Pi via series. It derives from the interface Series and contains the specific
implementation for the terms' evaluation.
- DumpSeries: Interface for dumpers.
- WriteSeies: Class to output the results of series computation on a file specified by the user.
- PrintSeries: Class to to output the results of series computation on the screen (default) or on a specified ostream.
Because of the modular structure of the project, the work was naturally divided between the two authors as follows:
- Alessia Ferraro: Implementation of the Series related classes and functions (exercises 2 and 5)
- Sajjad Azimi: Implementation of the Dumper related classes and functions (exercises 3 and 4)
The main program, as well as the small adjustments to the common methods, were implemented together in order to achieve a uniform structure.
To run the main the user has to provide the following arguments in the following order:
|1||string||series type||pi, arithmetic|
|2||string||series dumper||print, write|
|5||int||precision||needed only if the dumper is print|
|6||string||separator||comma, space, tab, pipe||needed only if the dumper is write|
|7||string||filename||needed only if the dumper is write|
The following command line will compute the pi series and output the results to the screen with frequency 10, maximum number of iteration 100 and precision of 6 digits.
main pi print 10 100 6
The following command line will compute the arithmetic series with the same values of frequency and maximum number of iteration as above, and write the results on the file data.txt using tab separators between columns.
main arithmetic write 10 100 tab data.txt
To plot the data which are produced by the 'write' dumper, the user should run the python script 'plot.py' with the following arguments: <br/>
- the file name generated by the main program
- the separator used to generate the output file.
For example: python ../plot.py data.txt tab