-
Notifications
You must be signed in to change notification settings - Fork 0
/
C ++ Struct Syntax definition.cpp
97 lines (71 loc) · 2.59 KB
/
C ++ Struct Syntax definition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
[PROGRAM] : C/C++ struct
[AUTHOR] : Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
A structure is a user defined data type in C/C++.
Syntax of struct
struct structureName
{
dataType member1;
dataType member2;
...
}; */
#include <iostream>
using namespace std;
//define Employee struct
typedef struct
{
int id; // for Employee id number
char name[30]; // for Employee name
float salary; // for Employee salary
char job [30]; // for Employee job
} Employee;
// A utility function to get Employee information
void get_Data(Employee[], int);
// A utility function to print All Employee information
void print(Employee[], int );
// the Driver Code
int main()
{
// variable n declaration and initialize by 5
int n = 2; // n is the number of employees
Employee employees[n]; // employees array of type Employee declaration
/* calling a function to get employees information from user.*/
get_Data(employees, n);
/* calling a function to print employees information .*/
print(employees, n);
return 0;// signal to operating system everything works fine
}/** End of main function */
// A utility function to get Employee information from user
void get_Data(Employee employees[], int size)
{
//Taking each employee detail as input
cout << "Enter "<< size << " employee informations" << endl;
for(int i = 0; i < size; i++)
{
cout << "Employee number " << i + 1 << " information\n";
cout << "Enter employee Name :"; // employee i Name
cin >> employees[i].name;
cout << "Enter employee ID :"; // employee i ID
cin >> employees[i].id;
cout << "Enter employee JOB:"; // employee i job
cin >> employees[i].job;
cout << "Enter employee Salary:"; // employee i Salary
cin >> employees[i].salary;
cout << endl;// go new line
}
} /** end of get_Data()*/
// A utility function to print All Employee informations
void print(Employee employees[], int size)
{
// printing all employees information
cout << "Printing All Employees Informations \n";
for(int i = 0; i < size; i++)
{
cout <<"Employee number " << i + 1 << " information" <<endl;
cout << "Name \t: " << employees[i].name << endl; // printing name
cout << "ID \t: " << employees[i].id << endl; // printing ID
cout << "Salary \t: " << employees[i].salary << endl; // printing salary
cout << "JOB \t: " << employees[i].job << endl; // printing job
}
} /** end of print()*/