Answer to Question #325861 in C++ for Anji

Question #325861

The principal of a school wants to speak with some of the students to assess their over all development including studies,most of the teachers were selecting the toppers of their classes but Mr,sam thought of an idea to select the bunch of students who did not have much difference in their marks so that he gains the reputation of a teacher who teaches well to the whole class and not just to a bunch of brilliant students.

Your are required to help mr,sam in selecting K students that can speak with principle from his class .you need to return an integer array representing the marks of the selected students sorted in ascending order.

Example1:

Input1:10

Innput2:{950,477,55,602,881,302,859,438,551,382}

Input3:1

Output:{950}


1
Expert's answer
2022-04-12T13:28:25-0400
#include<iostream>
#include<algorithm>

using namespace std;

bool Descending(int x, int y)
{
	if (x > y)return true;
	else return false;
}

int main()
{
	int numScores;
	cout << "Please, enter a num of scores: ";
	cin >> numScores;
	int* arr = new int[numScores];
	cout << "Please, enter " << numScores << " values: ";
	for (int i = 0; i < numScores; i++)
	{
		cin >> arr[i];
	}
	sort(&arr[0], &arr[numScores], Descending);
	int better;
	cout << "Please, enter number of better scores: ";
	cin >> better;
	for (int i = 0; i < better; i++)
	{
		cout<<arr[i]<<" ";
	}
	delete []arr;
}	

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