Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Assignment 3 Question 1&2

Monday, May 16, 2011


#include<iostream>
using namespace std;
#include<conio.h>
#include<string>
class person
{
public:
      virtual void getdata()=0;
      virtual void showdata()=0;
};
class student:public person
{
protected:
      string rol,gpa;
      string ag,nm;
     
public:
     
      void getdata()
      {
            cout<<"Enter name :";
            cin>>nm;
            cout<<"Enter age :";
            cin>>ag;
            cout<<"Enter enrollment number :";
            cin>>rol;
            cout<<"Enter GPA :";
            cin>>gpa;
      }
      void showdata()
      {
            cout<<"Name is : "<<nm<<endl;
            cout<<"Age is : "<<ag<<endl;
            cout<<"Enrollment number is :"<<rol<<endl;
            cout<<"GPA of student is :"<<gpa<<endl;
      }
      string chk()
      {
            return nm;
      }
};
class employee:public person
{
protected:
      string id,ag,nm;
public:
      void getdata()
      {
            cout<<"Enter name :";
            cin>>nm;
            cout<<"Enter age :";
            cin>>ag;
            cout<<"Enter id :";
            cin>>id;
      }
      void showdata()
      {
            cout<<"Name is : "<<nm<<endl;
            cout<<"Age is : "<<ag<<endl;
            cout<<"Id is : "<<id<<endl;
      }
     
};
class lecturer:public employee
{
protected:
      string pub,clpw;
public:
      void getdata()
      {
            employee::getdata();
            cout<<"Enter number of publications :";
            cin>>pub;
            cout<<"Enter classes per week :";
            cin>>clpw;
      }
      void showdata()
      {
            employee::showdata();
            cout<<"Number of publications is : "<<pub<<endl;
            cout<<"Classes per week : "<<clpw<<endl;
      }
      string chk()
      {
            return nm;
      }
};
class director:public employee
{
protected:
      string ms,ys;
public:
      void getdata()
      {
            employee::getdata();
            cout<<"Enter maximum qualification :";
            cin>>ms;
            cout<<"Enter years of service : ";
            cin>>ys;
      }
      void showdata()
      {
            employee::showdata();
            cout<<"Maximum qualification is : "<<ms<<endl;
            cout<<"Years of serice : "<<ys<<endl;
      }
      string chk()
      {
            return nm;
      }
};
class clerk:public employee
{
protected:
      string ovrtm,hrdt;
public:
      void getdata()
      {
            employee::getdata();
            cout<<"Enter Duty hours of clerk : ";
            cin>>hrdt;
            cout<<"enter Overtime of clerk : ";
            cin>>ovrtm;
      }
      void showdata()
      {
            employee::showdata();
            cout<<"Duty hours of clerk : "<<hrdt<<endl;
            cout<<"Overtime of clerk : "<<ovrtm<<endl;
      }
      string chk()
      {
            return nm;
      }
};
void main()
{
      int a;
      student obss;
      lecturer obll;
      clerk obcc;
      director obdd;
      cout<<"__________________Student Input________________"<<endl;
      cout<<"Enter number of students : ";
      cin>>a;
      student *obd=new student[a];
      for(int i=0;i<a;i++)
      {
            obd[i].getdata();
      }
      for(int d=0;d<a;d++)
      {
            for(int s=0;s<a;s++)
            {
                  if(obd[d].chk()<obd[s].chk())
                  {
                        obss=obd[d];
                        obd[d]=obd[s];
                        obd[s]=obss;
                  }
            }
      }

      cout<<"__________________Student Output________________"<<endl;
      for(int k=0;k<a;k++)
      {
            obd[k].showdata();
      }
      cout<<"__________________Lecturer Input________________"<<endl;
      cout<<"Enter number of lecturer`s ";
      cin>>a;
      lecturer *obl=new lecturer[a];
      for(int i=0;i<a;i++)
      {
            obl[i].getdata();
      }
      for(int d=0;d<a;d++)
      {
            for(int s=0;s<a;s++)
            {
                  if(obl[d].chk()<obl[s].chk())
                  {
                        obll=obl[d];
                        obl[d]=obl[s];
                        obl[s]=obll;
                  }
            }
      }
      cout<<"__________________Lecturer Output________________"<<endl;
      for(int k=0;k<a;k++)
      {
            obl[k].showdata();
      }
      cout<<"__________________Director Input________________"<<endl;
      cout<<"Enter number of director`s ";
      cin>>a;
      director *ob=new director[a];
      for(int i=0;i<a;i++)
      {
            ob[i].getdata();
      }
      for(int d=0;d<a;d++)
      {
            for(int s=0;s<a;s++)
            {
                  if(ob[d].chk()<ob[s].chk())
                  {
                        obdd=ob[d];
                        ob[d]=ob[s];
                        ob[s]=obdd;
                  }
            }
      }
      cout<<"__________________Director Output________________"<<endl;
      for(int k=0;k<a;k++)
      {
            ob[k].showdata();
      }
      cout<<"__________________Clerk Input________________"<<endl;
      cout<<"Enter number of clerk`s ";
      cin>>a;
      clerk *obc=new clerk[a];
      for(int i=0;i<a;i++)
      {
            obc[i].getdata();
      }
      for(int d=0;d<a;d++)
      {
            for(int s=0;s<a;s++)
            {
                  if(obc[d].chk()<obc[s].chk())
                  {
                        obcc=obc[d];
                        obc[d]=obc[s];
                        obc[s]=obcc;
                  }
            }
      }
      cout<<"__________________Clerk Output________________"<<endl;
      for(int k=0;k<a;k++)
      {
            obc[k].showdata();
      }

      cout<<"_________________________THANK YOU_________________________"<<endl;

getch();
}