-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.hpp
139 lines (123 loc) · 2.81 KB
/
structs.hpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <sstream>
#include <iostream>
#include <cmath>
#include "gnuplot_i.hpp" // Biblioteka do sciagniecia na https://code.google.com/archive/p/gnuplot-cpp/
// Kompilujemy z warunkiem "-I."
#include <limits>
#include <vector>
#if defined(_WIN32) || defined(WIN32) || defined(__TOS_WIN__) || defined(__WIN32__)
#include <conio.h>
#endif
using namespace std;
//
// Program korzysta z programu GNUPlot 4.6
//
enum TrygonType{
sin
cos
tan
cot
};
void wait_for_key(){
#if defined(_WIN32) || defined(WIN32) || defined(__TOS_WIN__) || defined(__WIN32__)
cout << endl << "Press any key to continue..." << endl;
//FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
_getch();
#elif defined(__unix) || defined(unix) || defined(__APPLE__) || defined(__UNIX__)
cout << endl << "Press ENTER to continue..." << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cin.get();
#endif
return;
}
struct Wielomian{
int stopien;
double *wartosci;
stringstream function;
Wielomian();
void wczytaj();
~Wielomian(){delete[] wartosci;}
double policz(double);
void narysuj();
};
struct Trygon{
double a;
double policz(){
return sin(a);
}
};
struct Wyklad{
stringstream function;
double podst, mnoz, dod;
void wczytaj();
double policz(double);
void narysuj();
};
// ################
// ### FUNKCJE ###
// ################
Wielomian::Wielomian(){
int st;
cout<<"Podaj stopieñ wielomianu:";
cin>>st;
stopien = st;
wartosci = new double[st+1];
}
void Wielomian::wczytaj(){
cout<<"Podaj wartosci dla ka¿dego stopnia zmiennej Dla: \n";
cout << "wyrazu wolnego: ";
cin>>wartosci[0];
function << wartosci[0];
for(int i=1;i<=stopien;i++){
cout<<"x^"<<i<<":";
cin>>wartosci[i];
function << "+" << wartosci[i];
for(int j = 0; j <i; j++)
function << "*x";
}
return;
}
double Wielomian::policz(double x){
double wynik = 0;
for(int i=0;i<=stopien;i++){
wynik += pow(x,i)*wartosci[i];
}
return wynik;
}
void Wielomian::narysuj(){
Gnuplot plot;
plot.set_grid();
plot.set_style("lines").plot_equation(function.str()).plot_equation("0", "OX");
wait_for_key();
}
void Wyklad::wczytaj(){
cout<<"Funkcja postaci a*b^x+c.\nPodaj a:";
cin>>mnoz;
function << mnoz << "*";
cout<<"Podaj b:";
cin>>podst;
cout<<"Podaj c:";
cin>>dod;
return;
}
double Wyklad::policz(double x){
double wynik = mnoz * pow(podst,x) + dod;
return wynik;
}
void Wyklad::narysuj(double x,double y){
double i = -10;
vector<double> xtab,ytab,ptx,pty;
ptx.push_back(x);
ptx.push_back(y);
pty.push_back(policz(x));
pty.push_back(policz(y));
while((i+=0.0625)<10){
xtab.push_back(i);
ytab.push_back(policz(i));
}
Gnuplot plot;
plot.set_grid();
plot.set_style("points").plot_xy(xtab,ytab,"Wykres funkcji").plot_xy(ptx,pty,"Punkty");
wait_for_key();
}