Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trainingproject #188

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5b89994
training project template with documentation
Dec 8, 2015
7c4eb81
added sin cos and tan functions
Dec 8, 2015
80819fa
everyone can implement one operation, come up with a function if all …
Dec 8, 2015
5c0c324
added more functions
Dec 8, 2015
b216643
completed the project template
Dec 8, 2015
15cb93f
subtraction function
Dec 9, 2015
3ea8c87
Merge pull request #50 from eslamromario/git_training
Dec 10, 2015
1cbdd6b
removed iostream
Dec 10, 2015
426a57d
added eslam romario
Dec 10, 2015
f53f7d1
Tan Function is Done
alsawaf Dec 10, 2015
e5597f2
Cos Function
Mohamed-Medhat Dec 10, 2015
fe69ba8
sine function
Abdo-Alaa Dec 11, 2015
5f112f7
Merge pull request #53 from Mohamed-Medhat/trainingproject
Dec 11, 2015
e626cfe
removed binary files
Dec 11, 2015
8860938
added mohamed medhat to the readme file
Dec 11, 2015
fc9d524
Tan Function is Done
alsawaf Dec 11, 2015
2a2593a
added the tan function
Dec 11, 2015
17001dd
merged omar changes and uncommented the operations in main.cpp accord…
Dec 11, 2015
53aa1b5
added omar to the readme
Dec 11, 2015
00637d2
added sine function
Abdo-Alaa Dec 11, 2015
4b916ad
add sine function
Abdo-Alaa Dec 11, 2015
c26b369
sin function
Abdo-Alaa Dec 11, 2015
50eda8b
merged abdo
Dec 11, 2015
9bf0aeb
added abdo to the readme
Dec 11, 2015
90a3fab
added abdo to the readme
Dec 11, 2015
3001d5f
add lines
yasminGhazy Dec 11, 2015
fbc0339
add func
yasminGhazy Dec 11, 2015
39e221a
log function
yasminGhazy Dec 11, 2015
f5d5aff
log done
yasminGhazy Dec 11, 2015
584b56f
merged yasmin changes
Dec 11, 2015
720664d
added yasmin to the readme
Dec 11, 2015
6af5e22
refactored some functions
Dec 11, 2015
297c839
Merge branch 'YaraYasser-trainingproject' into trainingproject
Dec 11, 2015
4885b57
added yara to the readme
Dec 11, 2015
cc22d37
ln
SaraMohamed2012 Dec 11, 2015
6fa3f3b
_negate function
OmneyaYahya Dec 11, 2015
280253d
_negate & add & divide & abslute & root & factorial function :)
OmneyaYahya Dec 12, 2015
f33dac7
factorial added function
Saieeed Dec 12, 2015
2f1575c
added
Dec 12, 2015
3a58cb4
added saieed to the readme file
Dec 12, 2015
c130933
Merge pull request #73 from OmneyaYahya/trainingproject
Dec 12, 2015
af87b95
merged omneya changes and fixed a type and uncommented corresponding …
Dec 12, 2015
f012b9e
power function
YaraYasser Dec 12, 2015
6f1e469
powerfunction
YaraYasser Dec 12, 2015
59f2b5e
merged Yara's changes
Dec 11, 2015
bb525fc
merged sara's work
Dec 12, 2015
6e2c62b
added sara rabie to readme
Dec 12, 2015
d997bdd
Added my absolute function
omarmmali Dec 13, 2015
ac5d09f
Readme changed, and added absolute function
omarmmali Dec 13, 2015
8976c6a
Merge pull request #74 from omarmmali/trainingproject
Dec 13, 2015
6e34a8e
First commit
xLuLuNAx Dec 15, 2015
a3a7460
Merge pull request #77 from xLuLuNAx/trainingproject
Dec 15, 2015
4a55417
added mennatullah magdy
Dec 15, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.exe
*.o
*.gch
a.out
78 changes: 21 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,24 @@
# iusegit
# Training Project: calculator
This is a calculator
It is supposed to take commands on the form of `awesomecalculator add 3 5` <br/>
and the output would be `8` <br/>
so `argv[1]` is the operation. ex. add, subtract, multiply, divide, absolute, negate, power, root, log, ln, factorial, sin, cos and tan.<br/>
`argv[2]` and `argv[3]` are the operands.<br/>
everyone can implement one operation function.<br/>
and someone will implement the main function body.<br/>
if all functions were already implemented, come up with a new one and make it :D

This is a challenge that acts as an exercise to help OSCians and non-OSCians learn git/github.<br/>
The challenge is to have your name added to the list below.

### steps to follow:
* Fork this repository.
* Clone it into your own laptop/PC.
* Add a new file that has your name.
* Add, commit and push your changes to your github repository.
* Create a pull request.

##Tips:
* Take this quick [interactive tutorial] (http://try.github.io/) <br/>
* Learn git on [Codeacademy.](https://www.codecademy.com/learn/learn-git) <br/>

#People who has completed the challenge:
## People who have contributed to the project so far:
<ol>
01- Adham Zahran<br/>
02- Romario<br/>
03- Baron Leonardo<br/>
04- Moustapha Saad <br/>
05- Mohamed Saad<br/>
06- Ahmed Elmasarany <br/>
07- Alaa Ahmed <br/>
08- Muhammed Ahmed Abdel-Nasser <br/>
09- Omar Ahmed<br/>
10- Hedaya Samy<br/>
11- Kholoud Abdo<br/>
12- Kholoud Rabie<br/>
13- Salma Hammad<br/>
14- KAbeer_El_Tazonyyen ^\_^ #Islam <br/>
15- Mina Mouris <br/>
16- Ahmed Farid Tyson <br/>
17- Beshoy 2n0n <br/>
18- Dina Essam <br/>
19- Dev Mostafa <br/>
20- ZiZi mohamed <br/>
21- Ahmad Ikramy <br/>
22- Bassel Safwat <br/>
23- Mariam Abouzeid <br/>
24- Islam Heggy <br/>
25- ana b2aaaaaaaaa s3diya b2a =D <br/>
26- العدي بن صالح بن ابو الزيد <br/>
27- Rana Hossam <br/>
28- samar rokeba <br/>
29- Dalia Emad (a5eran -\_-)<br/>
30- Sara Samir <br/>
31- Ahmed Essam <br/>
32- Usr Ahmed <br/>
33- NeuroWhAI <br/>
34- Abdo Alaa <br/>
35- Marwan Mahmoud <br/>
36- Mohamed Medhat <br/>
37- Mohamed Monstaser <br/>
38- Omar Alsawaf <br/>
39- Omneya <br/>
40- Yara Yasser <br/>
41- Yasmin <br/>
<li>Eslam Romario</li>
<li>Mohamed Medhat</li>
<li>Omar Alsawaf</li>
<li>Abdo Alaa</li>
<li>Yasmin Ghazy</li>
<li>Yara Yasser</li>
<li>Saieed Osama</li>
<li>Omneya Yahya</li>
<li>Sara Rabie</li>
<li>Omar M. Ali</li>
<li>Menna Tullah Magdy</li>
</ol>
139 changes: 139 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include <iostream>
#include <sstream>
#include <string>
#include "operations.h"
#include <math.h>
#define PI 3.14159265


using namespace std;

float str_to_float(string str)
{
istringstream iss(str);
float value;
if (iss >> value)
return value;
else
return NULL;
}

int main(int argc, char* argv[])
{
if (argc <= 2)
{
cerr << "too few arguments" << endl;
return 1;
}
else if (argc == 3)
{
string operation = argv[1];
float num1 = str_to_float(argv[2]);

if (num1 == NULL)
{
cerr << "invalid input" << endl;
return 1;
}

if (operation == "absolute")
{
cout << absolute(num1) << endl;
}
else if (operation == "negate")
{
cout << negate(num1) << endl;
}
else if (operation == "root")
{
// cout << root(num1) << endl;
}
else if (operation == "log")
{
cout << _log(num1) << endl;
}
else if (operation == "ln")
{
cout << ln(num1) << endl;
}
else if (operation == "factorial")
{
cout << factorial(num1) << endl;
}
else if (operation == "sin")
{
cout << _sin(num1) << endl;
}
else if (operation == "cos")
{
cout << cos ( num1 * PI / 180.0 ) ;

}
else if (operation == "tan")
{
cout << _tan (num1);
}
else
{
cerr << "invalid input" << endl;
return 1;
}
}
else if (argc == 4)
{
string operation = argv[1];
float num1 = str_to_float(argv[2]);
float num2 = str_to_float(argv[3]);

if (num1 == NULL || num2 == NULL)
{
cerr << "invalid input" << endl;
return 1;
}

if (operation == "add")
{
// cout << add(num1, num2) << endl;
}
else if (operation == "subtract")
{
cout << subtract(num1, num2) << endl;
}
else if (operation == "multiply")
{
// cout << multiply(num1, num2) << endl;
}
else if (operation == "divide")
{
if(num2 == 0)
cout<<"Invalid! num2 must be > 0"<<endl;
else
cout << divide(num1, num2) << endl;
}
else if (operation == "power")
{
cout << powerfunction(num1, num2) << endl;
}
else if (operation == "root")
{
// cout << root(num1, num2) << endl;
}
else if (operation == "log")
{
cout << _log(num1, num2) << endl;
}
else
{
cerr << "invalid input" << endl;
return 1;
}
}
else
{
cerr << "too many arguments" << endl;
return 1;
}

return 0;
}

126 changes: 126 additions & 0 deletions operations.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <math.h>

using namespace std;

#define PI 3.14159265

float _tan (float num1)
{
float result =tan(num1*PI/180);

return result;
}

float subtract(float num1, float num2)
{
float result = num1-num2 ;
return result;
}


float _sin(float rate)
{
float result,r;
r=rate/180;
int i=r;
if (i-r==0)
{
result=0;
}
else
{
result = sin ((rate*PI)/180);
}
return result;
}


double _log(double x)
{
return (log10(x));
}

double _log(double base, double x) {
return (double)(log(x) / log(base));
}

double powerfunction(double base, double power){

double f = base;
for (int i = 1; i < power; i++)
f *= base;
return f;
}


float factorial(float n)
{

float result=1;


for (float i =1;i<=n;i++){
result*=i;}

return result;
}

double _negate (double num){
return num*(-1);
}

double add (double n1 , double n2){
return n1+n2;
}

double root (double num){
return sqrt(num);
}

double divide(double n1 , n2){
if(n2!=0)
return n1/n2;
else cout<<"AN error";
return 0;
}

double absolute (double num){
return (num<0?-1*num:num);
}

unsigned long long factorial(double num){
unsigned long long fac=1;
for(int i = 1 ; i <= num ; i++)
fac*=i;
return fac;
}

long double ln(long double x)
{
//***********Variable Declarations************/
long double count = 0; //Keeps track of the count in the loop
long double totalValue = 0; //The summation of each polynomial evaluated
bool reciprocal = false; //Flag to use if greater than 2
long double precision = 9; //The the highest order of polynomial to use.

if (x > 2.0) //Use the rule -ln(1/x) == ln(x) to keep accuracy
{
x = 1 / x; //Change to using 1/x rather than x
reciprocal = true; //Flag as true (sign change is later)
}

while (count < precision)
{
totalValue += pow(-1, count + 1) * (pow((x-1),count)/count);
count++;
}

if (reciprocal == true)
totalValue * -1; //If reciprocal was used multiply by -1 to change sign

return totalValue;
}
float divide (float num1, float num2)
{
return (num1/num2);
}