The following program allows the user to enter the grades of 10 students in a class in an array called grade. In a separate loop, you need to test if a grade is passing or failing, and copy the grade to an array to store passing or failing grades accordingly. A passing grade is a grade greater than or equal to 60. You can assume the use will enter a grade in the range of 0 to 100, inclusive.
Declare an array named pass of suitable size and type to store passing grades. Declare another array named fail of suitable size and type to store failing grades. In a loop of your choice, check if the grade is greater than or equal to 60. If it is greater or equal to 60, copy this grade to the pass array. Otherwise, copy this grade to the fail array Note that the number of passing and failing grades will most likely be less than the total number of grades. This also means that the index of a specific student’s grade across the arrays may not be the same after copying. So, you will need separate counters to keep track of the elements across the arrays. Display the content of the both pass and fail arrays as well as the number of passing and failing students with a suitable message
#include<iostream>
using namespace std;
int main()
{
const int SIZE=10
int grade[SIZE];
for(int i=0;i<SIZE;++)
{
cout<<"Enter grade of Student #"<<i+1<<":";
cin>>grade[i];
}
cout<<"You entered:"<<endl;
for(int i=0;i<SIZE;++i)
{
cout<<"GRade student "<<grade[i]<<endl;
}
return 0;
}
Give below is the modified code. Please do rate the answer if it helped. Thank you.
#include<iostream>
using namespace std;
int main()
{
const int SIZE=10;
int grade[SIZE];
int pass[SIZE];
int fail[SIZE];
int numPass = 0, numFail = 0;
for(int i=0;i<SIZE;i++)
{
cout<<"Enter grade of Student
#"<<i+1<<":";
cin>>grade[i];
}
for(int i=0;i<SIZE;i++)
{
if(grade[i] >= 60)
{
pass[numPass] =
grade[i];
numPass++;
}
else
{
fail[numFail] =
grade[i];
numFail++;
}
}
cout<<"You entered:"<<endl;
for(int i=0;i<SIZE;++i)
{
cout<<"GRade student
"<<grade[i]<<endl;
}
cout << "Pass Grades:";
for(int i = 0; i < numPass; i++)
cout << " " <<
pass[i];
cout << endl << "No. of pass grades = "
<< numPass << endl;
cout << "Fail Grades:";
for(int i = 0; i < numFail; i++)
cout << " " <<
fail[i];
cout << endl << "No. of fail grades = "
<< numFail << endl;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.