LAST UPDATED: MARCH 24, 2022
C++ Program For Store Employee Information And Display Using Structure
A structure is a collection of items of different data types. It is very useful in creating complex data structures with different data type records. A structure is defined with the struct keyword.
An example of a structure is as follows ?
struct employee {
int empID;
char name[50];
float salary;
};
Store Employee Information And Display Using Structure in C++
A program that stores and displays information using structure is given as follows.
#include <iostream>
using namespace std;
struct employee {
int empID;
char name[50];
int salary;
char department[50];
};
int main() {
struct employee emp[3] = { { 1 , "Harry" , 20000 , "Finance" } , { 2 , "Sally" , 50000 , "HR" } , { 3 , "John" , 15000 , "Technical" } };
cout<<"The employee information is given as follows:"<<endl;
cout<<endl;
for(int i=0; i<3;i++) {
cout<<"Employee ID: "<<emp[i].empID<<endl;
cout<<"Name: "<<emp[i].name<<endl;
cout<<"Salary: "<<emp[i].salary<<endl;
cout<<"Department: "<<emp[i].department<<endl;
cout<<endl;
}
return 0;
}
The employee information is given as follows:
Employee ID: 1
Name: Harry
Salary: 20000
Department: Finance
Employee ID: 2
Name: Sally
Salary: 50000
Department: HR
Employee ID: 3
Name: John
Salary: 15000
Department: Technical
Conclusion
Here, in this tutorial, we have implemented the C++ Program For Store Employee Information And Display Using Structure.