01/03/2023

Write a C++ Program For Employee Details Using Structure

C++ program for employee details using class and object or c++ program to get and display employee details using class and object or c++ program for employee details using an array of objects or c program to generate employee details using structure orc++ program to calculate employee salary using class or c++ program for employee details using constructor or employee program in c++ using inheritance or employee management system project in c++ with file handling

So as we get some basic idea about structure now we define the structure and the structure name is Employee( you can change it) and its variable is ID, Name, Age, and Salary, as you can see that now our structure looks like the above syntax of the structure. Now the next step is to take the user input and store the user input value in structure with the help of 'For Loop' (you can use while and do while loops).

C++ Program For Employee Details Using Structure

At the end we have to print the value stored in the structure to the console this will help to check whether your structure is performing well or not. Here I use iomanip for manipulating data better like while printing the data in a structured systematic manner and the setw() is used to print the data in a manner

Setw()
 
Sets the field width to be used on output operations, it comes under the iomainp header file.


Try This: C++ Program For Store Book Details Using Structure

C++ Program For Employee Details Using Structure


#include <iostream>
#include <iomanip>

using namespace std;

struct Employee
{
	int Id;
	char Name[25];
	int Age;
	long Salary;
};

int main()
{
	int i, n;

	/*Write a C++ Program to Get and Display Employee Details Using Structure
	 */

	cout << "\nEnter The Number of Employee\n\n";
	cin >> n;

	Employee Emp[n];	// Structure object created emp

	for (i = 0; i < n; i++)
	{
		cout << "\nEnter Employee Details of " << i + 1 << " Employee" << endl;

		cout << setw(5) << "\nEnter Employee ID: ";
		cin >> Emp[i].Id;

		cout << setw(5) << "\nEnter Employee Name: ";
		cin >> Emp[i].Name;

		cout << setw(5) << "\nEnter Employee Age: ";
		cin >> Emp[i].Age;

		cout << setw(5) << "\nEnter Employee Salary: ";
		cin >> Emp[i].Salary;
	}

	cout << "\n\n------------------------------------------------------------\n";
	cout << "Display Employee Details";
	cout << "\n------------------------------------------------------------\n\n";

	cout << "ID" << setw(15) << "Name" << setw(10) << "Age" << setw(10) << "Salary";
	cout << endl;
	for (i = 0; i < n; i++)
	{
		cout << "\n" << Emp[i].Id << setw(15) << Emp[i].Name << setw(10) << Emp[i].Age << setw(10) << Emp[i].Salary;
	}

	cout << "\n\n------------------------------------------------------------\n";

}

The Output in Employee Details Using Structure in C++


The Output in Employee Details Using Structure in C++


c++ program for employee details using array of objects

What Is Structure


The structure is a user-defined data type in C++. The structure is used to represent a record. Suppose you want to store a record of a Student which consists of the student's name, address, roll number and age. You can define a structure to hold this information.

Defining a Structure


The struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.

Syntax:

struct structure_name
{
Statement...........1
Statement...........2
Statement...........3
.
.
.
Statement...........n
};


Note: here statement refers to variables and members of the structure.

Similar to Employee Details Using Structure


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: