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 72 73 74 75 76 77
|
#include <iostream>
#include <fstream>
using namespace std;
int highestGrade(int grade1, int grade2, int grade3); // Prototypes
char letterGrade(int high);
int main() // Main Function
{
string name; // Necessary variables
int grade1;
int grade2;
int grade3;
int highest;
char letter;
int count;
ifstream inputFile; // Opens Grades.txt to retrieve data
inputFile.open("Grades.txt");
ofstream outputFile; // Opens Results.txt to write data
outputFile.open("Results.txt");
for int count = 0; count < 4; count++) // Loop to handle all four students
{
inputFile >> name; // Takes the name and the assigns it to a variable, name
string name = name;
inputFile >> grade; // Takes the first grade and assigns it to a variable, grade1
int grade1 = grade;
inputFile >> grade; // Takes the second grade and assigns it to a variable, grade2
int grade2 = grade;
inputFile >> grade; // Takes the third grade and assigns it to a variable, grade3
int grade3 = grade;
int highestGrade(int grade1, int grade2, int grade3); // Calls the value returning function highestGrade, with grade1/2/3 as int inputs
char letterGrade(int highest); // Calls the value returning function letterGrade, with highest as an int input
outputFile << name; // Writes the name to the file Results.txt
outputFile << letter; // Writes the letter to the file Results.txt
return 0;
}
} // Ends the main function
int highestGrade(int grade1, int grade2, int grade3) // Defines the function highestGrade, and calculates which of the three variables (grade1,2,3) has the highest value and returns it
{
int grade1;
int grade2;
int grade3;
int highest = grade1;
if (grade2 > grade 1)
highest = grade2;
if (grade3 > highest)
highest = grade3;
return highest;
}
char letterGrade(highest) // Defines the function letterGrade, and calculates the letter grade based on the returned value 'highest' from the highestGrade function, and returns that value with the variable letter
{
if (highest >= 90)
letter = A;
if (highest >= 80, and not (highest >= 90))
letter = B;
if (highest >= 70, and not (highest >= 80))
letter = C;
if (highest >= 60, and not (highest >= 70))
letter = D;
else
letter = F;
return letter;
}
|