Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q. 5 Consider this formula: M (F+N) *(K-1)/P+H a) Show the order that a processo

ID: 3733833 • Letter: Q

Question

Q. 5 Consider this formula: M (F+N) *(K-1)/P+H a) Show the order that a processor would follow to calculate M b) By using multiple processors, rewrite above arithmetic expression to take advantage of concurrent processing and code it. Use the terms COBEGIN and COEND to delimit the sections of concurrent code. Q. 6 You and your friend visit the ATM in different location at exactly the same time, and both of you withdraw $50 from your same account. The bank's code is Debit (int account, int amount) t-balance [account]; balance[account]-t-amount; a) Something is missing in the code. What is that? b) How to use semaphore to solve the problem?

Explanation / Answer

Q5: a)

M=(F+N)*(K-1)/P+H
The processor will first execute the brackets as it has heighest precedence and the associativity is Left to Right:
1. a1=(F+N)
2. a2=(K-1)
The expression now becomes: M=a1*a2/P+H
The processor then executes divsion as it has higher prcedence over multiplication and addition:
3. a3=a2/P
The expression now becomes: M=a1*a3+H
The processor then executes multiplicationion as it has higher prcedence over addition:
4. a4=a1*a3
The expression now becomes: M=a4+H
The processor then executes addition:
5. a5=a4+H
a5 is the value of M.

-------------------------------------------------------------------------------------------------------------------------------

b)

Initialize;
cobegin
Calculate(M)
  {a1Add(F,N); a2Sub(k,1);}
  cobegin
  {a3Div(a2,P);}
  coend
  cobegin
  {a4Mul(a1,a3);}
  coend
  cobegin
  {a5Add(a4,H);}
  coend
coend;
Terminate

--------------------------------------------------------------------------------------------------------------------------------------

Q6: a)

Debit(int account,int amount)
{
while(balance[amount]>0)

{
t=balance[account];
balance[account]=t-amount;
}
}

---------------------------------------------------------------------------------------------------------------------------------

b)

Debit(int account,int amount)
{
If(amount>balance[amount])
cout<<"Your Balance is low";
else{
while(balance[amount]>0)

{
Wait(S);
t=balance[account];
balance[account]=t-amount;
Signal(S);
}
}
}