Saturday 12 August 2017

Create an employee class. The member data should comprise an int for storing the employee number and a float for storing the employee’s compensation. Member functions should allow the user to enter this data and display it.



Create an employee class. The member data should comprise an int for storing the employee number and a float for storing the employee’s compensation. Member functions should allow the user to enter this data and display it.
Write a main() that allows the user to enter data for three employees and display it.
SOLUTION:
#include "stdafx.h"
#include "iostream"
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////class employee
{
            private:
                        int E_num;
                        float E_comp;
            public:
                        void input( )
                        {
                                    cout << "Enter Employee Number ";  cin >> E_num;
                                    cout << "Enter Employee's Compensation "; cin >> E_comp;
                        }
                        void display( )
                        {
                                    cout << E_num<<"\t\t$  " << E_comp << "\n";
}
};
/////////////////////////////////////////////////////////////////////////////////////////void main( )
{
employee E1,E2,E3;
E1.input( );
E2.input( );
E3.input( );
cout << "\nNumber\t\tCompensation\n\n";
E1.display( );
E2.display( );
E3.display( );
system("pause");
}
OUTPUT:


1 comment:


  1. #include "iostream" // Helder File
    using namespace std; // For InPut OutPut Perpose
    class employee // Class
    {
    private: // CLass By Deflat Privete
    int Number;
    float comp;
    public:
    void input( ) // Input Value Funtion
    {
    cout << "Please Enter Employee Number : ";
    cin >>Number;
    cout << "Please Enter Employee's Compensation : ";
    cin >>comp;
    }
    void display( ) // Display On Console Screen
    {
    cout <<Number<<"\t\t$ " <<comp << "\n";
    }
    };
    int main () // Main Funtion
    {
    employee E[3]; // Using Arry If Next Time For More Employee

    for(int i =0 ;i<3 ; i++) // using For Loop To Input Value
    {
    E[i].input();
    }
    cout<<"\n***********************************";
    cout<<"\n******* Your Input Data Is ********";
    cout<<"\n***********************************";
    cout << "\nNumber\t\tCompensation\n\n";
    for(int i =0 ;i<3 ; i++) // Using For Loop To Display Data
    {
    E[i].display();
    }

    }

    ReplyDelete