/*PROGRAM TO SHOW CONCEPT OF ARRAY AND UNION*/
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
class struct_union
{
int i;
struct
{
char n[10];
int roll_no;
}s;
union
{
char n[10];
int roll_no;
}u;
public:
void struct_in();
void struct_out();
void union_process();
};
void struct_union::struct_in()
{
cout<<“Enter the data of the student:\n”;
cout<<“Enter name: “;
gets(s.n);
cout<<“Enter roll number: “;
cin>>s.roll_no;
}
void struct_union::struct_out()
{
cout<<“\n********Entered data of the student is:********\n”;
cout<<” Name: “<<s.n<<endl;
cout<<” Roll no: “<<s.roll_no<<endl;
}
void struct_union::union_process()
{
cout<<“Enter the data of the student:\n”;
cout<<“Enter name: “;
gets(u.n);
cout<<” Name: “<<u.n<<endl;
cout<<“Enter roll number: “;
cin>>u.roll_no;
cout<<” Roll no: “<<u.roll_no<<endl;
}
void main()
{
struct_union a1;
clrscr();
cout<<“STRUCTURE IMPLEMENTATION”<<endl;
a1.struct_in();
a1.struct_out();
cout<<“\nUNION IMPLEMENTATION”<<endl;
a1.union_process();
getch();
}