Write a program that would ask the user to input marks of N

Write a program that would ask the user to input marks of N (define as a preprocessor integer constant) number of quizzes in an array of size N. After getting the input from the user and storing them in an array, you are required to write the following functions:

1. Print the grade of each quiz entered by the user using the following function prototype: void print_quizzes(float A[], int size); For each score, the function should call another function using the specified function prototype: void print_grade(float score); which displays a corresponding letter grade based on the following rules:

If the score is between 85.00 and 100.00 inclusive, display an \'A\'.

If the score is between 75.00 and 84.99 inclusive, display a \'B\'.

If the score is between 65.00 and 74.99 inclusive, display a \'C\'.

If the score is between 50.00 and 64.99 inclusive, display a \'D\'.

If the score is less than 50, display an \'F\'.

2. Calculate average marks and return the average to main program and print it there. Call the print_grade function from there passing the average as a parameter and print the grade associated with the average. Use the specified function prototype to calculate average: float cal_average(float A[],int size);

3. Find the highest marks obtained out of all the quizzes entered by the user using a function with specified function prototype: float cal_max(float A[], int size);

4. Find the lowest marks obtained out of all the quizzes entered by the user using a function with specified function prototype: float cal_min(float A[], int size);

Important notes regarding implementation:

You are not allowed to use any global variables. You only have to use one preprocessor constant N.

You have to input the score for each quiz in the main function.

The input of each quiz must be an integer or float but the scores are float.

For each of the above mentioned problems you are required to follow the instructions as specified.

Solution

#include<iostream>
using namespace std;
//Preprocessor for Symbolic constant array size
#define N 5
//Prototype of functions
void print_quizzes(float A[], int size);
void print_grade(float score);
float cal_average(float A[],int size);
float cal_max(float A[], int size);
float cal_min(float A[], int size);
int main()
{
//Declares the size of array
float QuizMark[N];
int c;
//Enters the Quiz mark
cout<<\"\ Enter \"<<N<<\" Quiz Mark \";
for(c = 0; c < N; c++)
{
cout<<\"\ Enter Quiz \"<<c+1<<\" Mark: \";
cin>>QuizMark[c];
}
//Prints the quiz mark
print_quizzes(QuizMark, N);
//Prints the average mark
cout<<\"\ Average Mark = \"<<cal_average(QuizMark,N);
//Prints the grade
print_grade(cal_average(QuizMark,N));
//Prints the Maximum Quiz Mark
cout<<\"\ Maximum Quiz Mark = \"<<cal_max(QuizMark, N);
//Prints the Minimum Quiz Mark
cout<<\"\ Minimum Quiz Mark = \"<<cal_min(QuizMark, N);
}
//Returns the Minimum quiz mark
float cal_min(float A[], int size)
{
int c;
//Assumes the first quiz mark as the minimum
float minimum = A[0];
//Loops till the size of array
for(c = 1; c < size; c++)
{
//Checks if the minimum is less than the next quiz mark then update the minimum quiz mark
if(minimum < A[c])
minimum = A[c];
}
//Returns the minimum quiz mark
return minimum;
}
//Returns the Maximum quiz mark
float cal_max(float A[], int size)
{
int c;
//Assumes the first quiz mark as the Maximum
float maximum = A[0];
//Loops till the size of array
for(c = 1; c < size; c++)
{
//Checks if the Maximum is greater than the next quiz mark then update the Maximum quiz mark
if(maximum > A[c])
maximum = A[c];
}
//Returns the Maximum quiz mark
return maximum;
}
//Calculates and Returns the Average quiz mark
float cal_average(float A[],int size)
{
int c, tot = 0;
float avg;
for(c = 0; c < size; c++)
tot += A[c];
avg = tot / size;
return avg;
}
//Prints the Quiz Mark with Grade
void print_quizzes(float A[], int size)
{
int c;
for(c = 0; c < size; c++)
{
cout<<\"Quiz \"<<c+1<<\" Mark = \"<<A[c];
print_grade(A[c]);
}
}
//Prints the Grade
void print_grade(float score)
{
//Check the Quiz mark and display the Grade
if(score >= 85)
cout<<\" Grade = A\"<<endl;
else if(score >= 75)
cout<<\" Grade = B\"<<endl;
else if(score >= 65)
cout<<\" Grade = C\"<<endl;
else if(score >= 50)
cout<<\" Grade = D\"<<endl;
else
cout<<\" Grade = F\"<<endl;
}

Output:

Enter 5 Quiz Mark
Enter Quiz 1 Mark: 45.12

Enter Quiz 2 Mark: 68.89

Enter Quiz 3 Mark: 89.53

Enter Quiz 4 Mark: 53.7

Enter Quiz 5 Mark: 12.22
Quiz 1 Mark = 45.12 Grade = F
Quiz 2 Mark = 68.89 Grade = C
Quiz 3 Mark = 89.53 Grade = A
Quiz 4 Mark = 53.7 Grade = D
Quiz 5 Mark = 12.22 Grade = F

Average Mark = 53 Grade = D

Maximum Quiz Mark = 12.22
Minimum Quiz Mark = 89.53

Write a program that would ask the user to input marks of N (define as a preprocessor integer constant) number of quizzes in an array of size N. After getting t
Write a program that would ask the user to input marks of N (define as a preprocessor integer constant) number of quizzes in an array of size N. After getting t
Write a program that would ask the user to input marks of N (define as a preprocessor integer constant) number of quizzes in an array of size N. After getting t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site