Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Tabul {
- private:
- double step; // Параметр для функций
- double start,
- end;
- void sinX() {
- cout << "Введите диапазон [-1, 1]: ";
- cin >> start >> end;
- std::cout << "Введите шаг: ";
- std::cin >> step;
- std::cout << '\n';
- for (double x = start; x <= end; x += step) {
- double y = sin(x);
- cout << "sin(" << x << ") = " << y << '\n';
- }
- std::cout << '\n';
- }
- void cosX() {
- cout << "Введите диапазон [0, 1]: ";
- cin >> start >> end;
- std::cout << "Введите шаг: ";
- std::cin >> step;
- std::cout << '\n';
- for (double x = start; x <= end; x += step) {
- double y = cos(x);
- cout << "cos(" << x << ") = " << y << '\n';
- }
- std::cout << '\n';
- }
- void arctgX() {
- cout << "Введите диапазон [-2 , 2]: ";
- cin >> start >> end;
- std::cout << "Введите шаг: ";
- std::cin >> step;
- std::cout << '\n';
- for (double x = start; x <= end; x += step) {
- double y = atan(x);
- cout << "arctg(" << x << ") = " << y << '\n';
- }
- std::cout << '\n';
- }
- void arcctgX(){
- cout << "Введите диапазон [0, 1]: ";
- cin >> start >> end;
- std::cout << "Введите шаг: ";
- std::cin >> step;
- std::cout << '\n';
- for (double x = start; x <= end; x += step) {
- double y = atan(1/x);
- cout << "arcctg(" << x << ") = " << y << '\n';
- }
- std::cout << '\n';
- }
- void lnX() {
- cout << "Введите диапозон (0, 10]:";
- cin >> start >> end;
- cout << "Введите шаг: ";
- cin >> step;
- cout << '\n';
- for (double x = start; x <= end; x += step){
- if (x <= 0) {
- std::cerr << "Error: ln(x) is undefined for x <= 0\n";
- break;
- }
- double y = log(x);
- cout << "log(" << x << ") = " << y << '\n';
- }
- cout << '\n';
- }
- public:
- void doTask() {
- int temp;
- std::cout << "Какую функцию Вам нужно протабулировать:\n";
- std::cout << "sin(x) : 1\n";
- std::cout << "cos(x) : 2\n";
- std::cout << "arctg(x) : 3\n";
- std::cout << "arcctg(x) : 4\n";
- std::cout << "log(x) : 5\n";
- std::cout << '\n';
- std::cin >> temp;
- switch (temp) {
- case 1 : sinX();
- break;
- case 2 : cosX();
- break;
- case 3 : arctgX();
- break;
- case 4 : arcctgX();
- break;
- case 5 : lnX();
- break;
- default : std::cout << "Неправильный ввод\n";
- break;
- }
- }
- };
- int main() {
- char cont = 'y';
- while (cont == 'y') {
- Tabul task;
- task.doTask();
- std::cout << "\nЖелаете продолжить? y/n\t";
- std::cin >> cont;
- }
- return 0;
- }
- /// sin(x)
- /// cos(x)
- /// arctg(x)
- /// arcctg(x)
- /// ln(x)
- /*
- f(x) = x^2
- f(x) = x^3
- f(x) = |x| // abs()
- f(x) = ax^2 + bx + c
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement