Testcover.com Testcover.com
Shopping Cart Example -
updateItems() Pseudocode
Pseudocode for updateItems() action on the UPDATE transition from the nonemptyCart state to its containing state cart. Removed items are skipped; items with valid new quantities are updated; item totals are recomputed.

updateItems() {                                                                /* nonemptyCart UPDATE */
    newI=0;
    for(i=0; i<n; i++) {
        if(delChk[i]==1||newQ[i]==0) continue;                                 /* skip removed items */
        delChk[newI]=0;
        item[newI]=item[i];
        desc[newI]=desc[i];
        if(newQ[i]>0) {                                                        /* update valid quantities */
            qty[newI]=newQ[i];
            newQ[newI}=newQ[i];
        }
        else {                                                                 /* ignore invalid quantities */
            qty[newI]=qty[i];
            newQ[newI]=qty[i];
        }
        price[newI]=price[i];
        itemTotal[newI]=qty[newI]*price[newI];
        newI++;
    }
    n=newI;
}
Copyright © 2003-2018 Testcover.com, LLC. All rights reserved.