New Android apps UniqueKey

Tuesday, 12 May 2015

Class Program in C++

This is a C++ program to illustrate the class and its use in C++ programming language. Class is a main feature in object oriented programming language like C++.

#include<iostream>
#include<string.h>
using namespace std;

class employee
{
  char name[50];
  int number;
  float basic_pay,allowance,it,gross,net;
  public:
    void read(char e_name[],int e_number,float e_basic_pay);
    void calculate(void);
    void display(void);
};

void employee::read(char e_name[],int e_number,float e_basic_pay)
{
  strcpy(name,e_name);
  number=e_number;
  basic_pay=e_basic_pay;
  
}

void employee::calculate(void)
{
  allowance=(123*basic_pay)/100;
  gross=basic_pay+allowance;
  it=(30*gross)/100;
  net=basic_pay+allowance-it;
}

void employee::display(void)
{
  cout<<"Name: "<<name<<endl;
  cout<<"Number: "<<number<<endl;
  cout<<"Basic pay: "<<basic_pay<<endl;
  cout<<"Allowance: "<<allowance<<endl;
  cout<<"Income tax: "<<it<<endl;
  cout<<"Net Salary: "<<net<<endl;
}

main()
{
  employee e1;
  char e_name[50];
  int e_number;
  float e_basic_pay;
  cout<<"Name: ";
  cin>>e_name;
  cout<<"Employee number: ";
  cin>>e_number;
  cout<<"Basic Pay: ";
  cin>>e_basic_pay;
  e1.read(e_name,e_number,e_basic_pay);
  e1.calculate();
  e1.display();
}

No comments:

Post a Comment