Answer to Question #180488 in C++ for Kanav Garg

Question #180488

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.


1
Expert's answer
2021-04-12T02:27:57-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS