PROGRAM TO SHOW ARRAY INSIDE STRUCTURES

/*PROGRAM TO SHOW ARRAY INSIDE STRUCTURES*/

#include<conio.h>

#include<iostream.h>

#include<stdio.h>

class arr_struct

{

int i;

struct

{

char n[10];

int roll_no,total;

int marks[5];

}s;

public:

void input();

void output();

};

void arr_struct::input()

{

cout<<“Enter the data of the student:\n”;

cout<<“Enter name: “;

gets(s.n);

cout<<“Enter roll number: “;

cin>>s.roll_no;

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

{

cout<<“Enter marks in “<<i+1<<” subject: “;

cin>>s.marks[i];

}

}

void arr_struct::output()

{

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

cout<<”   Name: “<<s.n<<endl;

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

s.total=0;

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

{

cout<<”   Marks in “<<i+1<<” subject:”<<s.marks[i]<<endl;

s.total=s.total+s.marks[i];

}

cout<<”   Total marks are: “<<s.total;

}

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 *