Here, I've done the first half for you.
I've placed comments where I think they might be helpful.
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
|
#include <iostream>
int main() {
int num_students = 0;
//This variable represents the number of students in the class.
//Since there is one grade per student, it also represents the number of grades.
std::cout << "Enter the number of students in your class:\t";
std::cin >> num_students;
std::cout << std::endl;
int* grades = new int[num_students] {};
//This is a dynamic array called 'grades'.
//We use the 'new' operator to dynamically allocate the desired amount of integers.
//For example, if the teacher enters '3' for num_students, this array will have three integers.
//Each integer in this array represents one grade.
const int fail_threshold = 69;
//Any grade above this value is considered to be 'passing'.
//Any grade below this value is considered to be 'failing'
int input = 0;
//This integer will be used to read the teacher's input.
//We're about to enter a for-loop.
//One iteration per student
for (int i = 0; i < num_students; ++i) {
std::cout << "Enter grade for student #" << (i + 1) << " of " << num_students << ":\t";
std::cin >> input;
if (input > fail_threshold) {
std::cout << "Student #" << (i + 1) << " passed." << std::endl;
}
else {
std::cout << "Student #" << (i + 1) << " failed." << std::endl;
}
std::cout << std::endl;
}
//More code goes here
delete[] grades;
//We have to make sure to de-allocate our previously allocated memory.
return 0;
}
|
This snippet prompts the teacher to enter the number of students in their class.
Then, for each student in the class, the teacher is asked to enter a corresponding grade.
If an entered grade is below a certain threshold, a "failed" message is printed.
If an entered grade is above that threshold, a "passed" message is printed.
What's left for you to do:
Tally each time a student fails.
Tally each time a student passes.
Process the grades - determine the following:
The highest of all the grades.
The lowest of all the grades.
The average grade.
The number of A's.
The number of B's.
The number of C's.
The number of D's.
(For these it would help to have different thresholds for each)
Finally, print all the results. Don't forget to print the number of failing/passing students.