A program to declare a structure student with the following data members:
a) adm_no                     integer
b) name character          array
c) marks                       array of five float values
Your program should accept the data of 10 students and then print the data of all the students including total marks, average marks and result, where result is calculated as follows:
If average marks is above 40% result is pass otherwise result is fail.

 

#include<iostream.h>
#include<stdio.h>
#include<conio.h>

struct student
{
int adm_no;
char name[30];
float marks[5];
};

void main()
{
student stud[2];

double total[2],avg_marks[2];
int i,j;

for(i=0;i<2;i++)
{
cout<<"Enter admission no.: ";
cin>>stud[i].adm_no;
cout<<"Enter name of student: ";
gets(stud[i].name);
cout<<"Enter marks in the five subjects:"<<endl;
for(j=0;j<5;j++)
{
cout<<"Percentage marks in subject no."<<j+1<<": ";
cin>>stud[i].marks[j];
total[i]= total[i] + stud[i].marks[j];
}
avg_marks[i]= total[i] / 5;
cout<<endl;
}

cout<<"\n*******************************************\n\n";

for(i=0;i<2;i++)
{
cout<<"Admission no.: "<<stud[i].adm_no<<endl;
cout<<"Name of student: ";
puts(stud[i].name);
cout<<"Percentage in the five subjects:"<<endl;
for(j=0;j<5;j++)
cout<<"Percentage in subject no."<<j+1<<": "<<stud[i].marks[j]<<endl;
cout<<"Total Marks: "<<total[i]<<"/500"<<endl;
cout<<"Average Marks: "<<avg_marks[i]<<endl;
cout<<"Result: ";
if(avg_marks[i]<40)
cout<<"Fail"<<endl<<endl;
else
cout<<"Pass"<<endl<<endl;
}

cout<<"*******************************************";

getch();
}

 

 

< Back