Can any one tell me how to put a part of program into a header file or how to work with multiple files? According to my book, I need to put the template and class part into a separate file and include the header as "counter.h". I have done same and saved the file as counter.h but it didn’t worked. Please help me out!
Thanks in advance daniweb communitiy
#include<iostream>
template <class Type>
class counter
{
Type data; // store the count
public:
counter (Type N=0){data = N;} // constructor, default initial is 0
void increment(Type D=1){data += D;} // increment is 1 by default
Type getValue(){return data;} // return the current count
};
using namespace std;
int main()
{
int N; // input number
counter<int> counterOfOdds; // count of odd numbers
counter<short>counterMultiples; // count of multiple of 3
do
{
cout <<"Enter number (-1 to finish): ";
cin >>N;
if (N != -1) // not the terminator
{
if (N%2 == 0) counterOfOdds.increment(); // odd number
if (N%2 != 0) counterMultiples.increment(); // multiple of 3
}
} while(N != -1);
cout<<"Number of odd numbers: " <<counterOfOdds.getValue()<<endl;
cout<<"Number of even numbers: "<<counterMultiples.getValue()<<endl;
system("PAUSE");
return 0;
}