抽象的代码
  • 板块灌水区
  • 楼主tl_luwenhan
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/11/26 11:06
  • 上次更新2023/11/26 13:18:56
查看原帖
抽象的代码
723387
tl_luwenhan楼主2023/11/26 11:06

可计算加减乘除,还可以输出

#define  _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define term1 ' '//输出后的换行等符号
#define format 1 //浮点数输出保留位数,0是不做处理
using namespace std;
typedef long long ll;
typedef long double ld;
class compute {
    private:
        double answer;
    public:
        //初始化
        void __init__(short n) { answer = n; }
        void __init__(int n) { answer = n; }
        void __init__(ll n) { answer = n; }
        void __init__(float n) { answer = n; }
        void __init__(double n) { answer = n; }
        void __init__(ld n) { answer = n; }
        //加
        void num_add(short n) { answer += n; }
        void num_add(int n) { answer += n; }
        void num_add(ll n) { answer += n; }
        void num_add(float n) { answer += n; }
        void num_add(double n) { answer += n; }
        void num_add(ld n) { answer += n; }
        //减
        void num_sub(short n) { answer -= n; }
        void num_sub(int n) { answer -= n; }
        void num_sub(ll n) { answer -= n; }
        void num_sub(float n) { answer -= n; }
        void num_sub(double n) { answer -= n; }
        void num_sub(ld n) { answer -= n; }
        //乘
        void num_tim(short n) { answer *= n; }
        void num_tim(int n) { answer *= n; }
        void num_tim(ll n) { answer *= n; }
        void num_tim(float n) { answer *= n; }
        void num_tim(double n) { answer *= n; }
        void num_tim(ld n) { answer *= n; }
        //除
        void num_exc(short n) { answer /= n; }
        void num_exc(int n) { answer /= n; }
        void num_exc(ll n) { answer /= n; }
        void num_exc(float n) { answer /= n; }
        void num_exc(double n) { answer /= n; }
        void num_exc(ld n) { answer /= n; }
        //取余(不常用)
        /*void num_mod(short n) { answer %= n; }
        void num_mod(int n) { answer %= n; }
        void num_mod(ll n) { answer %= n; }*/
        auto pr() { return answer; }
};
class PRINT {
    public:
        void print(short n) { printf("%d%c", n, term1); }
        void print(int n) { printf("%d%c", n, term1); }
        void print(ll n) { printf("%lld%c", n, term1); }
        void print(float n) {
            if (format == 0) printf("%f%c", n, term1);
            else {
                cout.setf(ios::fixed);
                cout << setprecision(format) << n << term1;
            }
            resetiosflags(ios::fixed);
        }
        void print(double n) {
            if (format == 0)  printf("%lf%c", n, term1);
            else {
                cout.setf(ios::fixed);
                cout << setprecision(format) << n << term1;
            }
            resetiosflags(ios::fixed);
        }
        void print(ld n) { 
            if (format == 0) printf("%Lf%c", n, term1);
            else {
                cout.setf(ios::fixed);
                cout << setprecision(format) << n << term1;
            }
            resetiosflags(ios::fixed);
        }
        void print(char ch) { printf("%c%c", ch,term1); }
        void print(char ch[]) { printf("%s%c", ch, term1); }
        void print(string str) { printf("%s%c", str.c_str(), term1); }
};
int main() {
    PRINT print;//输出
    compute com;//计算
    return 0;
}
2023/11/26 11:06
加载中...