Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Index Visual C++ and MFC Fundamentals



  1. Click Finish

  2. To add a header file, on the main menu, click Project -> Add New Item... In the Add
    New Item – BusMath dialog box, in the Templates list, click Header File (.h).
    Replace the content of the Name edit box with bmcalc and click Open

  3. In the empty file, declare the following functions:


#ifndef _BUSINESSMATH_H_
#define _BUSINESSMATH_H_

double Min(const double *Numbers, const int Count);
double Max(const double *Numbers, const int Count);
double Sum(const double *Numbers, const int Count);
double Average(const double *Numbers, const int Count);
long GreatestCommonDivisor(long Nbr1, long Nbr2);

#endif // _BUSINESSMATH_H_


  1. To add a source file, on the main menu, click Project -> Add New Item... In the
    Templates lis of the Add New Item – BusMath dialog box, click Source File (.cpp).
    Replace the content of the Name edit box with bmcalc and click Open

  2. Implement the functions as follows:


#include "StdAfx.h"
#include "bmcalc.h"

double Min(const double *Nbr, const int Total)
{
double Minimum = Nbr[0];

for(int i = 0; i < Total; i++)
if( Minimum > Nbr[i] )
Minimum = Nbr[i];
return Minimum;
}

double Max(const double *Nbr, const int Total)
{
double Maximum = Nbr[0];

for(int i = 0; i < Total; i++)
if( Maximum < Nbr[i] )
Free download pdf