
Compute the Godel numbers of arithmetical expressions
Program Plan:
- In function “addingLargeNumbers()”:
- It takes two stacks corresponding to two large numbers as parameters.
- Till any one of stack becomes empty,
- Pop each digit from both stacks and add them with carry.
- Push resultant digit into resultant stack and store carry digit in “carryy”.
- If first stack not empty, till stack becomes empty,
- Pop each digit from stack and add them with carry.
- Push resultant digit into resultant stack and store carry digit in “carryy”.
- If second stack not empty, till stack becomes empty,
- Pop each digit from stack and add them with carry.
- Push resultant digit into resultant stack and store carry digit in “carryy”.
- If carry not “0”, push it into resultant stack.
- Return resultant stack.
- In function “compareNumbers()”,
- If count of digits in first number is greater than second , set flag value as “1”
- If count of digits in second number is greater than first set flag value as “2”.
- If count of digits in both numbers are same.
- Compare each digits of both number from left to right, if found any digits of first number greater than second, set flag as “1” and break.
- If found any digits of first number lesser than second, set flag as “2” and break.
- Otherwise set continue.
- Return flag value.
- In function “substractLargeNumbers()”,
- If first number is less than second exchange both numbers.
- Till any of stack for numbers becomes empty,
- For each digit from both stacks, perform subtraction.
- If digit of first number less than second, add “10” with it.
- Till stack for first number becomes empty,
- For each digit from both stacks, perform subtraction.
- If digit of first number less than second, add “10” with it.
- Return resultant stack.
- In function “divisionLargeNumbers()”,
- Initialize count value as “0”.
- Till first number become equal or less than second number,
- Subtract second number from first and compare them.
- If first number greater than second increment count value.
- Return count value.
- Print resultant stack.
- In function “multiplyLargeNumbers()”,
- Initialize resultant stack as “0”.
- Till second stack becomes empty,
- Multiply first number with each digit of second number.
- Add sum to resultant stack
- Return resultant stack.
- To compute power of two numbers repeatedly call function “multiplyLargeNumbers()”.
- To compute Godel number for each expression, choose corresponding prime number from array and perform repeated multiplication.

/**********************************************************
* Program to perform arithmetic operations on large *
* numbers. *
**********************************************************/
Explanation of Solution
Program:
//Include header files
#include <iostream>
#include<stack>
#include<queue>
using namespace std;
//Declare global variables
int flagg;
int size1,size2;
/*Function addingLargeNumbers() add two large numbers using stacks*/
stack<int> addingLargeNumbers(stack<int> Numm1_stack, stack<int> Numm2_stack)
{
//Initialize carryy as 0
int carryy=0;
//Declare variables
stack<int> Resultt_stack;
int numb1,numb2,resultt_num,resultdgt;
//If both stacks for input numbers are not empty
if(!Numm1_stack.empty() && !Numm2_stack.empty())
{
//Till any one of stack becomes empty
while(!Numm1_stack.empty() && !Numm2_stack. empty())
{
/*Take stack tops of Numm1_stack and Numm2_stack*/
numb1=Numm1_stack.top();
numb2=Numm2_stack.top();
//Add Both stack tops with carryy
resultt_num=numb1+numb2+carryy;
/*Push Last digit of result into stack Resultt_stack*/
resultdgt=resultt_num % 10;
Resultt_stack.push(resultdgt);
//Store carry digit into carryy
carryy=resultt_num / 10;
//Pop both stack tops
Numm1_stack.pop();
Numm2_stack.pop();
}
}
//If Numm1_stack is not empty
if(!Numm1_stack.empty())
{
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty())
{
//Take stack top from Numm1_stack
numb1=Numm1_stack.top();
//Add stack top with carryy to get result
resultt_num=numb1+carryy;
/*Push Last digit of result into stack Resultt_stack*/
resultdgt=resultt_num % 10;
Resultt_stack.push(resultdgt);
//Store carry digit into carryy
carryy=resultt_num / 10;
//Pop stack top of Numm1_stack
Numm1_stack.pop();
}
}
//If Numm2_stack is not empty
if(!Numm2_stack.empty())
{
//Till Numm2_stack becomes empty
while(!Numm2_stack.empty())
{
//Take stack top from Numm2_stack
numb2=Numm2_stack.top();
//Add stack top with carryy to get result
resultt_num=numb2+carryy;
// Compute Last digit of result
resultdgt=resultt_num % 10;
/*Push Last digit of result into stack Resultt_stack*/
Resultt_stack.push(resultdgt);
//Store carry digit into carryy
carryy=resultt_num / 10;
//Pop stack top of Numm2_stack
Numm2_stack.pop();
}
}
//If carryy is not 0
if(carryy!=0)
{
//Push carryy into Resultt_stack
Resultt_stack.push(carryy);
}
//Return Resultt_stack
return Resultt_stack;
}
//Function to compare two large numbers
int compareNumbers(stack<int> Numm1_stack, stack<int> Numm2_stack)
{
//Declare variables
stack<int> rough1,rough2;
size1=Numm1_stack.size();
size2=Numm2_stack.size();
int num1,num2,sizeroug;
//Set flagg as 0
flagg=0;
/*If number of digits in first number is less than second*/
if(size1<size2)
//Set flagg as 2
flagg=2;
/*If number of digits in first number is greater than second*/
if(size1>size2)
//Set flagg as 1
flagg=1;
//If number of digits in both numbers are same
if(size1==size2)
{
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty())
{
//Take top of Numm1_stack
num1=Numm1_stack.top();
//Push to stack rough1
rough1.push(num1);
//Pop top of Numm1_stack
Numm1_stack.pop();
//Take top of Numm2_stack
num2=Numm2_stack.top();
//Push to stack rough2
rough2.push(num2);
//Pop top of Numm2_stack
Numm2_stack.pop();
}
//Set sizeroug as size1
sizeroug=size1;
//Till sizeroug >0
while(sizeroug>0)
{
//Take top of rough1
num1=rough1.top();
//Push to Numm1_stack
Numm1_stack.push(num1);
//Pop top of rough1
rough1.pop();
//Take top of rough2
num2=rough2.top();
//Push to Numm2_stack
Numm2_stack.push(num2);
//Pop top of rough2
rough2.pop();
//Decrement sizeroug by 1
sizeroug--;
//If num1>num2
if(num1>num2)
{
//Set flagg as 1
flagg=1;
break;
}
//If num1<num2
else if(num1<num2)
{
//Set flagg as 2
flagg=2;
break;
}
//Otherwise
else
//Continue
continue;
}
}
//Return flagg
return flagg;
}
/*Function subtractLargeNumbers() add two large numbers using stacks*/
stack<int> substractLargeNumbers(stack<int> Numm1_stack, stack<int> Numm2_stack)
{
//Declare variables
int num1,num2,reslt,roughh,sizerou;
stack<int> rough1,rough2;
size1=Numm1_stack.size();
size2=Numm2_stack.size();
//If number digits in both numbers are equal
if(size1==size2)
{
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty())
{
//Take top of stack Numm1_stack
num1=Numm1_stack.top();
//Push into rough1
rough1.push(num1);
//Pop top of Numm1_stack
Numm1_stack.pop();
//Take top of Numm2_stack
num2=Numm2_stack.top();
//Push into rough2
rough2.push(num2);
//Pop top of Numm2_stack
Numm2_stack.pop();
}
//Set sizerou as size1
sizerou=size1;
//Till sizerou becomes 0
while(sizerou>0)
{
//Take top of rough1
num1=rough1.top();
//Push into Numm1_stack
Numm1_stack.push(num1);
//Pop top of rough1
rough1.pop();
//Take top of rough2
num2=rough2.top();
//Push into Numm2_stack
Numm2_stack.push(num2);
//Pop top of rough2
rough2.pop();
//Decrement sizerouby 1
sizerou--;
/*If number of digits in first number is greater than second*/
if(num1>num2)
{
//Set flagg as 1
flagg=1;
break;
}
//If num1<num2
else if(num1<num2)
{
//Set flagg as 2
flagg=2;
break;
}
//Otherwise
else
//Continue
continue;
}
//Till rough1 becomes empty
while(!rough1.empty())
{
//Take top of rough1
num1=rough1.top();
//Push into Numm1_stack
Numm1_stack.push(num1);
//Pop top of rough1
rough1.pop();
}
//Till rough2 becomes empty
while(!rough2.empty())
{
//take top of rough2
num2=rough2.top();
//Push into Numm2_stack
Numm2_stack.push(num2);
//Pop top of rough2
rough2.pop();
}
}
//If size1 < size2 or flagg is 2
if(size1<size2 || flagg == 2)
{
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty())
{
//Take top of Numm1_stack
num1=Numm1_stack.top();
//Push into rough1
rough1.push(num1);
//Pop top of Numm1_stack
Numm1_stack.pop();
}
//Till Numm2_stack becomes emty
while(!Numm2_stack.empty())
{
//Take top of Numm2_stack
num2=Numm2_stack.top();
//Push into rough2
rough2.push(num2);
//Pop top of Numm2_stack
Numm2_stack.pop();
}
//Till rough1 becomes empty
while(!rough1.empty())
{
//Take top of rough1
num1=rough1.top();
//Push into Numm2_stack
Numm2_stack.push(num1);
//Pop top of rough1
rough1.pop();
}
//Till rough2 becomes empty
while(!rough2.empty())
{
//Take top of rough2
num2=rough2.top();
//Push into Numm1_stack
Numm1_stack.push(num2);
//Pop top of rough2
rough2.pop();
}
}
/*Subtraction process Till Numm1_stack or Numm2_stack becomes empty */
while(!Numm1_stack.empty() && !Numm2_stack.empty())
{
//Take top of Numm1_stack
num1=Numm1_stack.top();
//Pop top of Numm1_stack
Numm1_stack.pop();
//Take top of Numm2_stack
num2=Numm2_stack.top();
//Pop top of Numm2_stack
Numm2_stack.pop();
//If num1 greater or equal to num2
if(num1 >= num2)
{
//Calculate result
reslt=num1-num2;
//Push result into resultant stack
rough1.push(reslt);
}
//Otherwise
else
{
//If Numm1_stack not empty
if(!Numm1_stack.empty())
{
//Add num1 with 10
num1=num1+10;
//Take top of Numm1_stack
roughh=Numm1_stack.top();
//Pop top of Numm1_stack
Numm1_stack.pop();
//Subtract 1 from next digit
roughh=roughh-1;
//Push new digit into same stack
Numm1_stack.push(roughh);
//Calculate result
reslt=num1-num2;
//Push result into resultant stack
rough1.push(reslt);
}
}
}
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty() )
{
//Take top of Numm1_stack
num1=Numm1_stack.top();
//Pop top of Numm1_stack
Numm1_stack.pop();
//If num1 <0
if(num1<0)
{
//Add 10 with num1
num1=10+num1;
//If Numm1_stack not empty
if(!Numm1_stack.empty())
{
//Take top of Numm1_stack
roughh=Numm1_stack.top();
//Pop top of Numm1_stack
Numm1_stack.pop();
//Decrement roughh1 by 1
roughh=roughh-1;
//Push into Numm1_stack
Numm1_stack.push(roughh);
}
}
//Push into rough1
rough1.push(num1);
}
//Return resultant stack
return rough1;
}
//Function to multiply large numbers
stack<int> multiplyLargeNumbers(stack<int> Numm1_stack, stack<int> Numm2_stack)
{
//Declare variables
stack<int> rough1,rough2,mresultStck;
mresultStck.push(0);
int num1,num2,qsize1,qsize2,mresult,addzero2;
int mcarry=0,addzero=0;
std::queue<int> numQueue1,numQueue2;
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty())
{
//Take top of Numm1_stack
num1=Numm1_stack.top();
//Pop top of Numm1_stack
Numm1_stack.pop();
//Push into Queue numQueue1
numQueue1.push(num1);
}
//Calculate size of numQueue1
qsize1=numQueue1.size();
//Till Numm2_stack becomes empty
while(!Numm2_stack.empty())
{
//Initialize mcarry as0
mcarry=0;
//Take top of Numm2_stack
num2=Numm2_stack.top();
//Pop top of Numm2_stack
Numm2_stack.pop();
//Set addzero2 as addzero
addzero2=addzero;
//Till addzero becomes 0
while(addzero2>0)
{
//Push zeros into rough1
rough1.push(0);
//Decrement addzero by 1
addzero2--;
}
//Set qsize2 as qsize1
qsize2=qsize1;
//Till qsize2 becomes 0
while(qsize2>0)
{
//Take from of queue numQueue1
num1=numQueue1.front();
//Remove front of queue numQueue1
numQueue1.pop();
//Push it into numQueue1
numQueue1.push(num1);
//Calculate result
mresult=(num1*num2)+mcarry;
//Push reslutant digit into stack
rough1.push(mresult%10);
//Set mcarry as resultant carry
mcarry=mresult/10;
//Decrement qsize2 by 1
qsize2--;
}
//If mcarry is not 0
if(mcarry!=0)
{
//Push carry into rough1
rough1.push(mcarry);
}
//Increment addzero by 1
addzero++;
//Till rough1 becomes empty
while(!rough1.empty())
{
//Take top of rough1
num1=rough1.top();
//Pop top of rough1
rough1.pop();
//Push into rough2
rough2.push(num1);
}
/*Reverse resultant stack
Till mresultStck becomes empty
*/
while(!mresultStck.empty())
{
//Take top of mresultStck
num1=mresultStck.top();
//Pop top of mresultStck
mresultStck.pop();
//Insert into queue numQueue2
numQueue2.push(num1);
}
//Till numQueue2 becomes empty
while(!numQueue2.empty())
{
//Take front of numQueue2
num1=numQueue2.front();
//Remove front of numQueue2
numQueue2.pop();
//Insert into mresultStck
mresultStck.push(num1);
}
//Call addition for addition
mresultStck=addingLargeNumbers(mresultStck,rough2);
//Till rough2 becomes empty
while(!rough2.empty())
//Pop top of rough2
rough2.pop();
}
//Return resultant stack
return mresultStck;
}
//Function for division of two large numbers
void divisionLargeNumbers(stack<int> Numm1_stack, stack<int> Numm2_stack)
{
//Declare variables
stack<int> divrough1,divrough2,divresultStck,stackfor1;
int num1,flaggg;
divresultStck.push(0);
stackfor1.push(1);
//Call function compareNumbers() to compare two numbers
flaggg=compareNumbers(Numm1_stack, Numm2_stack);
//If flaggg is 1 or 0
while(flaggg==1 || flaggg==0)
{
//Till divresultStck becomes empty
while(!divresultStck.empty())
{
//Take top of divresultStck
num1=divresultStck.top();
//Pop top of divresultStck
divresultStck.pop();
//Push into divrough1
divrough1.push(num1);
}
//Till divrough1 becomes empty
while(!divrough1.empty())
{
//Take top of divrough1
num1=divrough1.top();
//Pop top of divrough1
divrough1.pop();
//Push into divrough2
divrough2.push(num1);
}
//Till divrough2 becomes empty
while(!divrough2.empty())
{
//Take top of divrough2
num1=divrough2.top();
//Pop top of divrough1
divrough2.pop();
//Push into divresultStck
divresultStck.push(num1);
}
//Call function addingLargeNumbers()
divresultStck=addingLargeNumbers(divresultStck,stackfor1);
/*Call function substractLargeNumbers() to subtract second number from first*/
Numm1_stack=substractLargeNumbers(Numm1_stack, Numm2_stack);
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty())
{
//Take top of Numm1_stack
num1=Numm1_stack.top();
//If num1 is 0
if(num1==0)
{
//Pop top of Numm1_stack
Numm1_stack.pop();
}
//Otherwise
else
{
//Push into divrough2
divrough2.push(num1);
//Pop top of Numm1_stack
Numm1_stack.pop();
//Till Numm1_stack becomes empty
while(!Numm1_stack.empty())
{
//Take top of Numm1_stack
num1=Numm1_stack.top();
//Pop top of Numm1_stack
Numm1_stack.pop();
//Push into divrough2
divrough2.push(num1);
}
}
}
//Till divrough2 becomes empty
while(!divrough2.empty())
{
//Take top of divrough2
num1=divrough2.top();
//Pop top of divrough2
divrough2.pop();
//Push into divrough1
divrough1.push(num1);
}
//Till divrough1 becomes empty
while(!divrough1.empty())
{
//Take top of divrough1
num1=divrough1.top();
//Pop top of divrough1
divrough1.pop();
//Push into Numm1_stack
Numm1_stack.push(num1);
}
/*Call function compareNumbers() to compare new first number with second*/
flaggg=compareNumbers(Numm1_stack,Numm2_stack);
}
cout<<"\n Quotient is: "<<endl;
//Till divresultStck becomes empty
while(!divresultStck.empty())
{
//Take top of divresultStck
num1=divresultStck.top();
//Pop top of divresultStck
divresultStck.pop();
//Print number
cout<<num1;
}
}
//Program begins with main function
int main()
{
//Declare variables
stack<int> Numm1_stackk,Numm2_stackk,Resultt_stackk,powStack,powResultStack,godelResultStack,godelNum1;
char numm;
int ii,nnumm,jj,basenum,pwe;
int primearray[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
std::queue<int> roughQue;
powResultStack.push(1);
godelResultStack.push(1);
//Prompt and Read first number from user
cout<<"Enter first number"<<endl;
cin.get(numm);
//If input character is not new line or space
while(numm!='\n'&& numm!=' ')
{
//Push each digits into stack Numm1_stackk
Numm1_stackk.push(numm-48);
//Read next digit from user
cin.get(numm);
}
//Prompt and Read second number from user
cout<<"Enter second Number"<<endl;
cin.get(numm);
//If input character is not new line or space
while(numm!='\n'&& numm!=' ')
{
//Push each digits into stack Numm2_stackk
Numm2_stackk.push(numm-48);
cin.get(numm);
}
/*Call function addingLargeNumbers() to add first two numbers*/
Resultt_stackk=addingLargeNumbers(Numm1_stackk,Numm2_stackk);
//Print message for sum of numbers
cout<<"Sum of numbers is: ";
//If Resultt_stackk is not empty
while(!Resultt_stackk.empty())
{
//Print stack top of Resultt_stack
cout<<Resultt_stackk.top();
//Pop stack top of Resultt_stack
Resultt_stackk.pop();
}
cout<<"\n Difference of two numbers is : "<<endl;
/*Call function substractLargeNumbers() to compute difference*/
Resultt_stackk=substractLargeNumbers(Numm1_stackk,Numm2_stackk);
//If first number > second
if(size1 < size2 || flagg == 2)
{
//Print neagtive sign
cout<<"-";
}
//Till Resultt_stackk is not empty
while(!Resultt_stackk.empty())
{
//Print stack top of Resultt_stack
cout<<Resultt_stackk.top();
//Pop stack top of Resultt_stack
Resultt_stackk.pop();
}
cout<<"\n Product of two numbers is "<<endl;
/*Call function multiplyLargeNumbers() to compute product*/
Resultt_stackk=multiplyLargeNumbers(Numm1_stackk,Numm2_stackk);
//If Resultt_stackk is not empty
while(!Resultt_stackk.empty())
{
//Print stack top of Resultt_stack
cout<<Resultt_stackk.top();
//Pop stack top of Resultt_stack
Resultt_stackk.pop();
}
/*Call function divisionLargeNumbers() to perform division*/
divisionLargeNumbers(Numm1_stackk,Numm2_stackk);
/*To compute power
Insert base number into stack
*/
powStack.push(1);
powStack.push(2);
powStack.push(3);
//Initialize ii as 0
ii=0;
//Till ii becomes 45
while(ii<45)
{
//Till powResultStack becomes empty
while(!powResultStack.empty())
{
//Take top of powResultStack
nnumm=powResultStack.top();
//Pop top of powResultStack
powResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into powResultStack
powResultStack.push(nnumm);
}
/*Call function multiplyLargeNumbers() for repeated multiplication*/
powResultStack=multiplyLargeNumbers(powResultStack, powStack);
//Increment ii by 1
ii++;
}
cout<<" \n Power(123,45) is: "<<endl;
//Till powResultStack becomes empty
while(!powResultStack.empty())
{
//Print stack top of powResultStack
cout<<powResultStack.top();
//Pop stack top of powResultStack
powResultStack.pop();
}
//Godel Number calculation
cout<<" \n Enter Godel expression: "<<endl;
//initialize ii as 0
ii=0;
//Read character
cin.get(numm);
//Till character becomes newline
while(numm!='\n')
{
//Switch statement
switch(numm)
{
//If character is =
case '=':
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
/*Push last digit of basenum into stack*/
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
/*To reverse order digits in stack, Till godelNum1 becomes empty*/
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty
*/
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
//Call function multiplyLargeNumbers()
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character is +
case '+':
//Set pwe as 2
pwe=2;
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
/*Push last digit of basenum into stack*/
godelNum1.push(basenum%10);
/*Set basenum as basenum/10*/
basenum=basenum/10;
}
}
//To reverse order gigits in stack, Till godelNum1 becomes empty
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
/*Till godelResultStack becomes empty*/
while(!godelResultStack.empty())
{
/*Take top of godelResultStack*/
nnumm=godelResultStack.top();
/*Pop top of godelResultStack*/
godelResultStack.pop();
/*Insert into queue roughQue*/
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
/*Insert into godelResultStack*/
godelResultStack.push(nnumm);
}
/*Call function multiplyLargeNumbers()*/
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character is *
case '*':
//Set pwe as 3
pwe=3;
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
//Push last digit of basenum into stack
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
//To reverse order gigits in stack, Till godelNum1 becomes empty
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
/* Call function multiplyLargeNumbers() */
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character is /
case '/':
//Set pwe as 5
pwe=5;
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
//Push last digit of basenum into stack
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
//To reverse order gigits in stack, Till godelNum1 becomes empty
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
//Call function multiplyLargeNumbers()
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character is )
case ')':
pwe=7;
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
//Push last digit of basenum into stack
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
//To reverse order gigits in stack, Till godelNum1 becomes empty
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
/*Call function multiplyLargeNumbers() */
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character as 0
case '0':
//Set pwe as 9
pwe=9;
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
//Push last digit of basenum into stack
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
//To reverse order gigits in stack, Till godelNum1 becomes empty
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
//Call function multiplyLargeNumbers()
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character is S
case 'S':
//Set pwe as 10
pwe=10;
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
/* Push last digit of basenum into stack */
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
/* To reverse order gigits in stack, Till godelNum1 becomes empty */
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
//Call function multiplyLargeNumbers()
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character is x
case 'x':
//Read next character (i)
cin.get(numm);
//Set pwe as 11+2*i
pwe=11+2*(numm-48);
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
//Push last digit of basenum into stack
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
//To reverse order gigits in stack, Till godelNum1 becomes empty
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
//Call function multiplyLargeNumbers()
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//If character is X
case 'X':
//Read next character (i)
cin.get(numm);
//Set pwe as 12+2i
pwe=12+2*(numm-48);
//Take prime number at iith positon
basenum=primearray[ii];
//Increment ii by 1
ii++;
//If basenum<10
if(basenum<10)
{
//Push into godelNum1
godelNum1.push(basenum);
}
//Otherwise
else
{
//Till basenum becomes 0
while(basenum>0)
{
//Push last digit of basenum into stack
godelNum1.push(basenum%10);
//Set basenum as basenum/10
basenum=basenum/10;
}
}
//To reverse order gigits in stack, Till godelNum1 becomes empty
while(!godelNum1.empty())
{
//Take top of godelNum1
nnumm=godelNum1.top();
//Pop top of godelNum1
godelNum1.pop();
//Insert imto queue roughQue
roughQue.push(nnumm);
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Push into godelNum1
godelNum1.push(nnumm);
}
//Set jj as 0
jj=0;
/*To reverse order of digits in resultant stack
Till godelResultStackbecomes empty */
while(jj<pwe)
{
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Take top of godelResultStack
nnumm=godelResultStack.top();
//Pop top of godelResultStack
godelResultStack.pop();
//Insert into queue roughQue
}
//Till roughQue becomes empty
while(!roughQue.empty())
{
//Take front of roughQue
nnumm=roughQue.front();
//Pop front of roughQue
roughQue.pop();
//Insert into godelResultStack
godelResultStack.push(nnumm);
}
//Call function multiplyLargeNumbers()
godelResultStack=multiplyLargeNumbers(godelResultStack, godelNum1);
//Increment jj by 1
jj++;
}
//Till godelNum1 becomes empty
while(!godelNum1.empty())
//Pop top of godelNum1
godelNum1.pop();
break;
//Otherwise
default:
//Print error meassage
cout<<"Invalid Input"<<endl;
}
//Read next character
cin.get(numm);
}
//Godel number calculation
cout<<" \n Godel number is: "<<endl;
//Till godelResultStack becomes empty
while(!godelResultStack.empty())
{
//Print stack top of Resultt_stack
cout<<godelResultStack.top();
//Pop stack top of Resultt_stack
godelResultStack.pop();
}
//Return from program
system("pause");
return 0;
}
Output:
Enter first number
5476532
Enter second Number
214
Sum of numbers is: 5476746
Difference of two numbers is :
5476318
Product of two numbers is
1171977848
Quotient is:
25591
Power(123,45) is:
11110408185131956285910790587176451918559153212268021823629073199866111001242743
283966127048043
Enter Godel expression:
x1+x2=x3
Godel number is:
7960790698863876893250000000000000
Want to see more full solutions like this?
Chapter 4 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
- Is developed App in play store much easier than in app store because i look app like human anonymus and like walter labs prioritize iphone app store first is it difficult to developed app on play store ? And btw i want to move to iphone anroid suckarrow_forwardQ12- A three phase transformer 3300/400 V,has D/Y connected and working on 50Hz. The line current on the primary side is 12A and secondary has a balanced load at 0.8 lagging p.f. Determine the i) Secondary phase voltage ii) Line current iii) Output power Ans. (230.95 V, 99.11 A, 54.94 kW)arrow_forwardmake corrections of this program based on the errors shown. this is CIS 227 .arrow_forward
- Create 6 users: Don, Liz, Shamir, Jose, Kate, and Sal. Create 2 groups: marketing and research. Add Shamir, Jose, and Kate to the marketing group. Add Don, Liz, and Sal to the research group. Create a shared directory for each group. Create two files to put into each directory: spreadsheetJanuary.txt meetingNotes.txt Assign access permissions to the directories: Groups should have Read+Write access Leave owner permissions as they are “Everyone else” should not have any access Submit for grade: Screenshot of /etc/passwd contents showing your new users Screenshot of /etc/group contents showing new groups with their members Screenshot of shared directories you created with files and permissionsarrow_forward⚫ your circuit diagrams for your basic bricks, such as AND, OR, XOR gates and 1 bit multiplexers, ⚫ your circuit diagrams for your extended full adder, designed in Section 1 and ⚫ your circuit diagrams for your 8-bit arithmetical-logical unit, designed in Section 2. 1 An Extended Full Adder In this Section, we are going to design an extended full adder circuit (EFA). That EFA takes 6 one bit inputs: aj, bj, Cin, Tin, t₁ and to. Depending on the four possible combinations of values on t₁ and to, the EFA produces 3 one bit outputs: sj, Cout and rout. The EFA can be specified in principle by a truth table with 26 = 64 entries and 3 outputs. However, as the EFA ignores certain inputs in certain cases, it is easier to work with the following overview specification, depending only on t₁ and to in the first place: t₁ to Description 00 Output Relationship Ignored Inputs Addition Mode 2 Coutsjaj + bj + Cin, Tout= 0 Tin 0 1 Shift Left Mode Sj = Cin, Cout=bj, rout = 0 rin, aj 10 1 1 Shift Right…arrow_forwardShow the correct stereochemistry when needed!! mechanism: mechanism: Show the correct stereochemistry when needed!! Br NaOPh diethyl ether substitutionarrow_forward
- In javaarrow_forwardKeanPerson #keanld:int #keanEmail:String #firstName:String #lastName: String KeanAlumni -yearOfGraduation: int - employmentStatus: String + KeanPerson() + KeanPerson(keanld: int, keanEmail: String, firstName: String, lastName: String) + getKeanld(): int + getKeanEmail(): String +getFirstName(): String + getLastName(): String + setFirstName(firstName: String): void + setLastName(lastName: String): void +toString(): String +getParkingRate(): double + KeanAlumni() + KeanAlumni(keanld: int, keanEmail: String, firstName: String, lastName: String, yearOfGraduation: int, employmentStatus: String) +getYearOfGraduation(): int + setYearOfGraduation(yearOfGraduation: int): void +toString(): String +getParkingRate(): double In this question, write Java code to Create and Test the superclass: Abstract KeanPerson and a subclass of the KeanPerson: KeanAlumni. Task 1: Implement Abstract Class KeanPerson using UML (10 points) • Four data fields • Two constructors (1 default and 1 constructor with all…arrow_forwardPlz correct answer by best experts...??arrow_forward
- Q3) using the following image matrix a- b- 12345 6 7 8 9 10 11 12 13 14 15 1617181920 21 22 23 24 25 Using direct chaotic one dimension method to convert the plain text to stego text (hello ahmed)? Using direct chaotic two-dimension method to convert the plain text to stego text?arrow_forward: The Multithreaded Cook In this lab, we'll practice multithreading. Using Semaphores for synchronization, implement a multithreaded cook that performs the following recipe, with each task being contained in a single Thread: 1. Task 1: Cut onions. a. Waits for none. b. Signals Task 4 2. Task 2: Mince meat. a. Waits for none b. Signals Task 4 3. Task 3: Slice aubergines. a. Waits for none b. Signals Task 6 4. Task 4: Make sauce. a. Waits for Task 1, and 2 b. Signals Task 6 5. Task 5: Finished Bechamel. a. Waits for none b. Signals Task 7 6. Task 6: Layout the layers. a. Waits for Task 3, and 4 b. Signals Task 7 7. Task 7: Put Bechamel and Cheese. a. Waits for Task 5, and 6 b. Signals Task 9 8. Task 8: Turn on oven. a. Waits for none b. Signals Task 9 9. Task 9: Cook. a. Waits for Task 7, and 8 b. Signals none At the start of each task (once all Semaphores have been acquired), print out a string of the task you are starting, sleep for 2-11 seconds, then print out a string saying that you…arrow_forwardProgramming Problems 9.28 Assume that a system has a 32-bit virtual address with a 4-KB page size. Write a C program that is passed a virtual address (in decimal) on the command line and have it output the page number and offset for the given address. As an example, your program would run as follows: ./addresses 19986 Your program would output: The address 19986 contains: page number = 4 offset = 3602 Writing this program will require using the appropriate data type to store 32 bits. We encourage you to use unsigned data types as well. Programming Projects Contiguous Memory Allocation In Section 9.2, we presented different algorithms for contiguous memory allo- cation. This project will involve managing a contiguous region of memory of size MAX where addresses may range from 0 ... MAX - 1. Your program must respond to four different requests: 1. Request for a contiguous block of memory 2. Release of a contiguous block of memory 3. Compact unused holes of memory into one single block 4.…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningCOMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE L


