Write a C++ program to declare a structure for a student record consisting of the following fields:
·
RegNo //Registration
Number
·
Name //Name with
initial
·
Marks1 //1st
Assessment marks
·
Marks2 //2nd
Assessment marks
·
Total //Total of two marks
·
Avg // Average of two marks
Write a
program to keep the records for five students including functions to do the
following task.
·
Read the student’s data.
·
Calculate the total marks
and average for each student.
·
Display the students’
details.
#include<iostream>
using namespace std;
int main(){
struct
data{
string
RegNo;
string
Name;
int
Mark1;
int
Mark2;
int
Total;
float
Avg;
};
data
stud[5];
for(int
i=0;i<5;i++){
cout<<"enter
student "<<i+1<<" reg no = ";
cin>>stud[i].RegNo;
cout<<"enter
student "<<i+1<<" name = ";
cin>>stud[i].Name;
cout<<"enter
student "<<i+1<<" 1st assesment marks = ";
cin>>stud[i].Mark1;
cout<<"enter
student "<<i+1<<" 2nd assesment marks = ";
cin>>stud[i].Mark2;
stud[i].Total=stud[i].Mark1+stud[i].Mark2;
stud[i].Avg=(stud[i].Total)/2;
cout<<endl;
}
for(int
i=0;i<5;i++){
for(int
j=i+1;j<5;j++){
if(stud[i].Total<stud[j].Total){
data
temp;
temp=stud[i];
stud[i]=stud[j];
stud[j]=temp;
}
}
}
cout<<"RegNo\tName\ttotal\tAverage"<<endl;
for(int
j=0;j<5;j++){
cout<<stud[j].RegNo<<"\t"<<stud[j].Name<<"\t"<<stud[j].Total<<"\t"<<stud[j].Avg<<endl;
}
}
0 Comments