Code Samples
/* Source for Command Prompt COST */
CMD PROMPT('CALCULATE TOTAL COST')
PARM KWD(ITEM) TYPE(*CHAR) LEN(20) RSTD(*NO) +
MIN(1) ALWUNPRT(*NO) PROMPT('Item name' 1)
PARM KWD(PRICE) TYPE(*DEC) LEN(10 2) RSTD(*NO) +
RANGE(0.01 99999999.99) MIN(1) +
ALWUNPRT(*YES) PROMPT('Unit price' 2)
PARM KWD(QUANTITY) TYPE(*INT2) RSTD(*NO) RANGE(1 +
9999) MIN(1) ALWUNPRT(*YES) +
PROMPT('Number of items' 3)
// calcost.cpp
// Source for Program CALCOST
#include <iostream.h>
#include <string.h>
#include <bcd.h>
int main(int argc, char *argv[])
{
char *item_name;
_DecimalT<10,2> *price;
short int *quantity;
const _DecimalT<2,2> taxrate=__D("0.15");
_DecimalT<17,2> cost;
item_name = argv[1];
price = (_DecimalT<10,2> *) argv[2];
quantity = (short *) argv[3];
cost = (*quantity)*(*price)*(__D(1.00+taxrate));
cout << "\nIt costs $" << cost << " to buy "
<< *quantity << " " << item_name << endl;
}
Note: This program receives the incoming arguments from the
command
COST, calculates a cost, and prints values.
All incoming arguments are pointers.