
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
- using r language a continuous random variable X has density function f(x)=1/4x^3e^-(pi/2)^4,x>=0 derive the probability inverse transformation F^(-1)x where F(x) is the cdf of the random variable Xarrow_forwardusing r language in an accelerated failure test, components are operated under extreme conditions so that a substantial number will fail in a rather short time. in such a test involving two types of microships 600 chips manufactured by an existing process were tested and 125 of them failed then 800 chips manufactured by a new process were tested and 130 of them failed what is the 90%confidence interval for the difference between the proportions of failure for chips manufactured by two processes? using r languagearrow_forwardI want a picture of the tools and the pictures used Cisco Packet Tracer Smart Home Automation:o Connect a temperature sensor and a fan to a home gateway.o Configure the home gateway so that the fan is activated when the temperature exceedsa set threshold (e.g., 30°C).2. WiFi Network Configuration:o Set up a wireless LAN with a unique SSID.o Enable WPA2 encryption to secure the WiFi network.o Implement MAC address filtering to allow only specific clients to connect.3. WLC Configuration:o Deploy at least two wireless access points connected to a Wireless LAN Controller(WLC).o Configure the WLC to manage the APs, broadcast the configured SSID, and applyconsistent security settings across all APs.arrow_forward
- A. What will be printed executing the code above?B. What is the simplest way to set a variable of the class Full_Date to January 26 2020?C. Are there any empty constructors in this class Full_Date?a. If there is(are) in which code line(s)?b. If there is not, how would an empty constructor be? (create the code lines for it)D. Can the command std::cout << d1.m << std::endl; be included after line 28 withoutcausing an error?a. If it can, what will be printed?b. If it cannot, how could this command be fixed?arrow_forwardCisco Packet Tracer Smart Home Automation:o Connect a temperature sensor and a fan to a home gateway.o Configure the home gateway so that the fan is activated when the temperature exceedsa set threshold (e.g., 30°C).2. WiFi Network Configuration:o Set up a wireless LAN with a unique SSID.o Enable WPA2 encryption to secure the WiFi network.o Implement MAC address filtering to allow only specific clients to connect.3. WLC Configuration:o Deploy at least two wireless access points connected to a Wireless LAN Controller(WLC).o Configure the WLC to manage the APs, broadcast the configured SSID, and applyconsistent security settings across all APs.arrow_forwardTransform the TM below that accepts words over the alphabet Σ= {a, b} with an even number of a's and b's in order that the output tape head is positioned over the first letter of the input, if the word is accepted, and all letters a should be replaced by the letter x. For example, for the input aabbaa the tape and head at the end should be: [x]xbbxx z/z,R b/b,R F ① a/a,R b/b,R a/a, R a/a,R b/b.R K a/a,R L b/b,Rarrow_forward
- Given the C++ code below, create a TM that performs the same operation, i.e., given an input over the alphabet Σ= {a, b} it prints the number of letters b in binary. 1 #include 2 #include 3 4- int main() { std::cout > str; for (char c : str) { if (c == 'b') count++; 5 std::string str; 6 int count = 0; 7 char buffer [1000]; 8 9 10 11- 12 13 14 } 15 16- 17 18 19 } 20 21 22} std::string binary while (count > 0) { binary = std::to_string(count % 2) + binary; count /= 2; std::cout << binary << std::endl; return 0;arrow_forwardConsidering the CFG described below, answer the following questions. Σ = {a, b} • NT = {S} Productions: P1 S⇒aSa P2 P3 SbSb S⇒ a P4 S⇒ b A. List one sequence of productions that can accept the word abaaaba; B. Give three 5-letter words that can be accepted by this CFG; C. Create a Pushdown automaton capable of accepting the language accepted by this CFG.arrow_forwardGiven the FSA below, answer the following questions. b 1 3 a a b b с 2 A. Write a RegEx that is equivalent to this FSA as it is; B. Write a RegEx that is equivalent to this FSA removing the states and edges corresponding to the letter c. Note: To both items feel free to use any method you want, including analyzing which words are accepted by the FSA, to generate your RegEx.arrow_forward
- 3) Finite State Automata Given the FSA below, answer the following questions. a b a b 0 1 2 b b 3 A. Give three 4-letter words that can be accepted by this FSA; B. Give three 4-letter words that cannot be accepted by this FSA; C. How could you describe the words accepted by this FSA? D. Is this FSA deterministic or non-deterministic?arrow_forwardConsidering the TM below, answer the following questions. a/x,R €/E,L €/E,R €/E,L x/E,R c/c,R b/E.L c/c,L x/x,R I J K L M F b/E.L D A. Give three 4-letter words that can be accepted by this TM; B. Give three 4-letter words that cannot be accepted by this TM; C. How could you describe the words accepted by this TM? D. What is the alphabet of the language accepted by this TM?arrow_forwardWhat is the generator? Explain motor generator motorarrow_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


