Problem Create a program that determines grades at the end of the semester. Spec
ID: 3725718 • Letter: P
Question
Problem
Create a program that determines grades at the end of the semester.
Specifications
Using the array class, construct a 5 x 7 two-dimensional array based on the following table
Calculate the average for each student and store it in the Ave column.
Calculate the weighted average for each student (the first grade gets a weight of .2, the second a weight of .3, the third a weight of .3, and the fourth a weight of .2) and store it in the Wt Ave column.
HINT: Use a loop: for each row, calculate the ave and weighted average and store the values in the appropriate column.
Output the contents of the entire array neatly formatted in columns and rows with appropriate row and column labels.
Student Grade 1 Grade 2 Grade 3 Grade 4 Ave Wt Ave 1 85 88 90 81 2 73 68 75 77 3 94 89 82 91 4 88 79 81 84 5 71 65 78 73Explanation / Answer
PROGRAM IN C++
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float arr[5][7]; // Declare float two dimensional array
// Declare variables
int sum;
float avg;
float grade;
cout<<" Read Student Marks ";
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cin>>arr[i][j]; // Read Marks of the each students
for(int i=0;i<5;i++) {
sum=0; // initialize sum=0
for(int j=0;j<5;j++) {
sum+=arr[i][j]; // calculate sum of an array of marks
avg=(float)sum/5.0; //calculate average marks
arr[i][5]=(float)avg; // store average marks into 6th column
// check all conditions finding grade
if(avg>=90&&avg<=100)
grade=.2;
else
if(avg>=70&&avg<90)
grade=.3;
else
if(avg>=60&&avg<50)
grade=.3;
else
grade=.2;
cout<<setprecision(2);
arr[i][6]=(float)grade; // store grade marks into 7th column
}
}
// Display 5x7 table following including grades and average and weighted average marks
cout<<endl<<endl;
cout<<"============================================================ ";
cout<<"Student"<<" "<<"Grade1"<<" "<<"Grade2"<<" "<<"Grade3"<<" "<<"Grade4"<<" "<<"Ave"<<" "<<"Wt Ave"<<endl;
cout<<"============================================================ ";
for(int i=0;i<5;i++){
for(int j=0;j<7;j++){
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<"============================================================ ";
return 0;
}
OUTPUT
Read Student Marks
1 85 88 91 81
2 73 68 75 77
3 94 89 82 91
4 88 79 81 84
5 71 65 78 73
============================================================
Student Grade1 Grade2 Grade3 Grade4 Ave Wt Ave
============================================================
1 85 88 91 81 69 0.2
2 73 68 75 77 59 0.2
3 94 89 82 91 72 0.3
4 88 79 81 84 67 0.2
5 71 65 78 73 58 0.2
============================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.