Added template for Newton
And placed horner into horner/ folder
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
*.out
|
||||
4
newton/input.txt
Normal file
4
newton/input.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
1 2
|
||||
1.5 2.5
|
||||
2 3.5
|
||||
2.5 4
|
||||
69
newton/main.cpp
Normal file
69
newton/main.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Newton
|
||||
{
|
||||
public:
|
||||
void readFromFile(string filename)
|
||||
{
|
||||
string str;
|
||||
// stopien = 0;
|
||||
|
||||
fstream file(filename);
|
||||
if (!file)
|
||||
{
|
||||
cerr << "Nie udalo sie otworzyc pliku o nazwie: " << filename << "\n";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (getline(file, str))
|
||||
{
|
||||
std::istringstream iss(str);
|
||||
if (iss >> a >> b) {
|
||||
x.push_back(a);
|
||||
y.push_back(b);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void oblicz()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void wyswietl_x_y()
|
||||
{
|
||||
for (int i = 0; i < x.size(); i++)
|
||||
{
|
||||
cout << "x" << i << ": " << x[i] << "\t \t" << "y" << i << ": " << y[i] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void wyswietl_tabela()
|
||||
{
|
||||
std::cout << std::setw(5) << "i" << std::setw(10) << "x" << std::setw(10) << "y" << std::endl; // Table headers
|
||||
std::cout << std::string(26, '-') << std::endl;
|
||||
|
||||
for (size_t i = 0; i < x.size(); ++i)
|
||||
{
|
||||
std::cout << std::setw(5) << i << std::setw(10) << x[i] << std::setw(10) << y[i] << std::endl; // Table rows
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
float a, b;
|
||||
vector<float> x ,y;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
Newton first;
|
||||
first.readFromFile("input.txt");
|
||||
// first.wyswietl_x_y();
|
||||
first.wyswietl_tabela();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user