diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5610a5d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/fts427/Git/MathCentralTool/src", + "program": "/home/fts427/Git/MathCentralTool/src/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d2e3661 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..104aa15 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc 生成活动文件", + "command": "/usr/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}", + "" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "调试器生成的任务。" + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/bin/MCT b/bin/MCT index e00ad76..aec7b34 100755 Binary files a/bin/MCT and b/bin/MCT differ diff --git a/src/MCT-Linux b/src/MCT-Linux deleted file mode 100755 index 37f0c68..0000000 Binary files a/src/MCT-Linux and /dev/null differ diff --git a/src/Makefile b/src/Makefile index 65e2fa2..c4c4863 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,2 +1,2 @@ -MCT-Build: main.cpp +MCT-Build: main.cpp ./cpart/ g++ main.cpp -o ../bin/MCT diff --git a/src/cpart/calc.cpp b/src/cpart/calc.cpp new file mode 100644 index 0000000..92c9ea2 --- /dev/null +++ b/src/cpart/calc.cpp @@ -0,0 +1,53 @@ +//calc函数,计算器 +void calc(){ + clear(); + char o; + double num1,num2,num3; + hy("计算器"); + print("\033[1;37;43m[NOTE]\033[0m:现仅只支持两个数之间的运算!","no",true); + while (true){ + line("-",20,"yellow",true); + print("请输入计算式(+ - * / ^),输入'0c0'退出","white",true); + print("如: 1+1","white",true); + cin >> num1 >> o >> num2; + if (o == '+') + printf("%f+%f=%f\n",num1,num2,num1+num2); + //减 + if (o == '-') + printf("%f-%f=%f\n",num1,num2,num1-num2); + //乘 + if (o == '*') + printf("%f*%f=%f\n",num1,num2,num1*num2); + //除 + if (o == '/'){ + if (num2 != 0) + printf("%f/%f=%f\n",num1,num2,num1/num2); + else + error(); + } + //乘方 + /* +if (o == '^') { +int n=num2; +if(num1 != 0 && num2 != 0){ +num3 = 1; +while(n > 0) { +int(num1)*int(num3)=num3; +n--; +} +} +else +error(); +printf("%f^%f=%f\n",num1,num2,num3); +} +*/ + //退出 + if(o == 'c' && num1 == 0 && num2 ==0){ + clear(); + break; + } + //报错 + else + error(); + } +} diff --git a/src/cpart/cg.cpp b/src/cpart/cg.cpp new file mode 100644 index 0000000..bc56f82 --- /dev/null +++ b/src/cpart/cg.cpp @@ -0,0 +1,16 @@ +//E函数,几何计算 +void E(){ + hy("几何计算"); + while(true){ + line("-",20,"yellow",true); + print("输入任意键继续,输入“\033[1;33mc\033[0m”退出...","no",true); + cin >> q; + if (q == 'c' || q == 'C'){ + clear(); + break; + } + else{ + //矩形 梯形 三角形 圆 面积,周长,体积 + } + } +} \ No newline at end of file diff --git a/src/cpart/chn.cpp b/src/cpart/chn.cpp new file mode 100644 index 0000000..f74931b --- /dev/null +++ b/src/cpart/chn.cpp @@ -0,0 +1,58 @@ +//D函数,数值分析器 +void D(){ + clear(); + long double x, a; + hy("数值分析器"); + while(true){ + line("-",20,"yellow",true); + print("输入任意值继续,输入\033[1;33mC\033[0m退出...","no",true); + cin >> q; + if (q == 'c' || q == 'C'){ + clear(); + break; + } + else{ + print("请输入一个数:","blue",true); + cin >> x; + if (x == 0){ + cout << x << "是整数" << endl; + cout << x << "是正数" << endl; + cout << x << "不分质数合数" << endl; + cout << x << "是偶数" << endl; + } + else{ + if (modf(x, &a) == 0.0) + cout << x << "是整数" << endl; + else + cout << x << "是分数" << endl; + if (x > 0) + cout << x << "是正数" << endl; + else + cout << x << "是负数" << endl; + if (x == 1) + cout << x << "不分质数合数" << endl; + if (int(x) - x != 0) + cout << x << "不分质数合数" << endl; + else{ + int n=0, i; + for(i=2;i0) + cout << x << "是合数" << endl; + cout << x << "是质数" << endl; + } + if (int(x) == x){ + if (int(x) % 2 == 0) + cout << x << "是偶数" << endl; + cout << x << "是奇数" << endl; + } + else{ + if (x/2 - int(x)/2 == 0) + cout << x << "是偶数" << endl; + cout << x << "是奇数" << endl; + } + } + } + } +} \ No newline at end of file diff --git a/src/cpart/maxn.cpp b/src/cpart/maxn.cpp new file mode 100644 index 0000000..135890f --- /dev/null +++ b/src/cpart/maxn.cpp @@ -0,0 +1,31 @@ +//B函数,计算最大公约数 +void B(){ + clear(); + double num3, num4; + hy("最大公约数"); + print("\033[1;43;37m[NOTE]\033[0m:本功能只支持两个数之间的运算!","no",true); + while(true){ + line("-",20,"yellow",true); + print("输入任意值继续,输入\033[33;1mC\033[0m退出","no",true); + cin >> q; + if(q == 'c' || q == 'C'){ + clear(); + break; + } + else{ + print("请输入第一个数:","white",true); + cin >> num3; + print("请输入第二个数:","white",true); + cin >> num4; + num3 = abs(num3); + num4 = abs(num4); + while (num3 != num4){ + if (num3 > num4) + num3 -= num4; + else + num4 -= num3; + } + cout << "这两个数的的最大公约数是: " << num3 + num4 << endl; + } + } +} \ No newline at end of file diff --git a/src/cpart/minn.cpp b/src/cpart/minn.cpp new file mode 100644 index 0000000..632891c --- /dev/null +++ b/src/cpart/minn.cpp @@ -0,0 +1,38 @@ +//C函数,计算最小公倍数 +void C(){ + clear(); + hy("最小公倍数"); + print("\033[1;43;37m注意\033[0m:本功能只支持两个数之间的运算!","no",true); + while(true){ + line("-",20,"yellow",true); + print("输入任意值继续,输入\033[33;1mC\033[0m退出...","no",true); + cin >> q; + if(q == 'c' || q == 'C'){ + clear(); + break; + } + else{ + int n3; + double num5, num6; + while (true){ + print("请输入第一个数:","white",true); + cin >> num5; + print("请输入第二个数:","white",true); + cin >> num6; + if (num5 != int(num5) || num6 != int(num6)) + error(); + else + break; + } + n3 = (num5 > num6) ? num5 : num6; + while (true){ + if (n3 % int(num5) == 0 && n3 % int(num6) == 0){ + cout << "这两个数的的最小公倍数是:" << n3 << endl; + break; + } + else + ++n3; + } + } + } +} diff --git a/src/head/ECPPH.h b/src/head/mhead.h similarity index 90% rename from src/head/ECPPH.h rename to src/head/mhead.h index 4d37c49..737efd7 100644 --- a/src/head/ECPPH.h +++ b/src/head/mhead.h @@ -1,25 +1,17 @@ #include #include #include -#include -#include -#include #include #include -#include #include -#include using namespace std; int error(){ - printf("\033[1,31mERROR!\033[0m\a\n"); + cout << "\033[1,31mERROR!\033[0m\a\n"; return 1; } -void clear(){ - printf("\033[2J"); - printf("\033[0,0"); -} +void clear(){system("clear");} void print(const char T[],string color,bool i){ if(i==true){ @@ -91,3 +83,5 @@ void boxout(const char T[],string bc,string tc,bool i){ } error; } +void hy(const char T[]){cout<<"==> "< -char q; +#include "./head/mhead.h" +#include "./cpart/calc.cpp" +#include "./cpart/maxn.cpp" +#include "./cpart/minn.cpp" +#include "./cpart/chn.cpp" +#include "./cpart/cg.cpp" -void hy(const char T[]){cout<<"==> "<> num1 >> o >> num2; - //加 - if (o == '+') - printf("%f+%f=%f\n",num1,num2,num1+num2); - //减 - if (o == '-') - printf("%f-%f=%f\n",num1,num2,num1-num2); - //乘 - if (o == '*') - printf("%f*%f=%f\n",num1,num2,num1*num2); - //除 - if (o == '/'){ - if (num2 != 0) - printf("%f/%f=%f\n",num1,num2,num1/num2); - else - error(); - } - //乘方 - /* - if (o == '^') { - int n=num2; - if(num1 != 0 && num2 != 0){ - num3 = 1; - while(n > 0) { - int(num1)*int(num3)=num3; - n--; - } - } - else - error(); - printf("%f^%f=%f\n",num1,num2,num3); - } - */ - //退出 - if(o == 'c' && num1 == 0 && num2 ==0){ - clear(); - break; - } - //报错 - else - error(); - } -} - -//B函数,计算最大公约数 -void B(){ - clear(); - double num3, num4; - hy("最大公约数"); - print("\033[1;43;37m[NOTE]\033[0m:本功能只支持两个数之间的运算!","no",true); - while(true){ - line("-",20,"yellow",true); - print("输入任意值继续,输入\033[33;1mC\033[0m退出","no",true); - cin >> q; - if(q == 'c' || q == 'C'){ - clear(); - break; - } - else{ - print("请输入第一个数:","white",true); - cin >> num3; - print("请输入第二个数:","white",true); - cin >> num4; - num3 = abs(num3); - num4 = abs(num4); - while (num3 != num4){ - if (num3 > num4) - num3 -= num4; - else - num4 -= num3; - } - cout << "这两个数的的最大公约数是: " << num3 + num4 << endl; - } - } -} - -//C函数,计算最小公倍数 -void C(){ - clear(); - hy("最小公倍数"); - print("\033[1;43;37m注意\033[0m:本功能只支持两个数之间的运算!","no",true); - while(true){ - line("-",20,"yellow",true); - print("输入任意值继续,输入\033[33;1mC\033[0m退出...","no",true); - cin >> q; - if(q == 'c' || q == 'C'){ - clear(); - break; - } - else{ - int n3; - double num5, num6; - while (true){ - print("请输入第一个数:","white",true); - cin >> num5; - print("请输入第二个数:","white",true); - cin >> num6; - if (num5 != int(num5) || num6 != int(num6)) - error(); - else - break; - } - n3 = (num5 > num6) ? num5 : num6; - while (true){ - if (n3 % int(num5) == 0 && n3 % int(num6) == 0){ - cout << "这两个数的的最小公倍数是:" << n3 << endl; - break; - } - else - ++n3; - } - } - } -} - - -//D函数,数值分析器 -void D(){ - clear(); - long double x, a; - hy("数值分析器"); - while(true){ - line("-",20,"yellow",true); - print("输入任意值继续,输入\033[1;33mC\033[0m退出...","no",true); - cin >> q; - if (q == 'c' || q == 'C'){ - clear(); - break; - } - else{ - print("请输入一个数:","blue",true); - cin >> x; - if (x == 0){ - cout << x << "是整数" << endl; - cout << x << "是正数" << endl; - cout << x << "不分质数合数" << endl; - cout << x << "是偶数" << endl; - } - else{ - if (modf(x, &a) == 0.0) - cout << x << "是整数" << endl; - else - cout << x << "是分数" << endl; - if (x > 0) - cout << x << "是正数" << endl; - else - cout << x << "是负数" << endl; - if (x == 1) - cout << x << "不分质数合数" << endl; - if (int(x) - x != 0) - cout << x << "不分质数合数" << endl; - else{ - int n=0, i; - for(i=2;i0) - cout << x << "是合数" << endl; - cout << x << "是质数" << endl; - } - if (int(x) == x){ - if (int(x) % 2 == 0) - cout << x << "是偶数" << endl; - cout << x << "是奇数" << endl; - } - else{ - if (x/2 - int(x)/2 == 0) - cout << x << "是偶数" << endl; - cout << x << "是奇数" << endl; - } - } - } - } -} -/* -//E函数,几何计算 -void E(){ - hy("几何计算"); - while(true){ - line("-",20,"yellow",true); - print("输入任意键继续,输入“\033[1;33mc\033[0m”退出...","no",true); - cin >> q; - if (q == 'c' || q == 'C'){ - clear(); - break; - } - else{ - //矩形 梯形 三角形 圆 面积,周长,体积 - } - } -} -*/ //主函数 int main(){ clear(); hy("集成数学工具"); - char u; while(true){ line("-",20,"yellow",true); dash("\033[1;34m(1)\033[34m计算器\033[0m"); @@ -223,29 +20,31 @@ int main(){ dash("\033[1;33m(5)\033[33m几何\033[0m"); dash("\033[0m(a)关于\033[0m"); dash("\033[1;33m(e)退出\033[0m"); - print("==> ","white",false); - cin >> u; - if (u=='1') + print("> ","white",false); + cin >> q; + if (q=='1') calc(); - if (u=='2') + if (q=='2') B(); - if (u=='3') + if (q=='3') C(); - if (u=='4') + if (q=='4') D(); //if (u=='5')E(); - if (u=='E'||u=='e') + if (q=='E'||q=='e') break; - if (u=='A'||u =='a'){ + if (q=='A'||q =='a'){ clear(); line("=",20,"blue",true); - dash("MCT Preview v0.0.1.3-3"); + dash("MCT Preview v0.0.1.3-4"); dash("Made by QuantumLS-Studio"); dash("Url: https://github.com/QuantumLS-Studio/MathCentralTool"); line("=",20,"blue",true); } - else + else{ + clear(); error(); + } } return 0; }