PROGRAM TO SHOW ARRAY OF STRUCTURES

/*PROGRAM TO SHOW ARRAY OF STRUCTURES*/

#include<conio.h>

#include<iostream.h>

#include<stdio.h>

class arr_struct

{

int i;

struct

{

char n[10];

int roll_no;

float marks;

}s[5];

public:

void input();

void output();

};

void arr_struct::input()

{

cout<<“Getting the data of five students:\n”;

for(i=0;i<5;i++)

{

cout<<“Enter data of “<<i+1<<” student:\n”;

cout<<“Enter name: “;

gets(s[i].n);

cout<<“Enter roll number: “;

cin>>s[i].roll_no;

cout<<“Enter marks: “;

cin>>s[i].marks;

}

}

void arr_struct::output()

{

cout<<“Entered data of the students is:\n”;

for(i=0;i<5;i++)

{

cout<<“Data of “<<i+1<<” student is:\n”;

cout<<”   Name: “<<s[i].n<<endl;

cout<<”   Roll no: “<<s[i].roll_no<<endl;

cout<<”   Marks: “<<s[i].marks<<endl;

}

}

void main()

{

arr_struct a1;

clrscr();

a1.input();

a1.output();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *