In: Computer Science
PLEASE DESCING A FLOWCHART IN FLOWGORITHM
Test Average and Grade
Write a program that asks the user to enter five test scores. The program should display a letter grade for each the five test score and the average test score. Design the following functions in the program :
-calAverge This function should accept five test scores as arguments and return the average of the scores.
-determineGrade This function should accept a test score as an argument and return a letter grade for the score (as a string), based on the following grading scale
Score Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F
THANK YOU
Following is the design of the flowchart for the given problem using Flowgorithm.
Main function:
calAverage function:
determineGrade function:
Output:
95
63
86
72
45
72.2
A
D
B
C
F
C++ code:
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
// Headers
string toString (double);
int toInt (string);
double toDouble (string);
double calAverage(int[] m);
string determineGrade(int m);
int main() {
int marks[5];
int i;
string grade[5];
for (i = 0; i <= 4; i++) {
cin >> marks[i];
grade[i] = determineGrade(marks[i]);
}
double average;
average = calAverage(marks);
cout << average << endl;
for (i = 0; i <= 4; i++) {
cout << grade[i] << endl;
}
return 0;
}
double calAverage(int[] m) {
double average;
average = 0;
int sum;
sum = 0;
int i;
for (i = 0; i <= 4; i++) {
sum = sum + m[i];
}
average = (double) sum / 5;
return average;
}
string determineGrade(int m) {
string grade;
if (m >= 90 && m <= 100) {
grade = "A";
} else {
if (m >= 80 && m <= 89) {
grade = "B";
} else {
if (m >= 70 && m <= 79) {
grade = "C";
} else {
if (m >= 60 && m <= 69) {
grade = "D";
} else {
grade = "F";
}
}
}
}
return grade;
}
// The following implements type conversion functions.
string toString (double value) { //int also
stringstream temp;
temp << value;
return temp.str();
}
int toInt (string text) {
return atoi(text.c_str());
}
double toDouble (string text) {
return atof(text.c_str());
}