Module 5

Structures

Home > Courses > CP Lab > Structures

Programs with line-by-line explanations

Prepared by: Dr. Tojo Mathew

Warning! You are warned against blindly copying the code statements. Read the explanations given for the code statements and understand the implementation. Then, try to do it yourself. Blindly re-typing the code statements is a waste of time & effort.

Table of contents

5.1 Employee Details(Structure)

Write a C program to create a structure called Employee with members Name, Job, Salary. Create a structure variable. Accept the input values for the structure members at run time. Suitably display the same.

Input Format:

The first input is an integer which corresponds to the number of employees.

Second input is a character array which corresponds to the name of the employee.

Third input is a character array which corresponds to the job of the employee.

Fourth input is a float which corresponds to the salary of the employee.


Output Format

Output should display the employee details which are given in the sample input and output format.

Refer sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output]


Sample Input:

Enter the number of Employees :

3

Enter the details of Employee :1

Enter the Name :

Bala

Enter the Job :

SoftwareEngineer

Enter the Salary :

30000

Enter the details of Employee :2

Enter the Name :

Jenifer

Enter the Job :

Teacher

Enter the Salary :

10000

Enter the details of Employee :3

Enter the Name :

Kavin

Enter the Job :

Police

Enter the Salary :

25000


Output:

Details of Employee :1

Name :Bala

Job :SoftwareEngineer

Salary :30000.00

Details of Employee :2

Name :Jenifer

Job :Teacher

Salary :10000.00

Details of Employee :3

Name :Kavin

Job :Police

Salary :25000.00


Solution:

General description of program: Define a structure 'Employee' with members as name, job(designation), & salary. Create an array of structure to store details of n employees   where the value of n is a user input. Read the details of n employees from user and store in the array of Employee structure created. Display the details of all employees on screen.