This repository has been archived on 2025-01-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
MO_pracadomowa/newton/main.cpp
hamx01 918246c55d Added template for Newton
And placed horner into horner/ folder
2024-11-06 13:45:02 +01:00

69 lines
1.4 KiB
C++

#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;
}