Skip to content

Instantly share code, notes, and snippets.

@fsmv
Created January 19, 2017 16:04
Show Gist options
  • Save fsmv/dc0b2be1bb98eb1e608a988fca6646e3 to your computer and use it in GitHub Desktop.
Save fsmv/dc0b2be1bb98eb1e608a988fca6646e3 to your computer and use it in GitHub Desktop.
WARNING: Bad code. I found this on my old computer and thought it was interesting to see my parsing before I knew any parsing. I was 16 and teaching myself C++ for the first time when I wrote this.
#include <iostream>
#include <cstdlib>
using namespace std;
int add(int a, int b){
return a+b;
}
int subtract(int a, int b){
return a-b;
}
int multiply(int a, int b){
return a*b;
}
int divide(int a, int b){
return a/b;
}
int power(int a, int n){
return a^n;
}
int root(int a, int n){
return a^(1/n);
}
int main(int argc, char* argv[]){
bool done = false;
int i = 1;
int u = 0;
do{
if(argv[i][u] == '\0'){
if(argv[i][u+1] == 'R'){
done = true;
}else{
i++;
}
}
if(argv[i][u] == '+'){
string temp = "";
for(int c = 0; c < u; c++){
temp += argv[i][c];
}
int a = atoi(temp.c_str());
bool fin = false;
int v = -1;
do{
v++;
if(argv[i][v] == '\0'){
fin = true;
}
}while(!fin);
temp = "";
for(int c = u; c < v; c++){
temp += argv[i][c];
}
int b = atoi(temp.c_str());
cout << add(a, b) << endl;
}else if(argv[i][u] == '-'){
string temp = "";
for(int c = 0; c < u; c++){
temp += argv[i][c];
}
int a = atoi(temp.c_str());
bool fin = false;
int v = -1;
do{
v++;
if(argv[i][v] == '\0'){
fin = true;
}
}while(!fin);
temp = "";
for(int c = u; c < v; c++){
temp += argv[i][c];
}
int b = atoi(temp.c_str());
cout << subtract(a, b) << endl;
}
u++;
}while(!done);
return 0;
}
//////////////////////////////////////////////
// //
// MathClass: //
// version = 0.01 planning //
// modified = 08/09/2010 //
// license = GPL //
// //
//////////////////////////////////////////////
TODO:
Addition
Subtraction
Multiplication
Division
Powers
Roots
Mean
Median
Range
Mode
Scientific notation
Order of operations
constants
Coversion
Distance Formula
Slope Formula
Midpoint
Trig Functions
Logarithms
Imaginary numbers
Complex numbers
Lists
Matricies??
Sequences
Summation
Solve right Triangles -> solve triangles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment