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.
/**
* 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>
usingnamespace 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.
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...
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.
/**
* 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>
usingnamespace 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';
elseif (score > highest * .8)
return'B';
elseif (score > highest * .7)
return'C';
elseif (score > highest * .6)
return'D';
elsereturn'F';
}
int main(){
cout << "Greetings, I'm your grade curver named Kolton Johnson." << endl;
constint maxscores = {100};
constauto 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: ";
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()};
^