-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStructures_union_enum.cpp
More file actions
68 lines (59 loc) · 1.38 KB
/
Structures_union_enum.cpp
File metadata and controls
68 lines (59 loc) · 1.38 KB
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
#include <iostream>
using namespace std;
struct data
{
int id;
char name[10];
float salary;
};
union info
{
int id;
int aadhar;
int pan;
};
int main(){
int a,b;
// **********Structure************
struct data m;
cout<<"Enter the you id"<<endl;
cin>>m.id;
cout<<"now you have to enter the name"<<endl;
cin>>m.name;
cout<<"now you have to enter the salary"<<endl;
cin>>m.salary;
cout<<"your id is :"<<m.id<<endl;
cout<<"your name is :"<<m.name<<endl;
cout<<"your current salary is :"<<m.salary<<endl;
// **********Union****************
// union is as same as sturcture but we can acesses the only one
// data type in union
union info n;
cout<<"you have to choose what"<<"\n1 for id\n2 for aadhar\n3 for PAN"<<endl;
cin>>a;
switch (a)
{
case 1:
cout<<"you choosed to enter the college id"<<endl;
b=n.id;
break;
case 2:
cout<<"you choosed to enter the aadhar number"<<endl;
b=n.aadhar;
break;
case 3:
cout<<"you choosed to enter the PAN number"<<endl;
b=n.pan;
break;
default:
break;
}
cin>>b;
cout<<b;
// ******Enum*********
// basically it used to make the code easy to read ;
enum meal { breakfast, lunch, dinner};
cout<<breakfast<<endl;
cout<<lunch<<endl;
cout<<dinner<<endl;
}