From cb85ff5f76255487e408c569b434e1ce97f6451a Mon Sep 17 00:00:00 2001 From: ChestnutHeng Date: Wed, 23 Sep 2015 16:12:52 +0800 Subject: [PATCH] Rebuild Project --- Makefile | 16 ++ README.md | 49 +++-- fours.h => fours.cpp | 90 ++++----- linar.h => linar.cpp | 421 +++++++++++++++++++++-------------------- main.cpp | 62 +++--- main.h | 8 + numsys.h => numsys.cpp | 109 +++++------ 7 files changed, 414 insertions(+), 341 deletions(-) create mode 100644 Makefile rename fours.h => fours.cpp (86%) rename linar.h => linar.cpp (56%) create mode 100644 main.h rename numsys.h => numsys.cpp (93%) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..29339df --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +make: exec + +main.o: main.cpp main.h + g++ -c -o main.o main.cpp +linar.o: linar.cpp + g++ -c -o linar.o linar.cpp +fours.o: fours.cpp + g++ -c -o fours.o fours.cpp +numsys.o: numsys.cpp + g++ -c -o numsys.o numsys.cpp + +MathCalc.exe: main.o linar.o fours.o numsys.o + g++ -o MathCalc.exe main.o linar.o fours.o numsys.o + +exec: MathCalc.exe + ./MathCalc.exe diff --git a/README.md b/README.md index fcde401..f19b164 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,37 @@ -#Mathcal -*所有代码在g++下编译通过。 -*有任何问题请联系chestnutheng@gmail.com - - -计划功能(√已经实现 - 开发中 ×未实现) -*矩阵的加减乘幂运算 √ -*矩阵的行列式求值 - -*复杂表达式的运算 × -*进制转换 - - -*图形界面 \ No newline at end of file +##Multicalc + +###绠浠 +涓涓〃杈惧紡璁$畻鍣.鏀寔鍩烘湰鐨勮繍绠楀拰绾挎т唬鏁拌绠. +鏈変换浣曢棶棰樿鑱旂郴ChestnutHeng@gmail.com. + +###鍔熻兘浠嬬粛 + +- [x] 绾挎т唬鏁拌绠 + - [x] 鐭╅樀鍔犲噺娉 + - [x] 鐭╅樀涔樻硶 + - [x] 鐭╅樀鐨勫箓 + - [ ] 鐭╅樀鐨勮鍒楀紡鐨勫 + - [ ] 鐭╅樀鐨勪笂涓夎褰㈠寲绠 + - [ ] 鐭╅樀鐨勯嗗簭鏁 + - [ ] 鐭╅樀鐨勯 + - [ ] 鐭╅樀鐨勪即闅忕煩闃 + - [ ] 鐭╅樀鐨勭З +- [x] 杩涘埗杞崲 + - [x] R1 杞崲涓 R2 +- [ ] 琛ㄨ揪寮忚绠 + - [ ] 鍥涘垯杩愮畻 + - [ ] 涔樻柟杩愮畻 + - [ ] 瀵规暟鍑芥暟 + - [ ] 寮鏂硅繍绠 + +###鐗堟湰鍘嗗彶 +> * Ver 1.0 灏佽浜嗙嚎鎬т唬鏁版ā鍧楀拰鐭╅樀绫 +* Ver 1.1 瀹屽杽浜嗙煩闃电殑鍔犲噺娉 +* Ver 1.2 瀹屽杽鐭╅樀鐨勪箻娉曡繍绠楀拰骞傝繍绠 +* Ver 1.3 娣诲姞杩涘埗杞崲绯荤粺 + + +> * Ver 2.0 閲嶆瀯浜嗛儴鍒嗘柟娉曞拰鏂囦欢缁撴瀯 + + + diff --git a/fours.h b/fours.cpp similarity index 86% rename from fours.h rename to fours.cpp index bfce5de..bea5353 100644 --- a/fours.h +++ b/fours.cpp @@ -1,44 +1,48 @@ -#include -#include -#include -void fourr() -{ - / - -} -double fourans(double a, double b,string str) -{ - char ch = str.at(0); - switch(ch) - { - case '+': - return a+b; - case '-': - return a-b; - case '*': - return a*b; - case '/': - return a/b; - - } - return 1; -} - -int stringconvert(string str) -{ - - bool str1over = false; - for(unsigned int i = 0;i < str.length(); ++i) - { - if(str1over == false || 0 <= str[i] || str[i] <= 9 || str[i] == '.' || str[i] == 'E') - str1 += str[i]; - else if (0 > str[i] || str[i] > 9 || str[i] != '.' || str[i] != 'E') - { - str2 += str[i]; - str1over = true; - } - else str3 += str[i]; - - } - return 0; +#include +#include +#include + +using namespace std; +string str1,str2,str3; + +void fourr() +{ + // + +} +double fourans(double a, double b,string str) +{ + char ch = str.at(0); + switch(ch) + { + case '+': + return a+b; + case '-': + return a-b; + case '*': + return a*b; + case '/': + return a/b; + + } + return 1; +} + +int stringconvert(string str) +{ + + bool str1over = false; + for(unsigned int i = 0;i < str.length(); ++i) + { + if(str1over == false || 0 <= str[i] || str[i] <= 9 || str[i] == '.' || str[i] == 'E') + str1 += str[i]; + else if (0 > str[i] || str[i] > 9 || str[i] != '.' || str[i] != 'E') + { + str2 += str[i]; + str1over = true; + } + else str3 += str[i]; + + } + return 0; } \ No newline at end of file diff --git a/linar.h b/linar.cpp similarity index 56% rename from linar.h rename to linar.cpp index 2f16d13..e4d1531 100644 --- a/linar.h +++ b/linar.cpp @@ -1,204 +1,217 @@ -#include -#include -#include -using namespace std; -void Linar(); -class Box -{ -private: - int m,n; - vector line; - vector< vector >boxinfo; -public: - Box(int a,int b){m = a;n = b;} - void printbox(); - void inputbox(); - bool squarebox(); - Box operator + (Box &b1); - Box operator - (Box &b1); - Box operator * (Box &b1); - double boxvalue(); - Box trabox(); -}; -bool Box::squarebox() -{ - if(m == n) return true; - else return false; -} -Box Box::trabox() //codeing -{ - Box trabox(m,n); - for(int i = 0; i < n; ++i) trabox.line.push_back(this->boxinfo[0][i]); - trabox.boxinfo.push_back(line); - trabox.line.erase(line.begin(), line.end()); - for(int j = 0;j < this->n - 1; ++j) // j list - { - for(int i = 1;i < this->m; ++i) //i line - { - for (int k = 0 ;k <= this-> n; ++k) - { - //int temp = boxinfo[i][k] * boxinfo[j][k]/ (- boxinfo[j][j]) + boxinfo[i][k]; - //trabox.line.push_back(temp); - if(boxinfo[j][j] == 0) continue; - this->boxinfo[i][k] = boxinfo[i][k] * boxinfo[j][k]/ (- boxinfo[j][j]) + boxinfo[i][k]; - } //k from 1 to j - //trabox.boxinfo.push_back(line); - // trabox.line.erase(line.begin(), line.end()); - } - } - return trabox; -} -double boxvalue() //codeing -{ - return 0; -} -void Box::inputbox() -{ - for (int i = 0; i < this->m; ++i) - { - for(int j = 0; j < this->n; ++ j) - { - double temp; - cin >> temp; - line.push_back(temp); - - } - boxinfo.push_back(line); - line.erase(line.begin(), line.end()); - } -} - -void Box::printbox() -{ - cout << ">>>Display your Box:" << endl <m; ++i) - { - for(int j = 0; j < this->n; ++j) - { - cout.width(6); - cout.setf(ios::left); - cout.fill(' '); - cout << boxinfo[i][j] << " "; - } - cout << endl <m; ++i) - { - for(int j = 0; j < this->n; ++ j) - { - double temp = boxinfo[i][j] + b1.boxinfo[i][j]; - b2.line.push_back(temp); - } - b2.boxinfo.push_back(b2.line); - b2.line.erase(b2.line.begin(), b2.line.end()); - } - return b2; -} -Box Box::operator - (Box &b1) -{ - Box b2(n,m); - for (int i = 0; i < this->m; ++i) - { - for(int j = 0; j < this->n; ++ j) - { - double temp = boxinfo[i][j] - b1.boxinfo[i][j]; - b2.line.push_back(temp); - } - b2.boxinfo.push_back(b2.line); - b2.line.erase(b2.line.begin(), b2.line.end()); - } - return b2; -} -Box Box::operator * (Box &b1) -{ - Box b2(this->m,b1.n); - if(this ->n != b1.m) - { - cerr << "Error Input(m!=n)" <m; ++i) - { - for(int j = 0; j < b1.n; ++ j) - { - double temp (0); - for(int k = 0; k < this ->n ; ++k) - { - temp += boxinfo[i][k] * b1.boxinfo[k][j]; - } - b2.line.push_back(temp); - } - b2.boxinfo.push_back(b2.line); - b2.line.erase(b2.line.begin(), b2.line.end()); - } - return b2; -} - -Box createbox() -{ - cout << ">>>Input box m,n:" ; - int m,n; - cin >> m >> n ; - Box box1(m,n); - cout << ">>>Input box's data:" << endl; - box1.inputbox(); - return box1; -} -void Linar() -{ - char ch; - while(ch != 'q') - { - Linarloop: - cout << ">>>Input your want(+,-,*,^,q):"; - cin >> ch; - if(ch == 'q') return; - Box box1 (createbox()); - // box1.trabox(); unusful - // box1.printbox(); - if(ch == '^') - { - int level; - if(box1.squarebox() == false) - { - cerr << "Not a square box" <>>Input your level:"; - cin >> level; - for(int i = 0; i < level - 1; ++i) - box2 = box2 * box1; - box2.printbox(); - goto Linarloop; - } - Box box2 (createbox()); - if(ch == '+') - { - Box box3(box1 + box2); - box3.printbox(); - } - else if(ch == '-') - { - Box box3(box1 - box2); - box3.printbox(); - } - else if(ch == '*') - { - Box box3(box1 * box2); - box3.printbox(); - } - else - { - cout << "Wrong Input" << endl; - goto Linarloop; - } - - } - -} +#include +#include +#include + +using namespace std; + +class Box +{ +private: + int m,n; + vector line; + vector< vector >boxinfo; +public: + Box(int a,int b){m = a;n = b;} + void printbox(); + void inputbox(); + bool squarebox(); + Box operator + (Box &b1); + Box operator - (Box &b1); + Box operator * (Box &b1); + double boxvalue(); + Box trabox(); +}; + +bool Box::squarebox() //bool if martrix is a square or not +{ + return (m == n); +} +Box Box::trabox() //codeing, +{ + Box trabox(m,n); + for(int i = 0; i < n; ++i) trabox.line.push_back(this->boxinfo[0][i]); + trabox.boxinfo.push_back(line); + trabox.line.erase(line.begin(), line.end()); + for(int j = 0;j < this->n - 1; ++j) // j COL + { + for(int i = 1;i < this->m; ++i) //i ROW + { + for (int k = 0 ;k <= this-> n; ++k) + { + //int temp = boxinfo[i][k] * boxinfo[j][k]/ (- boxinfo[j][j]) + boxinfo[i][k]; + //trabox.line.push_back(temp); + if(boxinfo[j][j] == 0) continue; + this->boxinfo[i][k] = boxinfo[i][k] * boxinfo[j][k]/ (- boxinfo[j][j]) + boxinfo[i][k]; + } //k from 1 to j + //trabox.boxinfo.push_back(line); + // trabox.line.erase(line.begin(), line.end()); + } + } + return trabox; +} +double boxvalue() //codeing,calculate determinant value +{ + return 0; +} +void Box::inputbox() +{ + for (int i = 0; i < this->m; ++i) + { + for(int j = 0; j < this->n; ++ j) + { + double temp; + cin >> temp; + line.push_back(temp); + + } + boxinfo.push_back(line); + line.erase(line.begin(), line.end()); + } +} + +void Box::printbox() +{ + cout << ">>>Display your Box:" << endl <m; ++i) + { + for(int j = 0; j < this->n; ++j) + { + cout.width(6); + cout.setf(ios::left); + cout.fill(' '); + cout << boxinfo[i][j] << " "; + } + cout << endl <m; ++i) + { + for(int j = 0; j < this->n; ++ j) + { + double temp = boxinfo[i][j] + b1.boxinfo[i][j]; + b2.line.push_back(temp); + } + b2.boxinfo.push_back(b2.line); + b2.line.erase(b2.line.begin(), b2.line.end()); + } + return b2; +} +Box Box::operator - (Box &b1) +{ + Box b2(n,m); + for (int i = 0; i < this->m; ++i) + { + for(int j = 0; j < this->n; ++ j) + { + double temp = boxinfo[i][j] - b1.boxinfo[i][j]; + b2.line.push_back(temp); + } + b2.boxinfo.push_back(b2.line); + b2.line.erase(b2.line.begin(), b2.line.end()); + } + return b2; +} +Box Box::operator * (Box &b1) +{ + Box b2(this->m,b1.n); + if(this ->n != b1.m) + { + cerr << "Error Input! (m!=n)" <m; ++i) + { + for(int j = 0; j < b1.n; ++ j) + { + double temp (0); + for(int k = 0; k < this ->n ; ++k) + { + temp += boxinfo[i][k] * b1.boxinfo[k][j]; + } + b2.line.push_back(temp); + } + b2.boxinfo.push_back(b2.line); + b2.line.erase(b2.line.begin(), b2.line.end()); + } + return b2; +} + +Box createbox() +{ + cout << ">>>Input box m,n:" ; + int m,n; + cin >> m >> n ; + Box box1(m,n); + cout << ">>>Input box's data:" << endl; + box1.inputbox(); + return box1; +} + +bool legal_input(string str) +{ + if(str == "+" || str == "-" || str == "*" || str == "^" || str == "help" || str == "q") + return true; + else return false; +} +void Linar() +{ + cout << "Linarloop is a Tool to calculate martrix values." << endl; + string op_str; + while(true){ + cout << ">>>Input your operator(+,-,*,^,q,help):"; + cin >> op_str; + if(!legal_input(op_str)){ + cout << "Error Input." << endl; + continue; + } + //sys_op + if(op_str == "q") break; + else if(op_str == "help"){ + cout << "Help:" << endl; + cout << "'+','-','*'' is the base operator.\n'^'' to calculate the martrix's power." << endl; + cout << "'help' to help. q to quit." << endl; + continue; + } + //user_op + Box box1 (createbox()); + if(op_str == "^") + { + int level; + if(box1.squarebox() == false) + { + cerr << "Not a square box!" <>>Input your level:"; + cin >> level; + for(int i = 0; i < level - 1; ++i) + box2 = box2 * box1; + box2.printbox(); + } + Box box2 (createbox()); + if(op_str == "+") + { + Box box3(box1 + box2); + box3.printbox(); + } + else if(op_str == "-") + { + Box box3(box1 - box2); + box3.printbox(); + } + else if(op_str == "*") + { + Box box3(box1 * box2); + box3.printbox(); + } + else + { + cout << "System Error!" << endl; + } + } +} diff --git a/main.cpp b/main.cpp index 111a46d..f9a8e15 100644 --- a/main.cpp +++ b/main.cpp @@ -1,29 +1,33 @@ -#include -#include -#include -#include "linar.h" -#include "numsys.h" -using namespace std; - - -string str1,str2,str3; - -double fourans(double a, double b,string str); -int stringconvert(string str); - - -int main() -{ - string str; - while(str != "q") - { - cout << ">>>Input a command:(Linar,Numsys,q):"; - - cin >> str ; - if((str == "Linar") || (str == "linar")) Linar(); - if((str == "numsys") || (str == "Numsys")) Numsys(); - } - return 0; -} - - +#include +#include + +#include "main.h" + + +using namespace std; + +// double fourans(double a, double b,string str); +// int stringconvert(string str); + +int main() +{ + string str; + while(true) + { + cout << ">>>Input a command:(Linar,Numsys,q):"; + cin >> str ; + if(str == "q") { + break; + } + else if((str == "Linar") || (str == "linar")) { + Linar(); + } + else if((str == "numsys") || (str == "Numsys")) { + Numsys(); + } + else {cout << "Error input." << endl;} + } + return 0; +} + + diff --git a/main.h b/main.h new file mode 100644 index 0000000..bf90c3b --- /dev/null +++ b/main.h @@ -0,0 +1,8 @@ +#ifndef MAIN_H +#define MAIN_H + + +void Linar(); +void Numsys(); + +#endif diff --git a/numsys.h b/numsys.cpp similarity index 93% rename from numsys.h rename to numsys.cpp index 32e89a5..531c5c7 100644 --- a/numsys.h +++ b/numsys.cpp @@ -1,53 +1,56 @@ -#include -#ifndef EPS - #define EPS 0.0001 -#endif -using namespace std; - - -double convert_to_R(double num,double R) -{ - int num_int = (int)floor(num); - double num_flo = num - num_int; - double ans; - for(int j = 0;num_int != 0;++j) - { - ans = ans + pow(10,j) * floor(fmod(num_int,R)); - num_int = (int) (num_int / R); - //if (num_int == 0) break; - } - double num_flo_flo; - for(int j = 1;num_flo_flo < EPS;++j) - { - ans += pow(10,-j)*(floor(num_flo*R)); - num_flo *= R; - num_flo_flo = num_flo - floor(num_flo); - //if (num_int == 0) break;; - } - return ans; - -} - -double numconvert(double num,double R1,double R2) -{ - if (R1 == 10) return convert_to_R(num,R2); - return 0; //Coding - -} - -void Numsys() -{ - double former,later,r1,r2; - do - { - cout << "Input number and R1:" ; - cin >> former; - if (former == 0) break; - cin >> r1; - cout << "To R2:"; - cin >> r2; - later = numconvert(former,r1,r2); - cout << "The anwser is:" << later << "(" << r2 << ")" << endl; - cout << "0 to quit." << endl; - }while (former != 0); -} +#include +#include + +#ifndef EPS + #define EPS 0.0001 +#endif + +using namespace std; + + +double convert_to_R(double num,double R) +{ + int num_int = (int)floor(num); + double num_flo = num - num_int; + double ans; + for(int j = 0;num_int != 0;++j) + { + ans = ans + pow(10,j) * floor(fmod(num_int,R)); + num_int = (int) (num_int / R); + //if (num_int == 0) break; + } + double num_flo_flo; + for(int j = 1;num_flo_flo < EPS;++j) + { + ans += pow(10,-j)*(floor(num_flo*R)); + num_flo *= R; + num_flo_flo = num_flo - floor(num_flo); + //if (num_int == 0) break;; + } + return ans; + +} + +double numconvert(double num,double R1,double R2) +{ + if (R1 == 10) return convert_to_R(num,R2); + return 0; //Coding + +} + +void Numsys() +{ + double former,later,r1,r2; + do + { + cout << "Input number and R1:" ; + cin >> former; + if (former == 0) break; + cin >> r1; + cout << "To R2:"; + cin >> r2; + later = numconvert(former,r1,r2); + cout << "The anwser is:" << later << "(" << r2 << ")" << endl; + cout << "0 to quit." << endl; + }while (former != 0); +}