You are on page 1of 7

#include <iostream>

using namespace std;

void getData(float marks[5][4], int numCol, int


numRow)//function definition
//This function reads and stores data in an array named
marks.
{
for(int row = 0; row<numRow; row++)
{
cout<<endl<<"Enter marks student"<<row+1<<":"<<endl;
for(int col = 0; col<numCol; col++)
{
cout<<"Subject"<<col+1<<":"<<endl;
cin>>marks[row][col];
}
}
}

void detGrade(char grade[5][4], float marks[5][4], int numCol,


int numRow)
//This function will determine the grade based on the given
table and store into an array named grade.
{
for(int row = 0; row<numRow; row++)
{
for(int col = 0; col<numCol; col++)
{

if (marks[row][col] >= 80 &&


marks[row][col] <= 100)
{
grade[row][col]= 'A';
}
else if(marks[row][col] >= 60
&& marks[row][col] < 80)
{
grade[row][col]= 'B';
}
else if (marks[row][col] >= 50
&& marks[row][col] <60)
{
grade[row][col]= 'C';
}
else
{
grade[row][col]= 'D';
}
}
}
}

void dispData( float marks[5][4], char grade[5][4], int


numCol, int numRow)
//This function will display the marks and grade for each
students.
{
double avg = 0;
double sum = 0;
int count = 0;
cout<<"\nReport 1: Based on Marks "<<endl;
cout<<"\n\t\tSubject1\tSubject2\tSubject3\tSubject4
\tAverage Marks ";
for (int row = 0; row < numRow; row++)
{
cout<<"\nStudent"<<row+1<<":";
for(int col=0;col<numCol;col++)
{
cout<<"\t"<<marks[row][col]<<"\t";
sum = sum + marks[row][col];
}
avg = (sum/4); //to calculate the average of
student marks
cout<<"\t"<<avg<<"\t";
}

cout<<"\n\nReport 2 : Based on Grade"<<endl;


cout<<"\n\t\tSubject1\tSubject2\tSubject3\tSubject4
\tCount of A "<<endl;
for(int row=0;row<numRow;row++)
{
count=0;
cout<<"\nStudent"<<row+1;
for(int col=0;col<numCol;col++)
{
cout<<"\t"<<grade[row][col]<<"\t";
//to count the number of "A" of each student
if ( marks[row][col]<=100
&& marks[row][col]>=80)
{
count=count+1;
}
}
cout<<"\t"<<count<<"\t";
}
}
int main()
{
float marks[5][4]; //Array for marks
char grade[5][4]; //Array for grade
int count = 0;
const int numRow=5,numCol=4; //constant
//function call
getData(marks, numCol, numRow);
detGrade(grade, marks, numCol, numRow);
dispData(marks, grade, numCol, numRow);
return 0;
}