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.

Lab Assignment (Q no 5 >> Ch#9)

Thursday, August 11, 2011

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

class employee
{
private:
    char name[10];
    int id;
public:
    void input()
    {
        cout<<"Enter your name:"<<endl;
        cin>>name;
        cout<<"Enter your ID:"<<endl;
        cin>>id;
    }

    void output()
    {
        cout<<"Name: "<<name<<endl;
        cout<<"ID: "<<id<<endl;
    }
};

class employee2:public employee
{
public:
    double compensation;
    int x;
    void input()
    {
        employee::input();
        cout<<"Enter compensation in $:"<<endl;
        cin>>compensation;
        cout<<"Enter \n1 if hourly.\n2 if weekly.\n3 if monthly"<<endl;
        cin>>x;
    }

    void op()
    {
        switch(x)
        {
        case 1:
            cout<<"\n\nPAID HOURLY"<<endl;
            break;
        case 2:
            cout<<"\n\nPAID WEEKLY"<<endl;
            break;
        case 3:
            cout<<"\n\nPAID MONTHLY"<<endl;
            break;
        default:
            cout<<"\n\nUnknown paid type."<<endl;
            break;
        }
    }

    void output()
    {
        employee::output();
        cout<<"Compensation: "<<compensation<<endl;
    }

};

class manager:public employee2
{
private:
    string title;
    int dues;
public:
    void input()
    {
        employee2::input();
        cout<<"Enter title:"<<endl;
        cin>>title;
        cout<<"Enter golf dues:"<<endl;
        cin>>dues;
    }

    void output()
    {
        employee2::output();
        cout<<"Title: "<<title<<endl;
        cout<<"Golf club dues: "<<dues<<endl;
    }

};

class scientist:public employee2
{
private:
    int pub;
public:
    void input()
    {
        employee2::input();
        cout<<"Enter number of publications:"<<endl;
        cin>>pub;
    }

    void output()
    {
        employee2::output();
        cout<<"No. of publications: "<<pub<<endl;
    }
};

void main()
{
    employee2 ob1;
    manager ob2;
    scientist ob3;
    cout<<"*****Employee Data Input******"<<endl;
    ob1.input();
    cout<<"******Manager Data Input******"<<endl;
    ob2.input();
    cout<<"******Scientist Data Input******"<<endl;
    ob3.input();
    system("cls");

    cout<<"/////////////////////////////////////////////"<<endl;

    cout<<"^^^^^^Employee^^^^^^"<<endl;
    ob1.op();
    ob1.output();
    cout<<"^^^^^^Manager^^^^^^"<<endl;
    ob2.op();
    ob2.output();
    cout<<"^^^^^^Scientist^^^^^^"<<endl;
    ob3.op();
    ob3.output();
    _getch();
}