C++ Исходник Калькулятор

feel irl
Участник
Статус
Оффлайн
Регистрация
21 Дек 2018
Сообщения
677
Реакции[?]
294
Поинты[?]
16K
Код:
#include <iostream>
#include <math.h>
#include <cmath>
#include <sstream>
using namespace std;
double cot(double x) {
    return 1 / tan(x);
}
double fbeta(double x,double y) {
    return tgamma(x) * tgamma(y) / tgamma(x + y);
}
double coth(double x) {
    return  1/tanh(x);
}
string problem(double x) {
    std::ostringstream strs;
    strs << x;
    std::string str = strs.str();
    if (x >= 0)
        return "+" + str;
    if (x < 0)
        return "-" + str;

}


int main()
{
    double a, b;
    cin >> a;
    cin >> b;
    system("cls");
    cout << "sum: " << "\n" << a + b << "\n";
    cout << "dif: " << "\n" << a - b << "\n";
    cout << "op: " << "\n" << a*b << "\n";
    cout << "op^-1: " << "\n" << 1/a * 1/b << "\n";
    cout << "bop: " << "\n" << a / b << "\n";
    cout << "bop^-1: " << "\n" << b / a << "\n";
    cout << "exp a,b: " << "\n" << exp(a) << "," << exp(b) << "\n";
    cout << "sum exp: " << "\n" << exp(a + b) << "\n";
    cout << "dif exp: " << "\n" << exp(a - b) << "\n";
    cout << "op exp: " << "\n" << exp(a * b) << "\n";
    cout << "bop exp: " << "\n" << exp(a / b) << "\n";
    cout << "sum sin: " << "\n" << sin(a + b) << "\n";
    cout << "dif sin: " << "\n" << sin(a - b) << "\n";
    cout << "op sin: " << "\n" << sin(a * b) << "\n";
    cout << "bop sin: " << "\n" << sin(a / b) << "\n";
    cout << "sum cos: " << "\n" << cos(a + b) << "\n";
    cout << "dif cos: " << "\n" << cos(a - b) << "\n";
    cout << "op cos: " << "\n" << cos(a * b) << "\n";
    cout << "bop cos: " << "\n" << cos(a / b) << "\n";
    cout << "sum tan: " << "\n" << tan(a + b) << "\n";
    cout << "dif tan: " << "\n" << tan(a - b) << "\n";
    cout << "op tan: " << "\n" << tan(a * b) << "\n";
    cout << "bop tan: " << "\n" << tan(a / b) << "\n";
    cout << "sum cot: " << "\n" << cot(a + b) << "\n";
    cout << "dif cot: " << "\n" << cot(a - b) << "\n";
    cout << "op cot: " << "\n" << cot(a * b) << "\n";
    cout << "bop cot: " << "\n" << cot(a / b) << "\n";
    cout << "gamma a,b: " << "\n" << tgamma(a) << "," << tgamma(a) << "\n";
    cout << "gamma a+b: " << "\n" << tgamma(a+b) << "\n";
    cout << "gamma a-b: " << "\n" << tgamma(a - b) << "\n";
    cout << "gamma op: " << "\n" << tgamma(a * b) << "\n";
    cout << "loggamma a,b: " << "\n" << lgamma(a) << "," << tgamma(a) << "\n";
    cout << "loggamma a+b: " << "\n" << lgamma(a + b) << "\n";
    cout << "loggamma a-b: " << "\n" << lgamma(a - b) << "\n";
    cout << "loggamma op: " << "\n" << lgamma(a * b) << "\n";
    cout << "beta a,b: " << "\n" << fbeta(a,b) << "\n";
    cout << "beta a,b ^-1: " << "\n" << 1/fbeta(a, b) << "\n";
    cout << "a^b: " << "\n" << exp(b*log(a)) << "\n";
    cout << "(a^b)^-1: " << "\n" << 1/exp(b * log(a)) << "\n";
    cout << "b^a: " << "\n" << exp(a * log(b)) << "\n";
    cout << "(b^a)^-1: " << "\n" << 1 / exp(a * log(b)) << "\n";
    cout << "ln(a),ln(b): " << "\n" << log(a) << "," << log(b) << "\n";
    cout << "ln(a*b),ln(a/b): " << "\n" << log(a*b) << "," << log(a/b) << "\n";
    cout << "ln((a*b)^-1),ln(b/a): " << "\n" << log(1/a * 1/b) << "," << log(b / a) << "\n";
    cout << "log_a(b), log_b(a): " << "\n" << log(b)/log(a) << "," << log(a)/log(b) << "\n";
    cout << "a!,b!: " << "\n" << tgamma(a+1) << "," << tgamma(b + 1) << "\n";
    cout << "(a+b)!,(a-b)!: " << "\n" << tgamma(a+b+1) << "," << tgamma(a-b+1) << "\n";
    cout << "(a*b)!,(a/b)!,(b/a)!: " << "\n" << tgamma(a * b + 1) << "," << tgamma(a / b + 1) << "," << tgamma(b / a + 1) << "\n";
    cout << "sinh(a),sinh(b): " << "\n" << sinh(a) << "," << sinh(b) << "\n";
    cout << "sinh(a+b),sinh(a-b): " << "\n" << sinh(a+b) << "," << sinh(a-b) << "\n";
    cout << "sinh(a*b),sinh(a/b),sinh(b/a): " << "\n" << sinh(a * b) << "," << sinh(a / b) << "," << sinh(b/a) <<"\n";
    cout << "sinh((a*b)^-1): " << "\n" << sinh(1/a * 1/b) << "\n";
    cout << "cosh(a),cosh(b): " << "\n" << cosh(a) << "," << cosh(b) << "\n";
    cout << "cosh(a+b),cosh(a-b): " << "\n" << cosh(a + b) << "," << cosh(a - b) << "\n";
    cout << "cosh(a*b),cosh(a/b),cosh(b/a): " << "\n" << cosh(a * b) << "," << cosh(a / b) << "," << cosh(b / a) << "\n";
    cout << "cosh((a*b)^-1): " << "\n" << cosh(1 / a * 1 / b) << "\n";
    cout << "tanh(a),tanh(b): " << "\n" << tanh(a) << "," << tanh(b) << "\n";
    cout << "tanh(a+b),tanh(a-b): " << "\n" << tanh(a + b) << "," << tanh(a - b) << "\n";
    cout << "tanh(a*b),tanh(a/b),tanh(b/a): " << "\n" << tanh(a * b) << "," << tanh(a / b) << "," << tanh(b / a) << "\n";
    cout << "tanh((a*b)^-1): " << "\n" << tanh(1 / a * 1 / b) << "\n";
    cout << "coth(a),coth(b): " << "\n" << coth(a) << "," << coth(b) << "\n";
    cout << "coth(a+b),coth(a-b): " << "\n" << coth(a + b) << "," << coth(a - b) << "\n";
    cout << "coth(a*b),coth(a/b),coth(b/a): " << "\n" << coth(a * b) << "," << coth(a / b) << "," << coth(b / a) << "\n";
    cout << "coth((a*b)^-1): " << "\n" << coth(1 / a * 1 / b) << "\n";
    cout << "|a+bi|: " << "\n" << sqrt(a * a + b * b) << "\n";
    cout << "x=a,b  solve for problem " << "j(x^2" << problem(a+b) << "x" << problem(a*b) << "), where j is parameter in C \n";
system("pause");
}
в визуалке код выглядит красивее
1627190651697.png
ss: (ну мб кому надо)
1627190729508.png1627190766687.png
 
feel irl
Участник
Статус
Оффлайн
Регистрация
21 Дек 2018
Сообщения
677
Реакции[?]
294
Поинты[?]
16K
Ну, вообще мне было скучно, изначально я хотел без библиотек. и прочего с нуля всё писать, но чёто мне стало лень, и я даже без интегралов сделал(ну я хотел спец. функции ещё там поделать....)
но а так мб кому надо...
 
Легенда форума
Статус
Оффлайн
Регистрация
10 Дек 2018
Сообщения
4,381
Реакции[?]
2,284
Поинты[?]
189K
Немного щиткод в конце, можно было сэмпл функцию для этого написать и уже её с нужными аргументами вызывать.
Сильно сократит код.
 
Начинающий
Статус
Оффлайн
Регистрация
12 Дек 2020
Сообщения
67
Реакции[?]
10
Поинты[?]
0
Код:
#include <iostream>
#include <math.h>
#include <cmath>
#include <sstream>
using namespace std;
double cot(double x) {
    return 1 / tan(x);
}
double fbeta(double x,double y) {
    return tgamma(x) * tgamma(y) / tgamma(x + y);
}
double coth(double x) {
    return  1/tanh(x);
}
string problem(double x) {
    std::ostringstream strs;
    strs << x;
    std::string str = strs.str();
    if (x >= 0)
        return "+" + str;
    if (x < 0)
        return "-" + str;

}


int main()
{
    double a, b;
    cin >> a;
    cin >> b;
    system("cls");
    cout << "sum: " << "\n" << a + b << "\n";
    cout << "dif: " << "\n" << a - b << "\n";
    cout << "op: " << "\n" << a*b << "\n";
    cout << "op^-1: " << "\n" << 1/a * 1/b << "\n";
    cout << "bop: " << "\n" << a / b << "\n";
    cout << "bop^-1: " << "\n" << b / a << "\n";
    cout << "exp a,b: " << "\n" << exp(a) << "," << exp(b) << "\n";
    cout << "sum exp: " << "\n" << exp(a + b) << "\n";
    cout << "dif exp: " << "\n" << exp(a - b) << "\n";
    cout << "op exp: " << "\n" << exp(a * b) << "\n";
    cout << "bop exp: " << "\n" << exp(a / b) << "\n";
    cout << "sum sin: " << "\n" << sin(a + b) << "\n";
    cout << "dif sin: " << "\n" << sin(a - b) << "\n";
    cout << "op sin: " << "\n" << sin(a * b) << "\n";
    cout << "bop sin: " << "\n" << sin(a / b) << "\n";
    cout << "sum cos: " << "\n" << cos(a + b) << "\n";
    cout << "dif cos: " << "\n" << cos(a - b) << "\n";
    cout << "op cos: " << "\n" << cos(a * b) << "\n";
    cout << "bop cos: " << "\n" << cos(a / b) << "\n";
    cout << "sum tan: " << "\n" << tan(a + b) << "\n";
    cout << "dif tan: " << "\n" << tan(a - b) << "\n";
    cout << "op tan: " << "\n" << tan(a * b) << "\n";
    cout << "bop tan: " << "\n" << tan(a / b) << "\n";
    cout << "sum cot: " << "\n" << cot(a + b) << "\n";
    cout << "dif cot: " << "\n" << cot(a - b) << "\n";
    cout << "op cot: " << "\n" << cot(a * b) << "\n";
    cout << "bop cot: " << "\n" << cot(a / b) << "\n";
    cout << "gamma a,b: " << "\n" << tgamma(a) << "," << tgamma(a) << "\n";
    cout << "gamma a+b: " << "\n" << tgamma(a+b) << "\n";
    cout << "gamma a-b: " << "\n" << tgamma(a - b) << "\n";
    cout << "gamma op: " << "\n" << tgamma(a * b) << "\n";
    cout << "loggamma a,b: " << "\n" << lgamma(a) << "," << tgamma(a) << "\n";
    cout << "loggamma a+b: " << "\n" << lgamma(a + b) << "\n";
    cout << "loggamma a-b: " << "\n" << lgamma(a - b) << "\n";
    cout << "loggamma op: " << "\n" << lgamma(a * b) << "\n";
    cout << "beta a,b: " << "\n" << fbeta(a,b) << "\n";
    cout << "beta a,b ^-1: " << "\n" << 1/fbeta(a, b) << "\n";
    cout << "a^b: " << "\n" << exp(b*log(a)) << "\n";
    cout << "(a^b)^-1: " << "\n" << 1/exp(b * log(a)) << "\n";
    cout << "b^a: " << "\n" << exp(a * log(b)) << "\n";
    cout << "(b^a)^-1: " << "\n" << 1 / exp(a * log(b)) << "\n";
    cout << "ln(a),ln(b): " << "\n" << log(a) << "," << log(b) << "\n";
    cout << "ln(a*b),ln(a/b): " << "\n" << log(a*b) << "," << log(a/b) << "\n";
    cout << "ln((a*b)^-1),ln(b/a): " << "\n" << log(1/a * 1/b) << "," << log(b / a) << "\n";
    cout << "log_a(b), log_b(a): " << "\n" << log(b)/log(a) << "," << log(a)/log(b) << "\n";
    cout << "a!,b!: " << "\n" << tgamma(a+1) << "," << tgamma(b + 1) << "\n";
    cout << "(a+b)!,(a-b)!: " << "\n" << tgamma(a+b+1) << "," << tgamma(a-b+1) << "\n";
    cout << "(a*b)!,(a/b)!,(b/a)!: " << "\n" << tgamma(a * b + 1) << "," << tgamma(a / b + 1) << "," << tgamma(b / a + 1) << "\n";
    cout << "sinh(a),sinh(b): " << "\n" << sinh(a) << "," << sinh(b) << "\n";
    cout << "sinh(a+b),sinh(a-b): " << "\n" << sinh(a+b) << "," << sinh(a-b) << "\n";
    cout << "sinh(a*b),sinh(a/b),sinh(b/a): " << "\n" << sinh(a * b) << "," << sinh(a / b) << "," << sinh(b/a) <<"\n";
    cout << "sinh((a*b)^-1): " << "\n" << sinh(1/a * 1/b) << "\n";
    cout << "cosh(a),cosh(b): " << "\n" << cosh(a) << "," << cosh(b) << "\n";
    cout << "cosh(a+b),cosh(a-b): " << "\n" << cosh(a + b) << "," << cosh(a - b) << "\n";
    cout << "cosh(a*b),cosh(a/b),cosh(b/a): " << "\n" << cosh(a * b) << "," << cosh(a / b) << "," << cosh(b / a) << "\n";
    cout << "cosh((a*b)^-1): " << "\n" << cosh(1 / a * 1 / b) << "\n";
    cout << "tanh(a),tanh(b): " << "\n" << tanh(a) << "," << tanh(b) << "\n";
    cout << "tanh(a+b),tanh(a-b): " << "\n" << tanh(a + b) << "," << tanh(a - b) << "\n";
    cout << "tanh(a*b),tanh(a/b),tanh(b/a): " << "\n" << tanh(a * b) << "," << tanh(a / b) << "," << tanh(b / a) << "\n";
    cout << "tanh((a*b)^-1): " << "\n" << tanh(1 / a * 1 / b) << "\n";
    cout << "coth(a),coth(b): " << "\n" << coth(a) << "," << coth(b) << "\n";
    cout << "coth(a+b),coth(a-b): " << "\n" << coth(a + b) << "," << coth(a - b) << "\n";
    cout << "coth(a*b),coth(a/b),coth(b/a): " << "\n" << coth(a * b) << "," << coth(a / b) << "," << coth(b / a) << "\n";
    cout << "coth((a*b)^-1): " << "\n" << coth(1 / a * 1 / b) << "\n";
    cout << "|a+bi|: " << "\n" << sqrt(a * a + b * b) << "\n";
    cout << "x=a,b  solve for problem " << "j(x^2" << problem(a+b) << "x" << problem(a*b) << "), where j is parameter in C \n";
system("pause");
}
в визуалке код выглядит красивее
Посмотреть вложение 162635
ss: (ну мб кому надо)
сложно и непонятно(
 
Сверху Снизу