Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/etc/Job/SalesPerson.cpp

Go to the documentation of this file.
00001 // Implementation of class SalesPerson
00002 #ifndef __J2K__SalesPerson_CPP__
00003 #define __J2K__SalesPerson_CPP__
00004 
00005 #include <j2k/Fred/Job/SalesPerson.hpp>
00006 
00007 SalesPerson::SalesPerson() {
00008    for ( int i = 0; i < 12; i++ )
00009       sales[ i ] = 0.0;
00010 }
00011 
00012 // Function to get 12 sales figures from the user at the keyboard
00013 void SalesPerson::getSalesFromUser()
00014 {
00015    double salesFigure; 
00016 
00017    for ( int i = 0; i < 12; i++ ) {
00018       cout << "Enter sales amount for month " << i + 1 << ": ";
00019       cin >> salesFigure;
00020       setSales( i, salesFigure );
00021    }
00022 }
00023 
00024 // Function to set one of the 12 monthly sales figures.
00025 // Note that the month value must be from 0 to 11.
00026 void SalesPerson::setSales( int month, double amount )
00027 {
00028    if ( month >= 0 && month < 12 && amount > 0 ) {
00029       sales[ month ] = amount;
00030    } else {
00031       cout << "Invalid month or sales figure\n";
00032    }
00033 }
00034 
00035 // Print the total annual sales
00036 void SalesPerson::printAnnualSales()
00037 {
00038    cout << setprecision( 2 )
00039         << setiosflags( ios::fixed | ios::showpoint )
00040         << "\nThe total annual sales are: $"
00041         << totalAnnualSales() << endl;
00042 }
00043 
00044 // Private utility function to total annual sales
00045 double SalesPerson::totalAnnualSales()
00046 {
00047    double total = 0.0;
00048 
00049    for ( int i = 0; i < 12; i++ )
00050       total += sales[ i ];
00051 
00052    return total;
00053 }

Generated on Sun Oct 14 18:46:31 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001