Programming

Program to Create Database and Retrieve Information (C++)

An Educational institution whishes to maintain a data base of its employees. The database is divided into a No. of classes. Specify all the classes & define functions to create the database and retrieve individual information as and when required.

Source Code

#include<stdio.h>

#include<conio.h>

#include<iostream>

using namespace std;

class staff

{

        private: char name[20];

        int code;

        public: void getstaff()

        {

            cout<<"Enter name: ";

            cin>>name;

            cout<<"Enter code: ";

            cin>>code;

        }

void showstaff()

        {

            cout<<"name: "<<name<<endl;

            cout<<"code: "<<code<<endl;

        }

};

class teacher: public staff

        {

            private: char subject[20], publication[10];

            public: void getteacher()

        {

            getstaff();

            cout<<"Enter subject: ";

            cin>>subject;

            cout<<"Enter publication: ";

            cin>>publication;

        }

void showteacher()

        {

            showstaff();

            cout<<endl<<"Subject : "<<subject<<endl<<"publication: "<<publication<<endl;

        }

};

class typist: public staff

        {

            private:float speed;

            public: void gettypist()

            {

                getstaff();

                cout<<"Enter speed: ";

                cin>>speed;

            }

        void showtypist()

            {

                showstaff();

                cout<<"speed: "<<speed<<endl;

            }

        };

class regular: public typist

{

        private: int salary;

        public: void getregular()

        {

            gettypist();

            cout<<"Enter salary: ";

            cin>>salary;

        }

        void showregular()

        {

            showtypist();

            cout<<"salary: "<<salary<<endl;

        }

};

class casual: public typist

{

    private: int wage;  

    public: void getcasual()

        {

            gettypist();

            cout<<"Enter daily wage: ";

            cin>>wage;

        }

void showcasual()

        {

            showtypist();

            cout<<"wage: "<<wage<<endl;

        }

};

class officer: public staff

{

    private: char grade;

    public: void getofficer()

        {

            getstaff();

            cout<<"Enter grade: ";

            cin>>grade;

        }

void showofficer()

        {

                showstaff();

                cout<<"grade: "<<grade<<endl;

        }

};

int main()

{

        teacher t;

        regular r;

        casual c;

        officer o;

        cout<<"Enter data: "<<endl;

        cout<<"Teacher :"<<endl;

        t.getteacher();

        cout<<endl<<"regular typist: "<<endl;

        r.getregular();

        cout<<endl<<"casual typist: "<<endl;

        c.getcasual();

        cout<<endl<<"Officer : "<<endl;

        o.getofficer();

        cout<<endl<<endl<<"Display Database: "<<endl<<endl;

        t.showteacher();

        r.showregular();

        c.showcasual();

        o.showofficer();

        getch();

}

Output

create database and retrieve

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.