C++ Program to Display the Details of Employee Using Array of Structure

In this program, you'll learn to declare a structure 'employee' having name, designation and salary. Accept and display this information for five members.



Source Code
#include<iostream>
using namespace std;

struct employee
{
    char name[20];
    char designation[20];
    int salary;
} s[5];

int main()
{
    int i;
    //Accepting information
    cout<<"Enter details of 5 employees:\n";
    for(i=0; i<5; i++)
    {
        cout<<"Enter name :";
        cin>> s[i].name;
        cout<<"Enter designation :";
        cin>> s[i].designation;
        cout<<"Enter salary :";
        cin>> s[i].salary;
    }
    //displaying information
    cout<<"\nThe details of employees are :\n";
    for(i=0; i<5; i++)
    {
        cout<< s[i].name << "\t" << s[i].designation << "\t" <<  s[i].salary  << "\n";
    }
    return 0;
}
Output
Enter details of 5 employees:
Enter name :Mike
Enter designation :Accountant
Enter salary :15000
Enter name :Suraj
Enter designation :Professor
Enter salary :35000
Enter name :Harish
Enter designation :Clerk
Enter salary :15550
Enter name :Arnav
Enter designation :Professor
Enter salary :50000
Enter name :Shashank
Enter designation :Lecturer
Enter salary :25000

The details of employees are :
Mike    Accountant      15000
Suraj   Professor       35000
Harish  Clerk   15550
Arnav   Professor       50000
Shashank  Lecturer        25000