Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63137272
main.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 18, 00:33
Size
2 KB
Mime Type
text/x-c
Expires
Mon, May 20, 00:33 (2 d)
Engine
blob
Format
Raw Data
Handle
17736250
Attached To
R7581 SP4E Homework
main.cc
View Options
#include <iostream>
#include <fstream>
#include <string>
#include "Series.hh"
#include "DumperSeries.hh"
#include <sstream>
#include <typeinfo>
using
UInt
=
unsigned
int
;
// Defining unsigned int as UInt
int
main
(
int
argc
,
char
**
argv
)
//Passing arguments when running the code from terminal
{
//Setting default values for the input arguments
//Argument 1: 0-> Compute arithmetic series; 1-> Compute Pi
int
arg1
=
1
;
//Argument 2: Number of iterations
int
arg2
=
10
;
//Argument 3: Frequency
int
arg3
=
1
;
//Argument 4: Delimiter
char
arg4
=
','
;
//Argument 5: 0-> Print to screen; 1->Print to file
int
arg5
=
0
;
//Argument 6: 0-> Precision of the output to the screen (in case of writing to the file always default)
int
arg6
=
5
;
std
::
stringstream
sstr
;
// In case there is an input through terminal to main, those values are passed to the variables in the following section:
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
sstr
<<
argv
[
i
]
<<
" "
;}
//Argument 1: 0-> Compute arithmetic series; 1-> Compute Pi
sstr
>>
arg1
;
//Argument 2: Number of iterations
sstr
>>
arg2
;
//Argument 3: Frequency
sstr
>>
arg3
;
//Argument 4: Delimiter
sstr
>>
arg4
;
//Argument 5: 0-> Print to screen; 1->Print to file
sstr
>>
arg5
;
//Argument 6 : Precision of the output to the screen
sstr
>>
arg6
;
// Using input arguments to decide whether Arithmetic series, or PI approximating series is used and whether output is to screen or to the file
if
(
arg1
==
0
)
{
// In this case object srs is casted from ComputeArhitmetic class
ComputeArithmetic
*
srs
=
new
ComputeArithmetic
;
if
(
arg5
==
0
)
{
//Nested for loop to decide whether the chosen series is output to screen or written to file
// Object "prt1"- > to print on a screen
PrintSeries
*
prt1
=
new
PrintSeries
;
// Setting precision using setPrecision method in case of printing to the screen
prt1
->
setPrecision
(
arg6
);
prt1
->
dump
(
srs
,
arg2
,
arg3
);
}
else
{
//Object "wrt1" -> to print to a file
WriteSeries
*
wrt1
=
new
WriteSeries
;
wrt1
->
dump
(
srs
,
arg2
,
arg3
,
arg4
);
}
}
else
{
// In this case object srs is casted from ComputePi class
ComputePi
*
srs
=
new
ComputePi
;
if
(
arg5
==
0
)
{
//Nested for loop to decide whether the chosen series is output to screen or written to file
// Object "prt1"z - > to print on a screen
PrintSeries
*
prt1
=
new
PrintSeries
;
// Setting precision using setPrecision method in case of printing to the screen
prt1
->
setPrecision
(
arg6
);
prt1
->
dump
(
srs
,
arg2
,
arg3
);
}
else
{
//Object "wrt1" -> to print to a file
WriteSeries
*
wrt1
=
new
WriteSeries
;
wrt1
->
dump
(
srs
,
arg2
,
arg3
,
arg4
);
}
}
}
Event Timeline
Log In to Comment