RSS

Category Archives: Header Files

HEADER FILE HAVING AN OVERLOADED VERSION OF A FUNCTION FOR CALCULATONG A NUMBER TO THE POWER OF ANOTHER

//HEADER FILE HAVING MATHS RELATED FUNCTIONS

#ifndef _POWER_H
#define _POWER_H

float pow(float num, int power)
{
float val = 1.0;
for(int i=0; i<power; i++)
{
val *= num;
}

return val;
}

int power(int num, int power)
{
int val = 1;
for(int i=0; i<power; i++)
val *= num;
return val;
}

#endif

 
Leave a comment

Posted by on August 17, 2015 in Header Files

 

HEADER FILE HAVING FUNCTION TO CALCULATE SUM OF DIGITS OF A NUMBER

#ifndef diksha1_H
#define diksha1_H

int sum(int num)
{
int val = 0;

while(num)
{
val += num%10;
num /= 10;
}

return val;
}

#endif

 
Leave a comment

Posted by on August 17, 2015 in Header Files

 

HEADER FILE TO CALCULATE FACTORIAL OF A NUMBER

// MY HEADER FILE DIKSHA.H

#ifndef _diksha_h
#define _diksha_h

int fact(int num)
{
int val = 1;

for(; num>0; num–)
val *= num;
return val;
}

#endif

 
Leave a comment

Posted by on August 17, 2015 in Header Files

 

HEADER FILE HAVING CLASS DEFINITION OF EMPLOYEE CLASS

// HEADER FILE HAVING EMPLOYEE CLASS DEFINITION

#ifndef _CLASS_H
#define _CLASS_H
#include <stdio.h>

class employee
{
char name[20];
int empid;
long salary;

public:
void read()
{
cout<<“\nENTER EMPLOYEE ID\n”;
cin>>empid;
cout<<“\nENTER NAME\n”;
gets(name);
cout<<“\nENTER SALARY\n”;
cin>>salary;
}
void print()
{
cout<<“\nEMPLOYEE ID:\t”<<empid;
cout<<“\nEMPLOYEE NAME:\t”;
cout.write(name,100);
cout<<endl;
cout<<“EMPLOYEE SALARY:\t”<<salary;
}
int getid()
{ return empid;}
};

#endif

 
Leave a comment

Posted by on August 17, 2015 in Header Files