Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

write a program to input employed id, name address and post of 20 employers and disply them

+1 vote
asked Feb 7, 2020 by labintumbapo (160 points)

1 Answer

0 votes
answered Feb 28, 2020 by Mohammad Danish
#include<iostream>
#include<string>
struct Employee
{
    long int _EmployeeID;
    std::string _Name;
    std::string _Address;
    std::string _Designation;
    void InsertDetails(int i)
    {
        std::cout <<"\n"<< i << "th Employee Details: \n";
        std::cout << "\nEnter the Employee ID: ";
        std::cin >> _EmployeeID;
        std::cin.ignore();
        std::cout << "\nEnter the Employee Name: ";
        getline(std::cin, _Name);
        std::cout << "\nEnter the Employee Address: ";
        getline(std::cin, _Address);
        std::cout << "\nEnter the Designation of the Employee: ";
        getline(std::cin, _Designation);
    }
    void DisplayDetails()
    {
        std::cout << "\nEmployee ID-: " << _EmployeeID;
        std::cout << "\nEmployee Name-: " << _Name;
        std::cout << "\nEmployee Address-: " << _Address;
        std::cout << "\nEmployee Designation-: " << _Designation;
    }
    ~Employee()
    {
        _EmployeeID = 0;
        _Name = '\0';
        _Address = '\0';
        _Designation = '\0';
    }
};
int main()
{
    int _numberOfEmployees;
    std::cout << "\nEnter the Number of Employees: ";
    std::cin >> _numberOfEmployees;
    Employee* _EmployeeObject=new Employee[_numberOfEmployees];
    for (int i = 0; i < _numberOfEmployees; i++)
    {
        _EmployeeObject[i].InsertDetails(i);
    }
    std::cout << "\nNOW DISPLAYING THE DETAILS OF THE EMPLOYEES\n";
    for (int i = 0; i < _numberOfEmployees; i++)
    {
        _EmployeeObject[i].DisplayDetails();
    }
    
    if(_EmployeeObject != NULL)
    {
        delete[] _EmployeeObject;
        _EmployeeObject = NULL;
        
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...