Professional Documents
Culture Documents
Calculator
Calculator
//e-mail: abdoasemelzedy@hotmail.com
#include<iostream>//main library
class calc
private:
void setInfo()
int temp;
for(temp=0;temp<=len;temp++)
copy[temp] = main[temp];
}
//editing formulas to be adaptable to computing rules
void edit()
{//star edit
int temp;
len = strlen(ch);
for(temp=0;temp<len;temp++)
insert(temp,len,'*');
insert(temp,len,'*');
insert(temp,len,'*');
//the condition when there is a number before (
insert(temp,len,'*');
else if( ( ch[temp]=='.' && temp == 0) || ( temp>0 && ch[temp] == '.' && !isdigit( (ch[temp-1]) ) ) )
insert(temp,len,'0');
smaller(temp,len,'+');
smaller(temp,len,'-');
smaller(temp,len,'+');
smaller(temp,len,'-');
if(ch[0]=='+')
decrease(0,1);
}//end edit
bool exam ()
temp;//temprature variable
if( isdigit(ch[temp]) )
continue;
leftBracket ++;
rightBracket ++;
return false;
if(rightBracket != rightBracket)
return false;
return false;
//defaule condition
return true;
{
//sin condition
if(ch[temp] == 's' && ch[temp+1] == 'i' && ch[temp+2] == 'n' && ch[temp+3] == '(' &&
isdigit(ch[temp+4]) )
return true;
//cos condition
else if(ch[temp] == 'c' && ch[temp+1] == 'o' && ch[temp+2] == 's' && ch[temp+3] == '(' &&
isdigit(ch[temp+4]) )
return true;
//tan condition
else if(ch[temp] == 't' && ch[temp+1] == 'a' && ch[temp+2] == 'n' && ch[temp+3] == '(' &&
isdigit(ch[temp+4]) )
return true;
//defaul condition
return false;
}
//sin condition
if(ch[temp] == 's' && ch[temp+1] == 'i' && ch[temp+2] == 'n' && ch[temp+3] == '(' &&
isdigit(ch[temp+4]) )
return true;
//cos condition
else if(ch[temp] == 'c' && ch[temp+1] == 'o' && ch[temp+2] == 's' && ch[temp+3] == '(' &&
isdigit(ch[temp+4]) )
return true;
//tan condition
else if(ch[temp] == 't' && ch[temp+1] == 'a' && ch[temp+2] == 'n' && ch[temp+3] == '(' &&
isdigit(ch[temp+4]) )
return true;
}
//defaul condition
return false;
for(temp=len;temp>order;temp--)
ch[temp]=ch[temp-1];
for(temp=order;temp<len;temp++)
ch[temp]=ch[temp+1];
//increase characters
ch[order] = ob;
//decrease
decrease(order, 1);
ch[order] = ob;
if(num<0)
plus = true;
num*=-1;
for(intLen=0;intPart>0;intPart/=10)
intLen++;
if(intLen == 0)
floatPart>0?floatLen=1:floatLen=0;
temp = static_cast<int>(floatPart) ;
if(plus){
intPart *=-1;
}
return numLen;
void convert(char carriage[], double num, int intLen, int intPart, int floatLen, double floatPart, int
numLen, bool sign )
int start = 0;
if(numLen>0)
carriage[numLen]=0;
else
numLen=1;
carriage[numLen]=0;
}
//negative conditions
if(!sign){
start ++;
carriage[0] = '-';
//integer part
for(temp=intLen-1;temp>=start;temp--)
//floating part
if(floatPart!=0){
carriage[intLen]='.';
for(temp=intLen+1;temp<floatLen+intLen; temp++)
}//end if
int temp;
for(temp=0;temp<len;temp++)
if(ch[temp]==var)
decrease(temp,1);//remove variable
}//end for
}//end replace
int arrange;
arrange=1;
//intger part
position--;
//because it will be increase with the loop
return num;
//because we start get the num from its first numerical digit
if(ch[position]=='-')
position++;
sign = false;
}
//intger part
while(isdigit(ch[position]))
position++;
if(ch[position+1]=='.')
if(!sign)
num*=-1;
return num;
num1 = getNum(temp);
len1 = getNumLen(num1);
while(isdigit(ch[temp]))
temp++;
symbol = ch[++temp];
}//end if condition
else
return false;
insNum;//insert num
len = strlen(ch);
//sin condition
temp+=4;
//inside num
insNum = getNum(temp);
numLen= getNumLen(insNum);
temp-=3+numLen;
decrease(temp,numLen+5);
num=sin(insNum);
insertNum(temp, num);
temp+=getNumLen(num);
//cos condition
temp+=4;
//inside num
insNum = getNum(temp);
numLen= getNumLen(insNum);
//return for the main positioin
temp-=3+numLen;
decrease(temp,numLen+5);
num=cos(insNum);
insertNum(temp, num);
//tan condition
temp+=4;
//inside num
insNum = getNum(temp);
numLen= getNumLen(insNum);
//return for the main positioin
temp-=3+numLen;
decrease(temp,numLen+5);
num=tan(insNum);
insertNum(temp, num);
int temp;
str=0;//initial value
for(temp=0;temp<len;temp++)
str=temp+1;
else if(str > 0 && ch[temp]== ')' && !isalpha(ch[str-1]) )
end = temp;
break;
}//emd for
void process (double num1, double num2, char symbol, int temp)
{//processing operations
if(symbol == '^')
num = pow(num1,num2);
num = num1*num2;
num = num1/num2;
num = num1+num2;
if(num2 >= 0 && num1 >=0) //in this condition the lenght of of num1 and num2 are real
count = len1+len2;
//in this condition the lenght of of num2 is real and num1 is with negative sign so we should remove it
count = len1+len2;
//in this condition the lenght of of num1 is real and num2 is with negative sign so we should remove it
//in this condition the lenght of of num1 and num2 are with negative signs so we should remove them
if(symbol != '-')
count ++ ;
decrease(temp,count);
insertNum(temp,num);
edit();
}
void semiMath(int str, int end, char ch[])
int temp,
char symbol;
len = end;
for(temp=str;temp<len;temp++)
if(triangle(temp))
trigon_op(temp);
getBorders(str,end);
temp = str -1;//return to first digit after increasing loop to process anothers
len=end+1;
}
//first stage
len = end;
for(temp=str;temp<len;temp++)
if(symbol == '^')
process(num1,num2,symbol,temp);
getBorders(str,end);
temp = str -1;//return to first digit after increasing loop to process anothers
len=end+1;}
//second stage
len = end;
for(temp=str;temp<len;temp++)
process(num1,num2,symbol,temp);
getBorders(str,end);
temp = str -1;//return to first digit after increasing loop to process anothers
len=end;
//third stage
len = end;
for(temp=str;temp<len;temp++)
process(num1,num2,symbol,temp);
getBorders(str,end);
temp = str -1;//return to first digit after increasing loop to process anothers
len=end;
}
}//end covering loop
zero = 0,
end ;
if(exam())
getBorders(str,end);
semiMath(str, end,ch);
len = strlen(ch);
if(str !=0)
getBorders(str,end);
decrease(str-1,1);
decrease(end-1 ,1);
}//end if condition
num=getNum(zero);
return num;
else
throw invalid_argument(
int len;
len = strlen(ch);
if(num>=0)
sign = true;
else
sign = false;
//negative condition
increase(order, len,1);
/////////////////////////////////////////////////////////////
public:
double getResult()
setInfo();
return num;
return num;
void main ()
{
calc test;
while(cout<<"= "<<test.getResult()<<endl<<endl<<endl);
#include<iostream>
void main()
int a,b;
do
cin >> a;
system("CLS");
switch (a)
case 1:
if (x == y)
y--;
x = 0;
break;
case 2:
if (x == y)
}
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
{
cout << "OUTPUT OF PROGRAM 7 ." << endl;
break;
case 8:
break;
default:
cout << " YOU ENTERED INVALID VALUE . " << endl;
break;
cout << "DO YOU WANT TO SEE OTHER OUTPUTS ? IF YES , PRESS [1] .ELSE PRESS
[0] ." << endl;
cin >>b;
} while (b);
#include<iostream>
void main()
int a,b;
do
{
cout << "PRESS [1] FOR PROBLEM 1 ." << endl;
cin >> a;
system("CLS");
switch (a)
case 1:
if (x == y)
y--;
x = 0;
break;
}
case 2:
if (x == y)
if (z == 5)
break;
case 3:
{
if (x == y)
y--;
x = 1;
break;
case 4:
break;
case 5:
break;
}
case 6:
break;
case 7:
break;
case 8:
break;
default:
cout << " YOU ENTERED INVALID VALUE . " << endl;
break;
cout << "DO YOU WANT TO SEE OTHER OUTPUTS ? IF YES , PRESS [1] .ELSE PRESS
[0] ." << endl;
cin >>b;
} while (b);
}
#include<iostream>
int main()
int a,b;
do
cin >> a;
system("CLS");
switch (a)
case 1:
for(x;x== y;x)
{
y--;
x = 0;
break;
case 2:
if (x == y)
if (z == 5)
}
}
break;
case 3:
break;
case 4:
{
cout << "OUTPUT OF PROGRAM 4 ." << endl;
if (i % j == 0)
chk++;
break;
if (chk == 0 && i != 1)
x++;
sum = sum + i;
chk = 0;
cout << endl << "THE SUM OF 10 PRIME NUMBERS ARE : " << sum << endl
<< endl;
break;
case 5:
cout << x;
for(x;x== y;x)
y--;
x = 0;
break;
case 6:
cout << k;
}
break;
case 7:
int i, j, k, l;
break;
}
case 8:
int x = 5;
{
cout << "*";
break;
default:
cout << " YOU ENTERED INVALID VALUE . " << endl;
break;
cout << "DO YOU WANT TO SEE OTHER OUTPUTS ? IF YES , PRESS [1] .ELSE PRESS
[0] ." << endl;
cin >>b;
} while (b);