Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65779863
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
Thu, Jun 6, 04:21
Size
1 KB
Mime Type
text/x-c
Expires
Sat, Jun 8, 04:21 (2 d)
Engine
blob
Format
Raw Data
Handle
18126100
Attached To
R7571 SP4E-TB-TL-FR
main.cc
View Options
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <memory>
#include <ctgmath>
#include "arithmetic.hh"
#include "pi.hh"
#include "series.hh"
#include "print.hh"
#include "write.hh"
#include "dumper.hh"
/* -------------------------------------------------------------------------- */
int
main
(
int
argc
,
char
**
argv
)
{
// Parse arguments into stringstream
std
::
stringstream
sstr
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
sstr
<<
argv
[
i
]
<<
" "
;
}
// Argument 1: series type ("ar" or "pi")
std
::
string
seriestype
;
sstr
>>
seriestype
;
// Argument 2: number of iterations
unsigned
int
N
;
sstr
>>
N
;
// Argument 3: dump method ("print" or "write")
std
::
string
dumpmethod
;
sstr
>>
dumpmethod
;
// Argument 4 (conditional): frequency (for "print") or separator (for "write")
unsigned
int
freq
;
std
::
string
separator
;
if
(
dumpmethod
==
"print"
)
{
sstr
>>
freq
;
}
else
if
(
dumpmethod
==
"write"
)
{
sstr
>>
separator
;
}
// Instanciate appropriate series object
std
::
unique_ptr
<
Series
>
series
;
// doesn't point to anything yet
if
(
seriestype
==
"ar"
)
{
series
.
reset
(
new
ComputeArithmetic
);
}
else
if
(
seriestype
==
"pi"
)
{
series
.
reset
(
new
ComputePi
);
}
// Instanciate appropriate dumper object
std
::
unique_ptr
<
DumperSeries
>
dumper
;
// doesn't point to anything yet
if
(
dumpmethod
==
"print"
)
{
dumper
.
reset
(
new
PrintSeries
(
*
series
,
N
,
freq
));
}
else
if
(
dumpmethod
==
"write"
)
{
dumper
.
reset
(
new
WriteSeries
(
*
series
,
N
,
separator
));
}
// Dump series
dumper
->
dump
();
return
EXIT_SUCCESS
;
}
Event Timeline
Log In to Comment