Studytonight is now part of the GUVI universe. Explore GUVI →
🤩 New Cool Developer Tools for you. Explore →
FREE JavaScript Video Series Start Learning →
Signup/Sign In
Tests
MCQs to test your knowledge.
Compilers
Compilers to execute code in browser.
Index
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.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.

Learn to Code
Learn and practice coding side-by-side.
NEW
C language Course
115+ coding exercises
Javascript Course
85+ coding exercises

AltStyle によって変換されたページ (->オリジナル) /