Wednesday 4 December 2013

Program for searching an object from an array of objects

//
//  program - searching an employee details from an n number of employees using member functions
//
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

// definition of employee class
class employee
{
      int empno;
      char name[10];
      char desig[10];
      float sal;
   public:
      void input();
      int search(int);
};

// start member function input
void employee::input()
{
   cout<<"Enter ID     : ";
   cin>>empno;
   cout<<"Enter Name   : ";
   gets(name);
   cout<<"Enter Desig  :  ";
   gets(desig);
   cout<<"Enter salary :  ";
   cin>>sal;
}
// end member function input

// start member function search
int employee::search(int e_id)
{
   if(e_id==empno)
   {
      cout<<"\nEmployee ID   : "<<empno;
      cout<<"\nEmployee name : "<<name;
      cout<<"\nDesignation   : "<<desig;
      cout<<"\nSalary        : "<<sal;
      return(1);
   }
   else
      return(0);
}
// end member function search

// start of main program
void main()
{
   clrscr();
   employee e[100];
   int n,eid,flag;
   char option;
   cout<<"Enter the No of Employee : ";
   cin>>n;
   for(int i=0;i<n;i++)
      e[i].input();
   while (1)
   {
      cout<<"Enter the Employee ID to be Searched : ";
      cin>>eid;
      for(i=0;i<n;i++)
      {
     flag=e[i].search(eid);
     if (flag==1)
        break;
      }
      if (flag==0)
     cout<<"Employee Not Found";
      getch();
      cout<<"Enter Y/y to Continue...";
      cin>>option;
      if(option!='Y'&& option!='y')
     break;
   }
}
// end of main program

Thursday 14 November 2013

Ambiguity Cases

Chances of ambiguity in the case of Constructors with default arguments:

Case:1
class complex
{
      float real;
      float imag;
   public:
      complex(void);
      complex(float a=1.5);
};

Case:2
class complex
{
      float real;
      float imag;
   public:
      complex(float a=1.5);
      complex(float, float b=2.5);
};

Tuesday 12 November 2013

Welcome my dear students,

Here you can post your doubts, thoughts and ideas.