Curving the Grade

Write a program to help determine a grade curve. The program reads all the student scores, determines the highest score, and then assigns grades based on the following scheme:

Grade is A if score is > highest*.9
Grade is B if score is > highest*.8
Grade is C if score is > highest*.7
Grade is D if score is > highest*.6
Grade is F otherwise.
The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. Here is a sample run:

Greetings, I'm your helpful grade curver named Brent.
Enter the number of students: 4
    Enter 4 scores: 40 55 70 58
    Student 1: F
    Student 2: C
    Student 3: A
    Student 4: B
Grading complete.  Goodbye.



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
/**
 * File: Curving the Grade
 * Author: Jake John
 * Course: CS I
 * Assignment: Curving the Grade
 * Due Date: March 15, 2021
 *
 * The program prompts the user to enter the total 
 * number of students, then prompts the user to enter 
 * all of the scores, and concludes by displaying the grades. 
 */

#include <bits/stdc++.h>
using namespace std;

int numStudents(){
	
	cout << "Enter the number of students: ";
	cin >> num;
	
	return num;
}

int gradeArray(){
	
	cout << "	Enter " << numStudents << " scores: ";
	
	
}

int main(){
	
	int numStudents;
	
	cout << "Greetings, I'm your grade curver named Kolton Johnson." << endl;
	cout << "Enter the number of students: ";
	cin >> numStudents;
	cout << "	Enter " << numStudents << " scores: ";
	
	
	
	return 0;
}



Here is what I have and I am stuck on how I Should start/ fix my array.
Last edited on
arrays have a fixed size, so you need to pick a size bigger than what is necessary for running the program. Later you can use vectors, which can change size at run time. Here, 1000 for example.
you declare an array like this:
int grades[1000]{}; //initialized them all to zero with the {} part. [size] is the array part.

then you can access it:
grades[0] = 40; //the first grade is a 40. note that it is indexed [index] from zero, not 1.
or a loop:
for(int i = 0; i < numgrades; i++)
cin >> grades[i]; //read each grade...

and so on.
Last edited on
I'm really confused about what you are saying. Why would I set the first grade to 40? the grades could change based on the input.
Something like:

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
#include <iostream>
using namespace std;

size_t numStudents()
{
	size_t num {};

	cout << "Enter the number of students: ";
	cin >> num;

	return num;
}

char grade(double score, double highest)
{
	if (score > highest * .9)
		return 'A';

	if (score > highest * .8)
		return 'B';

	if (score > highest * .7)
		return 'C';

	if (score > highest * .6)
		return 'D';

	return 'F';
}

int main()
{
	cout << "Greetings, I'm your helpful grade curver named seeplus.\n";

	const size_t maxscores {100};
	const auto num {numStudents()};
	double scores[maxscores] {};
	double highest {};

	cout << "Enter " << num << " scores: ";

	for (size_t i = 0; i < num && i < maxscores; ++i) {
		cin >> scores[i];

		if (scores[i] > highest)
			highest = scores[i];
	}

	for (size_t i = 0; i < num && i < maxscores; ++i)
		cout << "Student " << i + 1 << ": " << grade(scores[i], highest) << '\n';
}

it was an example of how to access the array, without writing the whole thing for you.
I was not giving you live code to copy but an answer to your question, how to use an array.
Last edited on
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
/**
 * File: Curving the Grade
 * Author: Jake John
 * Course: CS I
 * Assignment: Curving the Grade
 * Due Date: March 15, 2021
 *
 * The program prompts the user to enter the total 
 * number of students, then prompts the user to enter 
 * all of the scores, and concludes by displaying the grades. 
 */

#include <bits/stdc++.h>
using namespace std;

int numStudents(){
	
	int num = {0};
	
	cout << "Enter the number of students: ";
	cin >> num;
	
	return num;
}

char grade(double score, double highest){
	if (score > highest * .9)
		return 'A';

	else if (score > highest * .8)
		return 'B';

	else if (score > highest * .7)
		return 'C';

	else if (score > highest * .6)
		return 'D';
	
	else
		return 'F';
	
}

int main(){
	
	cout << "Greetings, I'm your grade curver named Kolton Johnson." << endl;
	
	const int maxscores = {100};
	const auto num {numStudents()};
	double scores[maxscores] = {0};
	double highest = {0};

	cout << "Enter " << num << " scores: ";

	for (size_t i = 0; i < num && i < maxscores; ++i) {
		cin >> scores[i];

		if (scores[i] > highest)
			highest = scores[i];
	}

	for (size_t i = 0; i < num && i < maxscores; ++i)
		cout << "Student " << i + 1 << ": " << grade(scores[i], highest) << '\n';
	
	return 0;
}


There are two errors.
g++ "Curving the Grade.cpp" -o "Curving the Grade.exe"
Curving the Grade.cpp: In function 'int main()':
Curving the Grade.cpp:49:13: error: 'num' does not name a type
  const auto num {numStudents()};
             ^
Curving the Grade.cpp:53:22: error: 'num' was not declared in this scope
  cout << "Enter " << num << " scores: ";
It thinks it's an initializer list because of the {} syntax you're using. Just write 'int' instead of 'auto' on line 49.

seeplus,
Greetings, I'm your helpful grade curver named seeplus
Haha, so you admit you're just doing the work for ungrateful people. :)
Last edited on
I changed the 'auto' to 'int' and it still has an error.

g++ "Curving the Grade.cpp" -o "Curving the Grade.exe"
Curving the Grade.cpp: In function 'int main()':
Curving the Grade.cpp:49:16: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
  const int num {numStudents()};
                ^
only available with -std=c++11


It's 2021. Time to upgrade your compiler.
Topic archived. No new replies allowed.