Monday, 14 March 2016

C++ Program For Store Employee Information And Display Using Structure

Problem:- 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 array of objects or c program to generate employee details using structure or
c++ 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 

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Before going to actual problem let's know Structure in brief.

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 Student which consists of student name, address, roll number and age. You can define a structure to hold this information.

Defining a structure

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 variables and member of the structure.

Logic:- So as we get some basic idea about structure now we define the structure and structure name is  Employee( you can change ) and its variable is ID, Name, Age, and Salary, as you can see that now our structure looks like 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). at the end we have to print the value stored in structure to console this will help to check your structure is performing well or not. Here I use iomanip for manipulating data better like while printing the data of structure systematic manner and the setw() is used for print the data in manner  

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

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

Tip:- I recommended please read this full article and suggest post and most important always try to solve "Try This" if any available. If you like my work please share, comments and subscribe for all about new post and Article.

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

Solution:-

#include<iostream>
#include<iomanip>
using namespace std;

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

int main()
{
    int i, n;  

/*Visit www.programmingwithbasics.com*/

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 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 << "Details of Employees";
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";

}

Output:-

C++ Program For Store Employee Information And Display Using Structure


C++ Program For Store Employee Information And Display Using Structure


You May Like This:-

1. Hacker Rank Solution for 30 Days of Code

2. Hacker Rank solution for Attribute Parser

3. Java Program For Find The Gross Salary Of An Employee

4. C++ Program For School Management System ( SMS Project ) With Source Code

5. Hacker Rank Solution For Mini-Max Sum

6. Hacker Rank Solution For Birthday Cake Candles

7. C++ Program For Store Employee Information And Display Using Structure

8. C Program For Find A Grade Of Given Marks Using Switch Case

9. C Program For HEAP Sort In Ascending Order Also Show Complexity

10. C++ Program For Selection Sort Using Function


5 comments:
Write comments
  1. good work bro..-biplab(M.Sc(Tech) Engg Physics, NITW)

    ReplyDelete
    Replies
    1. Welcome Bro Ghanendra Yadav(MCA CSE NITW)

      Delete
  2. Good work bro i am following your program, please could have the code for search, save, update,delete and exit of the employees. Thanks i will appreciate it.

    ReplyDelete
  3. Replies
    1. Thank You Very Much Bro. Thanks for Visit, Keep visit and share

      Delete

Recommended Posts × +