Doing the arithmetic operations by reusing the user defined header file in C++ programming - creating our own library
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
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: Save the arithmet.h file in the standard INCLUDE directory. Check your compiler documentation. You can find (add & delete) your VC++ EE INCLUDE directories by browsing: Tools -> Options -> Projects and Solutions -> VC++ Directories -> Show directories for: -> Include files.
To do: Doing the arithmetic operations by reusing the user defined header file in C++ programming - creating our own library
To show: Creating our own library, store it in the standard C/C++/IDE project include directory
// reusing the user defined header file. The way to create your own C/C++ library
using namespace std;
// by storing the arithmet.h file in the standard C/C++ include directory, we can use
// <arithmet> instead of "arithmet.h"
// global variables need access from external
float p, q;
// local scope variable
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;
Enter two numbers separated by space:
Division: 30 / 40 = 0.75
Multiplication: 30 * 40 = 1200
Press any key to continue . . .
Now, the arithmet.h is reusable and our main() program becomes smaller. When there are a lot of our own header files used for specific tasks programming it will become our new library. In compiled form, those header files might be in .lib extension.