Testcover.com Testcover.com
Shopping Cart Example -
addItem() Pseudocode
Pseudocode for addItem() action on entry to the cart state. When a new item is already in the shopping cart, its quantity is incremented. Otherwise the new item is looked up in the catalog database.

addItem() {                                                                    /* cart entry */
    if(!isset(n)) n=0;
    if(isset(newItem)) {
        for(i=0; i<n; i++) {
            if(newItem==item[i]) {                                             /* increment quantity of item in cart */
                qty[i]++;
                newQ[i]=qty[i];
                itemTotal[i]=qty[i]*price[i];
                break;
            }
            if(i==n-1) {                                                       /* item not in cart - look in catalog */
                select ctlgItem, ctlgDesc, ctlgPrice from ctlg where ctlgItem=newItem;
                if(isset(ctlgItem)) {
                    delChk[n]=0;
                    item[n]=ctlgItem;
                    desc[n]=ctlgDesc;
                    qty[n]=1;
                    newQ[n]=1;
                    price[n]=ctlgPrice;
                    itemTotal[n]=ctlgPrice;
                    n++;
                    unset(ctlgItem);
                }
            }
        }
        unset(newItem);
    }
}
Copyright © 2003-2018 Testcover.com, LLC. All rights reserved.