Answer to Question #258312 in C++ for Alemnat

Question #258312

1.     Write a function accepts list of marks of students and counts the number of students who have scored marks greater than 20 in an exam out of 30. The total number of students who took the test is to be entered from the keyboard. 



1
Expert's answer
2021-10-28T15:20:32-0400
#include<iostream>
#include<string>
using namespace std;


int numberStudents(int* tests,int totalNumberStudents){
	int counter=0;
	for(int i=0;i<totalNumberStudents;i++){
		if(tests[i]>=20){
			counter++;
		}
	}
	return counter;
}




int main(){
	int totalNumberStudents;
	int* tests; 
	cout<<"Enter the total number of students who took the test: ";
	cin>>totalNumberStudents;
	tests=new int[totalNumberStudents];
	for(int i=0;i<totalNumberStudents;i++){
		cout<<"Enter the test "<<(i+1)<<": ";
		cin>>tests[i];
	}


	cout<<"\nThe number of students who have scored marks greater than 20 in an exam is: "<<numberStudents(tests,totalNumberStudents)<<"\n\n";


	delete[] tests;


	cin>>totalNumberStudents;




	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