In: Computer Science
A local instructor wants you to write a c++ program using arrays to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60 or above is considered passing. Also determine the number of scores that were an A (90 or better), B (80 – 89), C (70 – 79), D (60 – 69), or F (below 60).
• Use main( ) as the driver function. Allow the user to process as many exams as desired.
1. Write a function to prompt the user for the following
information:
(a) The name of the exam.
(b) The 12 integer scores ranging from 0 to 100. (Store these
scores in a one-dimensional array.
Perform input/data validation.)
2. Write a function to determine the highest and lowest score.
(Hint: Code is in your etext section:
Finding the Highest and Lowest Values in a Numeric Array)
3. book or see assignment #1.)
4. Write a function to calculate the average score for the exam.
(Hint: Code is in your etext section:
Finding the Highest and Lowest Values in a Numeric Array)
5. Write a function to determine the number of students who passed
and failed the exam.
6. Write a function to determine the number of scores represented
by each letter grade in a standard 10-
point grading scale.
7. Write a function to display the exam’s name, all 12 scores
recorded on the exam, the average score, the highest and lowest
score, the number of students who passed and failed the exam, and
number of scores that were represented by each letter grade in the
standard 10-point grading scale. Display the average to a hundredth
of a decimal.
Program code:
#include<iostream>
using namespace std;
int Score[12]; //Array to store
scores of 12 students.
char grade[12]; //Array to store
grades of 12 students.
int minScore,maxScore; //Variables to store Minimum and
maximum scores
float sum,average;
//Variables to store sum and average of 12
scores.
string Subject;
//Variable to store Subject name.
void Prompt(int Score[12]) //Function to
input scores of 12 students.
{
int val;
cout << "Enter Subject Name:";
cin >> Subject;
cout << "Enter marks:" <<
endl;
for(int i=0;i<12;i++)
{
cout << "Student -
" << i+1 << " Score :";
cin >> val;
if(val>=0 &&
val<=100)
Score[i]=val;
else
{
cout
<< "Score should be between 0-100." <<endl;
i=i-1;
}
}
}
void MinMax(int Score[12]) //Function to
find minimum and maximum score
{
minScore=Score[0],maxScore=Score[0];
for(int i=1;i<12;i++)
{
if(minScore>Score[i])
minScore=Score[i];
if(maxScore<Score[i])
maxScore=Score[i];
}
cout << "Maximum score is :"<<
maxScore << endl << endl;
cout << "Minimum score is :"<<
minScore << endl << endl;
}
void Average(int Score[12]) //Function to
find average of 12 scores
{
sum=0;
for(int i=0;i<12;i++)
{
sum=sum+Score[i];
}
average=sum/12;
cout << "Average score is: " <<
average << endl << endl;
}
void Passed(int Score[12]) //Function to
find the number of students passed and failed.
{
int pass=0;//fail;
for(int i=0;i<12;i++)
{
if(Score[i]>60)
pass++;
}
//fail=12-pass;
cout << "Number of students
passed:"<< pass <<endl<<endl;
cout << "Number of students
failed:"<< (12-pass) <<endl<<endl;
}
void Grade(int Score[12]) //Function to find
grades of students
{
for(int i=0;i<12;i++)
{
if(Score[i]>=90)
grade[i]='A';
else if(Score[i]>=80
&& Score[i]<90)
grade[i]='B';
else if(Score[i]>=70
&& Score[i]<80)
grade[i]='C';
else if(Score[i]>=60
&& Score[i]<70)
grade[i]='D';
else
grade[i]='F';
}
cout << "Grades of students is
:"<<endl;
for(int i=0;i<12;i++)
cout << grade[i]
<< " ";
}
void display() //Function to print all
those values
{
cout << endl << "Exam Name:"
<< Subject << endl << endl;
cout << "Scores of students are:" <<
endl;
for(int i=0;i<12;i++)
cout << Score[i]
<< " ";
cout << endl << endl;
Average(Score);
MinMax(Score);
Passed(Score);
Grade(Score);
}
int main()
{
Prompt(Score);
display();
}
Output: