Back Button
Back to Chapter
C++ Introduction
No items found.
C++ Basics
No items found.
C++ Control Statements
No items found.
C++ Logical Operators
No items found.
C++ Procedural Programming
No items found.
C++ Structural Programming
No items found.
C++ Implementation of OOPS
No items found.
C++ Arrays and Vectors
No items found.
C++ Error Handling
No items found.
C++ File Handling
No items found.
Collapse_Icon
Table of Contents

Write a program to accept and display the data of employees and the salary of the employee.

Make a structure which consists of fields name, age, position and salary.

Using this structure declare a variable and use this variable to access the members of the structure and input the employee information. Finally display this information.

Solution:

#include using namespace std; //define a structure employee struct employee{ char name[20]; int age; int salary; char position[20]; }; void display(employee a)//function to display data { cout<<"name:"<>a.name; cout<<"enter age:"; cin>>a.age; cout<<"enter position:"; cin>>a.position; cout<<"Enter salary:"; cin>>a.salary; display(a); } main() { employee X;//declaring a structure input(X); return 0; }
Output: enter Name:Ray enter age:42 enter position:manager Enter salary:100000 name:Ray position:manager age:42 salary:100000

We define a structure and then we use this structure as a data type to declare variables of this structure. Each of these variables has all the members or fields of the structure to access these members we use variableName.member;