Divided classes appended them to one main

This commit is contained in:
2024-11-06 13:50:50 +01:00
parent 918246c55d
commit 677aa8a90f
2 changed files with 37 additions and 10 deletions

62
newton/Newton.cpp Normal file
View File

@@ -0,0 +1,62 @@
#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;
};