-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructArray.cpp
53 lines (48 loc) · 1.08 KB
/
structArray.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
#include <iostream>
using namespace std;
void display(struct employee e[], int n);
struct employee {
int deptNo;
string name;
float salary;
};
int main()
{
employee emps[3];
// emps[0].deptNo = 1;
// emps[0].name = "Khan";
// emps[0].salary = 34;
for(int i=0; i<3; i++)
{
cout<<"Enter data for employee "<<i+1<<endl;
cout<<"Enter dept number: ";
cin>>emps[i].deptNo;
cout<<"Enter name: ";
cin.ignore();
getline(cin, emps[i].name);
cout<<"Enter salary: ";
cin>>emps[i].salary;
}
// cout<<emps[0].deptNo<<endl;
// cout<<emps[0].name<<endl;
// cout<<emps[0].salary<<endl;
// for(int i=0; i<3; i++)
// {
// cout<<"Employee "<<i+1<<" Data\n";
// cout<<"Dept no: "<<emps[i].deptNo<<endl;
// cout<<"Name: "<<emps[i].name<<endl;
// cout<<"Salary: "<<emps[i].salary<<endl;
// }
display(emps, 3);
return 0;
}
void display(employee e[], int n)
{
for(int i=0; i<n; i++)
{
cout<<"Employee "<<i+1<<" Data\n";
cout<<"Dept no: "<<e[i].deptNo<<endl;
cout<<"Name: "<<e[i].name<<endl;
cout<<"Salary: "<<e[i].salary<<endl;
}
}