arrays

I need help! on how to display the students grades in increasing order of the number of correct answers.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;

int main()
{
	const int numbStudents = 8;
	const int numbQuestions = 10;

	//Students' answers to the questions
	char answers[numbStudents][numbQuestions] =
	{
		{'A','B','A','C','C','D','E','E','A','D'},
		{'D','B','A','B','C','A','E','E','A','D'},
		{'E','D','D','A','C','B','E','E','A','D'},
		{'C','B','A','E','D','C','E','E','A','D'},
		{'A','B','D','C','C','D','E','E','A','D'},
		{'B','B','E','C','C','D','E','E','A','D'},
		{'B','B','A','C','C','D','E','E','A','D'},
		{'E','B','E','C','C','D','E','E','A','D'},
	};

	//Key to the questions
	char keys[] = {'D','B','D','C','C','D','A','E','A','D'};

	//Grade all answers
	for (int i = 0; i < numbStudents; i++)
	{
		//Grade one student
		int correctCount = 0;
		for (int j = 0; j < numbQuestions; j++)
		{
			if (answers[i][j] == keys[j])
				correctCount++;
		}
	
		cout << "Student " << i << "'s correct count is " << correctCount << endl;
	}
	return 0;
}
This is the output
1
2
3
4
5
6
7
8
9
 Student 0's correct count is 7
Student 1's correct count is 6
Student 2's correct count is 5
Student 3's correct count is 4
Student 4's correct count is 8
Student 5's correct count is 7
Student 6's correct count is 7
Student 7's correct count is 7
Press any key to continue . . . 
Last edited on
Since you're probably not concerned about efficiency, let's take a brute force approach.

You can do a selection sort. Although the simplest implementation of a selection sort is not stable, you can do extra checks to make it so.

Try searching the web for the algorithm. It's pretty common and I think that algorithm is one of the solution on top of your head.
This is what u need!!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
                                                                                                             
#include <iostream>
using namespace std;

 int main()
{
	const int numbStudents = 8;
	const int numbQuestions = 10;

	int StudentsMarktemp[numbStudents];


	//Students' answers to the questions
	char answers[numbStudents][numbQuestions] =
	{
		{'A','B','A','C','C','D','E','E','A','D'},
		{'D','B','A','B','C','A','E','E','A','D'},
		{'E','D','D','A','C','B','E','E','A','D'},
		{'C','B','A','E','D','C','E','E','A','D'},
		{'A','B','D','C','C','D','E','E','A','D'},
		{'B','B','E','C','C','D','E','E','A','D'},
		{'B','B','A','C','C','D','E','E','A','D'},
		{'E','B','E','C','C','D','E','E','A','D'},
	};

	//Key to the questions
	char keys[] = {'D','B','D','C','C','D','A','E','A','D'};

	//Grade all answers
	for (int i = 0; i < numbStudents; i++)
	{
		//Grade one student
		int correctCount = 0;
		for (int j = 0; j < numbQuestions; j++)
		{
			if (answers[i][j] == keys[j])
				correctCount++;
		}

		StudentsMarktemp[i] = correctCount;
	}
	int temp = 0;

	int k=0;
	int max =0; 
	while (k!=8)
	{
			temp =0;
			max = StudentsMarktemp[0];
			
			for (int j=0;j<numbStudents;j++)
			{
				if ((max<StudentsMarktemp[j]))
				{

					max = StudentsMarktemp[j];
					temp = j;
				}
			}
			cout << "Student " << temp << "'s correct count is " << StudentsMarktemp[temp] << endl;
			StudentsMarktemp[temp] =-1;
		k++;
	}

	getchar();

	return 1;


}
Last edited on
Hey Steakrider ! Thank's for the help!!!
i am glad to help you;)
Topic archived. No new replies allowed.