Friday, September 26, 2014

Assume that an object represents an employee report that contains the information like employee id , total bonus, total overtime in a particular year. Use array of objects to represent n employee’s reports. WAP that displays report. Use setreport() member functions to set report attribute by passing the arguments and member functions displayreport() to show the reports according to parameter passed. Display the report in following format. Employee with ________ has received Rs._____ as bonus and had worked____hours as an overtime in year_______.

#include
#include
#include

class employee
{
int bonus;

public:

setreport(int ot)
{
 bonus=ot*500;
 return(bonus);
}

void displayreport(int id,int year,int b,int ot)
{
cout<
}
};



void main()
{
clrscr();
int n,id,year,ot,b;
cout<
cin>>n;
employee a[50];
for(int i=0;i
{
cout<
cin>>id;
cout<
cin>>year;
cout<
cin>>ot;
}

for(i=0;i
{
b=a[i].setreport(ot);
a[i].displayreport(id,year,b,ot);
}
getch();

}

WAP with classes to represent circle, rectangle and triangle. Each classes should have data members to represent the actual objects and member functions to read and display objects , find perimeter and area of the object with other useful functions. Use the classes to create objects in your program.

#include
#include
#include
#define PI 3.14159
class circle
{
      private:
      float r,a1,p1;
      public:
      void get()
      {
                  cout<
                  cin>>r;
      }
      void show()
      {
                  cout<
                  cout<
      }
      friend float a(float r);
      friend float b(float r);
};
class rectangle
{
      private:
      float l,b;
      public:
      void get()
      {
                  cout<
                  cin>>l>>b;
      }
      void show()
      {
                  cout<
                  cout<
      }
      friend float c(float l,float b);
      friend float d(float l,float b);
};
class triangle
{
      private:
      float s,s1,s2,s3,a3,p3;
      public:
      void get()
      {
                  cout<
                  cin>>s1>>s2>>s3;
      }
      void show()
      {
                  cout<
                  cout<
      }
      friend float e(float s,float s1,float s2,float s3);
      friend float f(float s,float s1,float s2,float s3);

};
float a(float r)
{
      return (PI*r*r);
}
float b(float r)
{
      return (2*PI*r);
}
float c(float l,float b)
{
      return (l*b);
}
float d(float l,float b)
{
      return (2*(l+b));
}
float e(float s,float s1,float s2,float s3)
{
      s=(s1+s2+s3)/2;
      return (pow((s-s1)*(s-s2)*(s-s3),1/2));
}
float f(float s,float s1,float s2,float s3)
{
      return (s1+s2+s3);
}


void main()
{
      clrscr();
      circle c;
      c.get();
      c.show();
      rectangle r;
      r.get();
      r.show();
      triangle t;
      t.get();
      t.show();
      getch();

}

WAP to transfer the given amount of money from one account to another by using the concept of passing objects by pointers. For this create a class with suitable data members and necessary member functions.

#include
#include
class account
{
            private:
   int accno;
   float balance;
   public:
   void getdata()
   {
            cout<<"Enter account no.:";
      cin>>accno;
      cout<<"Enter balance:";
      cin>>balance;
   }
   void display()
   {
            cout<<"Account number is"<
      cout<<"Balance is"<
   }
   void moneytransfer(account *acc,float amt);
};
void account::moneytransfer(account *acc,float amt)
{
            balance=balance-amt;
   acc->balance=acc->balance+amt;
}
main()
{
            float money;
   account acc1,acc2;
   acc1.getdata();
   acc2.getdata();
   cout<<"A/C info:"<
   acc1.display();
   acc2.display();
   cout<<"How much money to be transferred from account 2 to account 1"<
   cin>>money;
   acc2.moneytransfer(&acc1,money);
   cout<<"Updated info of account:"<
   acc1.display();
   acc2.display();
   getch();

}

WAP defining a class distance with member data meter, centimeter, kilometer. Introduce member functions getdata (), show () and function to add two objects of class distance and returning objects. Use reference arguments in the function for addition.

#include
#include
class distance
{
            int m,cm,km,add3;
            public:
            void getdata()
            {
                        cout<<"Enter distance in kilometer:";
                        cin>>km;
                        cout<<"Enter distance in meter:";
                        cin>>m;
                        cout<<"Enter distance in centimeter:";
                        cin>>cm;
            }
            void show(distance add3)
            {
                        cout<<"The sum is:"<
            }
            void ad(distance &add1,distance &add2,distance &add3);
};

            void distance :: ad(distance &add1,distance &add2,distance &add3)
            {
                        add3.cm=add1.cm+add2.cm;
                        add3.m=add1.m+add2.m;
                        add3.km=add1.km+add2.km;
                        if(add3.cm>=(100))
                        add3.m++;
                        if(add3.m>=(1000))
                        add3.km++;
      add3.cm=add3.cm%100;
      add3.m=add3.m%1000;
   }
void main()
{
            clrscr();
            distance add1,add2,add3;
            add1.getdata();
            add2.getdata();
            add3.ad(add1,add2,add3);
            add3.show(add3);
            getch();

}