Doing the arithmetic operation by reusing the user defined header file in C++ programming

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Doing the arithmetic operation by reusing the user defined header file in C++ programming

To show: Reusing the user defined header file, arithmet.h in C++ programming

// user defined function and header file, the way in building your own C/C++ library. Reusing the user defined header file

#include <iostream>

// the arithmet.h file stored in the same project directory else provide the relative path

#include "arithmet.h"

using namespace std;

//global variable need access from external

float p, q;

// new main program with partial function call

void main(void)

{

// local scope variables

float t, u;

cout<<"Enter two numbers separated by space: "<<endl>>p>>q;

// r = AddNum(p, q);

// s = SubtractNum(p, q);

t = DivideNum(p, q);

u = MultiplyNum(p, q);

// cout<<"Addition: "<<p <<" + "<<q<<" = "<<r<<endl;

// cout<<"Subtraction: "<<p <<" - "<<q<<" = "<<s<<endl;

cout<<"Division: "<<p <<" / "<<q<<" = "<<t<<endl;

cout<<"Multiplication: "<<p <<" * "<<q<<" = "<<u<<endl;

}

Output example:

Enter two numbers separated by space:

20 30

Division: 20 / 30 = 0.666667

Multiplication: 20 * 30 = 600

Press any key to continue . . .