Array of structure program

Structure: the structure is a group of different data types. 
In this program, there is a structure called “student” it contains rollno, name, marks of five subjects. 
These are different data types. 

The program will accept all these things for 5 students and it will calculate the total and the percentage.

#include<iostream.h>
#include<conio.h>
 
struct student
{
int rollno;
char name[10];
int h,e,p,c,m,total,per;
};

main()
{
clrscr();
student s[5]; // array of structure

for (int i=0; i <=4; i=i+1)
{

 cout << "Enter any rollno";
 cin >> s[i].rollno;

 cout << "Enter any name";
 cin >> s[i].name;

 cout << "Enter marks of physics";
 cin >> s[i].p;

 cout <<"Enter marks of chemistry";
 cin >> s[i].c;

 cout << "Enter marks of maths";
 cin >> s[i].m;

  s[i].total=0;

  s[i].total=s[i].p+s[i].c+s[i].m;
  cout << "Total =";
  cout << s[i].total << endl;
  
  s[i].per=s[i].total/3;
  cout << "Per =";
  cout << s[i].per << endl;
}

getch();

}
 
 

 

Leave a Reply