ILE C/C++ Programmer's Guide

Creating the Source Files

The source code for service program COST, module COST2, and programs COSTDPT1 and COSTDPT2 is shown in the following figure:

Figure 25. Source Code for Service Program COST


    

// cost1.cpp
// contains the export function cost1() for the old service program
#include <iostream.h>
#include <bcd.h>
_DecimalT<10,2> cost1 (
int q, // The quantity.
_DecimalT<10,2> p ) // The price.
{
_DecimalT<10,2> c; // The cost.
c = q*p;
return c;
}
// cost2.cpp
// contains the export function cost2() for the new service program
#include <iostream.h>
#include <bcd.h>
_DecimalT<10,2> cost2 (int quantity, _DecimalT<10,2> price,
_DecimalT<3,1> discount )
{
_DecimalT<10,2> c = __D(quantity*price*discount/100);
return c;
}
// costdpt1.cpp
// This program prompts users (from dept1) to enter the
// quantity, and price for a product. It uses function
// cost1() to calculate the cost, and prints the result out.
#include <iostream.h>
#include <bcd.h>
_DecimalT<10,2> cost1(int, _DecimalT<10,2>);
int main(void)
{
int quantity;
_DecimalT<10,2> cost;
_DecimalT<10,2> price;
cout << "Enter the quantity, please." << endl;
cin >> quantity;
cout << "Enter the price, please." << endl;
cin >> price;
cost = cost1(quantity, price);
cout << "The cost is $" << cost << endl;
}

// costdpt2.cpp
// This program prompts users (from dept2) to enter the
// quantity, price, and discount rate for a product.
// It uses function cost2() to calculate the cost, and prints
// the result out.
#include <iostream.h>
#include <decimal.h>
_DecimalT<10,2> cost2(int, _DecimalT<10,2>, _DecimalT<3,1>);
int main(void)
{
int quantity;
_DecimalT<10,2> price;
_DecimalT<10,2> cost;
_DecimalT<3,1> discount;
cout << "Enter the quantity, please." << endl;
cin >> quantity;
cout << "Enter the price, please." << endl;
cin >> price;
cout << "Enter the discount, please.( %)" << endl;
cin >> discount;
cost = cost2(quantity, price, discount);
cout << "The cost is be $" << cost << endl;
}


[ Top of Page | Previous Page | Next Page | Table of Contents ]