-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd6470d
commit 1bb1ad4
Showing
5 changed files
with
342 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# Multicalc | ||
Multicalc using cpp | ||
#Mathcal | ||
*所有代码在g++下编译通过。 | ||
*有任何问题请联系chestnutheng@gmail.com | ||
|
||
|
||
计划功能(√已经实现 - 开发中 ×未实现) | ||
*矩阵的加减乘幂运算 √ | ||
*矩阵的行列式求值 - | ||
*复杂表达式的运算 × | ||
*进制转换 - | ||
|
||
*图形界面 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <iostream> | ||
#include <stdio.h> | ||
#include <string> | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <iomanip> | ||
using namespace std; | ||
void Linar(); | ||
class Box | ||
{ | ||
private: | ||
int m,n; | ||
vector<double> line; | ||
vector< vector<double> >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 <<endl; | ||
for (int i = 0; i < this->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 <<endl; | ||
} | ||
} | ||
|
||
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(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)" <<endl; | ||
return b2; | ||
} | ||
for (int i = 0; i < this->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" <<endl; | ||
goto Linarloop; | ||
} | ||
Box box2(box1); | ||
cout << ">>>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; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <iostream> | ||
#include <stdio.h> | ||
#include <string> | ||
#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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <cmath> | ||
#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); | ||
} |