Professional Documents
Culture Documents
Class : RCDCS1103C
QUESTION 1
Wood temp;
if(temp.getWoodType() == 'm')
{
MerantiStack.push(temp);
}
while(!MerantiStack.isEmpty()) // Meranti
{
temp = MerantiStack.pop();
countTotalM++;
else // Small
{
countSmallM++;
}
TempStack.push(temp);
}
while(!TempStack.isEmpty())
{
MerantiStack.push(TempStack.pop());
}
while(!CengalStack.isEmpty()) // Cengal
{
temp = CengalStack.pop();
countTotalC++;
else // Small
{
countSmallC++;
}
TempStack.push(temp);
}
while(!TempStack.isEmpty())
{
CengalStack.push(TempStack.pop());
}
// Display
System.out.println(" _________________________________________________________ ");
System.out.printf("|%-13s|%-15s|%-15s|%-11s|\n", "TYPE", "BIG SIZE", "SMALL SIZE", "TOTAL");
System.out.println("|_____________|_______________|_______________|___________|");
System.out.printf("|%-13s|%-15s|%-15s|%-11s|\n", "Meranti", countBigM, countSmallM, countTotalM);
System.out.printf("|%-13s|%-15s|%-15s|%-11s|\n", "Cengal", countBigC, countSmallC, countTotalC);
System.out.printf("|%-13s|%-15s|%-15s|%-11s|\n", "TOTAL", totalBig, totalSmall, totalBoth);
System.out.println("|_____________|_______________|_______________|___________|");
System.out.println("Big size: Width >= 6, Heigth >= 8\nSmall size: Other size");
Output:
--------------------Configuration: <Default>--------------------
_________________________________________________________
|TYPE |BIG SIZE |SMALL SIZE |TOTAL |
|_____________|_______________|_______________|___________|
|Meranti |1 |3 |4 |
|Cengal |4 |2 |6 |
|TOTAL |5 |5 |10 |
|_____________|_______________|_______________|___________|
Big size: Width >= 6, Heigth >= 8
Small size: Other size
Process completed.
QUESTION 2
i) ( A * B ) + ( C * D ) + ( E / F )
(AB*)+(CD*)+(EF/)
(AB*)(CD*)++(EF/)
(AB*)(CD*)+(EF/)+
AB*CD*+EF/+
ii) M * N $ O – X * ( Y * Z )
M*N$O–X*(YZ*)
(MN*)$O–X*(YZ*)
(MN*)O$-X*(YZ*)
(MN*)O$-X(YZ*)*
(MN*)O$X(YZ*)*-
MN*O$XYZ**-
iii) 1 + 2 * 3 – 4 / 4 - 1 2 / 6 * 6
1+(23*)–(44/)-1(26/)*6
1+(23*)–(44/)-1(26/)6*
1(23*)+(44/)-1(26/)-6*
123*+44/-126/-6*
b) Evaluate the following arithmethic expression using stack. Show all your works.
86*84+/5+
Step 1 : 8 6 * 8 4 + / 5 +
Step 2 :
4
6 8 8 12 5
8 8 48 48 48 48 4 4 9
8 6 * 8 4 + / 5 +
Answer : 9
Question 3
• A*B/C+D
(*AB)/C+D
/(*AB)C+D
+/(*AB)CD
+/*ABCD
• E–(F+G)/H
E–(+FG)/H
E-/(+FG)H
-E/(+FG)H
-E/+FGH
• (P+Q–R)/S
(PQ+-R)/S
(PQ+R-)/S
(PQ+R-)S/
PQ+R-S/
• T–U$V *W
T–(UV$)*W
T–(UV$)W*
T(UV$)W*-
TUV$W*-
c) Given the following infix expression:
X=J/K+(L–M*N)
i) Convert the above infix into postfix notation using stack. Show all the steps.
J empty J
/ / J
K / JK
+ + JK/
( +( JK/
L +( JK/L
- +(- JK/L
M +(- JK/LM
* +(-* JK/LM
N +(-* JK/LMN
) +(-*) JK/LMN*-
+
empty JK/LMN*-+
ii) Evaluate the above postfix notation using stack configuration if,
J = 140, K = 7, L = 55, M = 9, N = 5
Step 1 : J K / L M N * - +
Step 2 :
5
9 9 45
7 55 55 55 55 10
140 140 20 20 20 20 20 20 30
J K / L M N * - +
Answer : 30