main cpp include iostream include culc hpp int main int std cout Input

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//main.cpp
#include <iostream>
#include "culc.hpp"
int main()
{
int n = 1;
std::cout<<"Input number of iteration"<<std::endl;
std::cin>>n;
Calc *c = new Calc(n);
c->Initalfaln();
c->Showalfa0();
delete c;
return 0;
}
//culc.hpp
#ifndef __CULC__
#define __CULC__
//#include <stdio.h>
#include <gmpxx.h>
#include <mpfr.h>
#include <vector>
#define NUM 1000
class Calc
{
public:
Calc();
Calc(int _n);
~Calc();
void Initalfaln();
void Showalfa0();
int n;
std::vector<mpfr_t> alfa0;
};
#endif
//culc.cpp
#include "culc.hpp"
Calc::Calc()
{
for(unsigned int i = 0; i < alfa0.size(); i++)
{
mpfr_clear(alfa0[i]);
}
}
Calc::Calc(int _n)
{
n = _n;
}
Calc::~Calc()
{
}
void Calc::Initalfaln()
{
long int x = 0;
mpfr_t y;
mpfr_init2 (y, NUM);
for(unsigned int i = 0; i < n; i++)
{
if(i%2==0)
{
x = 1;
}
else
{
x = -1;
}
mpfr_set_ui (y, i, MPFR_RNDD);
mpfr_si_div (y, x, y, MPFR_RNDD);
alfa0.push_back(y);
}
}
void Calc::Showalfa0()
{
for(unsigned int i = 0; i < alfa0.size(); i++)
{
mpfr_out_str(stdout, 10, 0, alfa0[i], MPFR_RNDD);
//std::cout<<std::endl;
}
}