A structure stores details of 5 students (roll number, name, marks in 5 subject ). Write a program to prepare a rank list of students. Also print out a list of students who have failed in more than one subject.
#include <iostream>
#include <string>
using namespace std;
struct student{
int rollNumber;
string name;
int marksSubject[5];
};
int main(){
student students[5];
int rollNumber;
string name;
int mark;
//read info from the user
for(int i=0;i<5;i++){
cout<<"Enter the student roll number: ";
cin>>rollNumber;
cin.ignore();
cout<<"Enter the student name: ";
getline(cin,name);
students[i].rollNumber=rollNumber;
students[i].name=name;
for(int s=0;s<5;s++){
mark=-1;
while(mark<0 || mark>100){
cout<<"Enter the student mark [0-100]: ";
cin>>mark;
}
students[i].marksSubject[s]=mark;
}
cout<<"\n";
}
//print out a list of students who have failed in more than one subject.
for(int i=0;i<5;i++){
int numberFailedSubjects=0;
for(int s=0;s<5;s++){
if(students[i].marksSubject[s]<60){
numberFailedSubjects++;
}
}
if(numberFailedSubjects>1){
cout<<"The student "<<students[i].name<<" failed in more than one subject.\n";
}
}
return 0;
}
Comments
Leave a comment