C++ Program – Classes and objects

by Nideesh C on May 2, 2011 · 0 comments

in C++




//Downloaded From theonlinetutorials.com
//Program to illustrate Classes and objects

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class emp      //Employee class
{
 int empcode;
 char empname[20];
 char desig[20];
 float bsal,hra,da,netsal;
 void calculate();
 public:emp()
 {          //Assigning all values as 0
 empcode=0;
 bsal=0.0;
 hra=0.0;
 da=0.0;
 netsal=0.0;
 strcpy(empname,"Not Initialised");
 strcpy(desig,"Not Initialised");
 }
void input();      //Calling input and output functions
void output();
}ob[10];
 void emp::calculate()   //calculate function
 {
 netsal=bsal+hra+da;
 }
 void emp::input()     //accept values from user
 {
 cout<<"\nEnter the employee code:";
 cin>>empcode;
 cout<<"\nEnter the employee name:";
 gets(empname);
 cout<<"\nEnter designation:";
 gets(desig);
 cout<<"\nEnter the basic salary:";
 cin>>bsal;
 cout<<"\nEnter HRA:";
 cin>>hra;
 cout<<"\nEnter DA:";
 cin>>da;
 calculate();
 }
 void emp::output()  //Output values
 {
 cout<<empcode;
 cout<<empname;
 cout<<desig;
 cout<<netsal;
 }
void main()
 {
 clrscr();
 int i,n;
 cout<<"\nEnter the number of employees:";
 cin>>n;
 for(i=0;i<n;i++)
 {
 ob[i].input();
 }
 cout<<"\n\nCode\tName\tSalary\n";
 for(i=0;i<n;i++)
 {
 ob[i].output();
 cout<<endl;
 }
 getch();
 }



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to illustrate the operations of singly linked list
  2. C Program to find the gross and net salary
  3. C++ Program – Binary File Handling
  4. C++ Program – Bubble Sort Salary
  5. C++ program – implement three classes using multiple inheritance

Leave a Comment

Previous post:

Next post: