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
|
#include <stdio.h>
#include <iostream>
#include <string>
#define MAX_ENTRIES 50
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
string student_name[MAX_ENTRIES];
int test_score[MAX_ENTRIES];
char grade_score[MAX_ENTRIES];
int count = 0;
int sum = 0, i, high_stud_name;
double average;
char letter_grade[5] = {'A','B','C','D','F'};
int grade[5] = { 90, 80, 70, 60, 0 };
cout << "This is a grading program" << endl;
cout << "It will generate a letter grade from points." << endl;
cout << "All grades are generated from 100 point scores." << endl;
cout << "When prompted please input student names and points" << endl;
cout << "and when finished, input a zero as a name, and it will assign letter grades" << endl << endl;
do
{
cout << "Enter one of your student's name: " << endl;
cin >> student_name[count];
if (student_name[count] != "0")
{
cout << "Enter the student's test score: " << endl;
do{
cin >> test_score[count];
if (test_score[count] > 100) // Check if scores are out of input ranges
cout << "Test scores can NOT exceed 100. Re-enter test score." << endl;
if (test_score[count] < 0)
cout << "Test scores can NOT be less than zero. Re-enter test score." << endl;
} while (test_score[count] < 0 || test_score[count] > 100);
sum += test_score[count]; // Increase sum
count++; // Increase count
}
}while (count < MAX_ENTRIES && student_name[count] != "0");
for (i = 0; i < count; i++)
{
for (int x = 0; x < 5; x++)
{
if (test_score[i] >= grade[x])
{
grade_score[i] = letter_grade[x]; // Found grade and assigned letter
x = 5; // So, exit the x loop
}
}
}
cout << endl << "Student ID\tTest Score\tLetter Grade" << endl;
cout << "----------\t----------\t------------" << endl;
for (i = 0; i<count; ++i)
cout << student_name[i] << "\t\t" << test_score[i] << "\t\t" << grade_score[i] << endl;
return 0;
}
|