
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
- Draw a system/level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary. Example of what a level-0 diagram looks like is attached.arrow_forwardWhat is the value of performing exploratory data analysis in designing data visualizations? What are some examples?arrow_forwardDraw a level-0 diagram for this scenario: You are developing a new customer relationship management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_forward
- Draw a context diagram for this scenario: You are developing a new customer relationship Management system for the BEC store, which rents out movies to customers. Customers will provide comments on new products, and request rental extensions and new products, each of which will be stored into the system and used by the manager for purchasing movies, extra copies, etc. Each month, one employee of BEC will select their favorite movie pick of that week, which will be stored in. the system. The actual inventory information will be stored in the Entertainment Tracker system, and would be retrieved by this new system as and when necessary.arrow_forwardWrite a complete Java program named FindSumAndAverage that performs the following tasks in 2-D array: Main Method: a. The main() method asks the user to provide the dimension n for a square matrix. A square matrix has an equal number of rows and columns. b. The main() method receives the value of n and calls the matrixSetUp() method that creates a square matrix of size n and populates it randomly with integers between 1 and 9. c. The main method then calls another method named printMatrix() to display the matrix in a matrix format. d. The main method also calls a method named findSumAndAverage() which: • Receives the generated matrix as input. • Calculates the sum of all elements in the matrix. • Calculates the average value of the elements in the matrix. • Stores these values (sum and average) in a single-dimensional array and returns this array • e. The main method prints the sum and average based on the result returned from findSumAndAverage()). Enter the dimension n for the square…arrow_forwardThe partial sums remain the same no matter what indexing we done to s artial sum of each series onverges, * + s of each series to the series or show 12. (1)+(0)+(0)+(+1)+ 17, " (F) + (F) + (F)(F)(- 18. 19. 1 #20. (三)+(三)-(三)+(3) 20 (9)-(0)-(0)-- 10 +1 2.1+(男)+(男)+(罰)+(鄂 9 T29 x222-끝+1-23 + -.... Repeating Decimals 64 Express each of the numbers in Exercises 23-30 as the m integers. 23. 0.23 = 0.23 23 23... 24. 0.234 = 0.234 234 234. 25. 0.7 = 0.7777... 26. 0.d = 0.dddd... where d is a digit natio of own s converges or * 27. 0.06 = 0.06666.. 28. 1.4141.414 414 414... 29. 1.24123 = 1.24 123 123 123... 30. 3.142857 = 3.142857 142857. Using the ath-Term Test In Exercises 31-38, use the ath-Term Test for divergence to show that the series is divergent, or state that the test is inconclusive 8arrow_forward
- CPS 2231 Computer Programming Homework #3 Due Date: Posted on Canvas 1. Provide answers to the following Check Point Questions from our textbook (5 points): a. How do you define a class? How do you define a class in Eclipse? b. How do you declare an object's reference variable (Hint: object's reference variable is the name of that object)? c. How do you create an object? d. What are the differences between constructors and regular methods? e. Explain why we need classes and objects in Java programming. 2. Write the Account class. The UML diagram of the class is represented below (10 points): Account id: int = 0 - balance: double = 0 - annualInterestRate: double = 0.02 - dateCreated: java.util.Date + Account() + Account(id: int, balance: double) + getId(): int + setId(newId: int): void + getBalance(): double + setBalance(newBalance: double): void + getAnnualInterestRate(): double + setAnnualInterest Rate (newRate: double): void + toString(): String + getDataCreated(): java.util.Date +…arrow_forwardTHIS IS NOT A GRADING ASSIGNMENT: Please only do lab 2.2 (bottom part of the first picture) For that Lab 2.2 do: *Part 1 (do the CODE, that's super important I need it) *Part 2 *Part 3 I also attached Section 2.5.2 which is part of the step 1 so you can read what is it about. Thank you!arrow_forwardTHIS IS NOT A GRADING ASSIGNMENT: Please only do lab 2.2 (bottom part of the first picture) For that Lab 2.2 do: *Part 1 *Part 2 *Part 3 I also attached Section 2.5.2 which is part of the step 1 so you can read what is it about. Thank you!arrow_forward
- can you please give me: * the code (step 3) *the list file (step 5) *and answer step 6 Thank youarrow_forward# Find the error# Why will the following code not print out a list of contact namesphoneBook = {'Doe, Jane' : '843-000-0000' ,'Doe, John' : '843-111-1111' ,'Smith, Adam' : '843-222-2222' ,'Jobs, Steve' : '999-333-3333' ,}for contact in phoneBook.values():print(contact)arrow_forward# Find the error:# The following code creates an empty dictionary and attempts to add a record# Why will the following code not create a new dictionary entry as intended?phoneBook = {}phoneBook{'Jobs, Steve'} = '999-111-1111'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


