How to use the user defined header file in C++ programming

 

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: none

To do: Doing the arithmetic operations using the custom made header file for C++ programming

To show: How to use the user defined header file in C++ programming

 

// user defined function using user defined header file, "arithmet.h"

// A very simple arithmetic operation functions

#include <iostream>

// notice this! Provide relative path if needed

#include "arithmet.h"

using namespace std;

 

// global variables, which need external access

float p, q;

 

void main(void)

{

// local scope (to this file) variables

float r, s, t, u;

 

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

 

// function calls

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:

10.5 12.5

Addition: 10.5 + 12.5 = 23

Subtraction: 10.5 - 12.5 = -2

Division: 10.5 / 12.5 = 0.84

Multiplication: 10.5 * 12.5 = 131.25

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index