Answer to Question #233110 in C++ for mani

Question #233110

Write a program that calculates GPA

Arrays in main function

1.  A two dimensional array Grades[Number_of_students][Number_of_subjects] that stores the grades (0 ~ 100) of 6 students for 4 subjects.

2.  A one dimensional array Credit_hours[Number_subjects]

3.  A two dimensional array Grade_points.

 Grade_points [Number_of_students][Number_of_subjects] that will stores the grade points of each subject for 6 students.

4.  A one dimensional array GPA[Number_of_students] that stores the GPA of each student

Write the following Functions

a.  A function Enter_Grades() that takes the two dimensional Grades array.

b.  A function Enter_credit_hours that takes the array Credit_hours.

c.  A function Display_grades

d.  A function Calculate_ Grade_points that takes two arrays Grades and Grade_points.

e.  A function Calculate_GPA that takes three arrays Credit_hours, GPA and

GPA=(GP1*CH1 + GP2*CH2 + GP3*CH3 + GP4*CH4)/(CH1 + CH2 + CH3 + CH4)


1
Expert's answer
2021-09-04T10:55:41-0400
#include <iostream>
#include <iomanip>
using namespace std;


#define Number_of_students 6
#define Number_of_subjects 4


//Write the following Functions
//a.  A function Enter_Grades() that takes the two dimensional Grades array.
void Enter_Grades(int Grades[Number_of_students][Number_of_subjects]){
	for(int i=0;i<Number_of_students;i++){
		cout<<"Enter grades for student "<<(i+1)<<"\n";
		for(int j=0;j<Number_of_subjects;j++){
			cout<<"Enter grade for subject "<<(j+1)<<": ";	
			cin>>Grades[i][j];
		}
	}
}
//b.  A function Enter_credit_hours that takes the array Credit_hours.
void Enter_credit_hours(int Credit_hours[Number_of_subjects]){
	for(int j=0;j<Number_of_subjects;j++){
		cout<<"Enter credit hours for subject "<<(j+1)<<": ";	
		cin>>Credit_hours[j];
	}
}
//c.  A function Display_grades
void Display_grades(int Grades[Number_of_students][Number_of_subjects]){
	cout<<fixed<<"Student"<<setw(15)<<"Subject 1"<<setw(15)<<"Subject 2"<<setw(15)<<"Subject 3"<<setw(15)<<"Subject 4\n";
	for(int i=0;i<Number_of_students;i++){
		cout<<left<<setw(15)<<(i+1);
		for(int j=0;j<Number_of_subjects;j++){
			cout<<setw(15)<<Grades[i][j];	
		}
		cout<<"\n";
	}
}
//d.  A function Calculate_Grade_points that takes two arrays Grades and Grade_points.
void Calculate_Grade_points(int Grades[Number_of_students][Number_of_subjects],int Grade_points[Number_of_students][Number_of_subjects]){
	for(int i=0;i<Number_of_students;i++){
		for(int j=0;j<Number_of_subjects;j++){
			if(Grades[i][j]>=90 && Grades[i][j]<=100){
				Grade_points[i][j]=4;	
			}
			if(Grades[i][j]>=80 && Grades[i][j]<90){
				Grade_points[i][j]=3;
			}
			if(Grades[i][j]>=70 && Grades[i][j]<80){
				Grade_points[i][j]=2;
			}
			if(Grades[i][j]>=60 && Grades[i][j]<70){
				Grade_points[i][j]=1;
			}
			if(Grades[i][j]>=0 && Grades[i][j]<60){
				Grade_points[i][j]=0;
			}
		}
	}
}


//e.  A function Calculate_GPA that takes three arrays Credit_hours, GPA and
//GPA=(GP1*CH1 + GP2*CH2 + GP3*CH3 + GP4*CH4)/(CH1 + CH2 + CH3 + CH4)
void Calculate_GPA(int Credit_hours[Number_of_subjects],int Grade_points[Number_of_students][Number_of_subjects],float GPA[Number_of_students]){
	//float GPA=(GP1*CH1 + GP2*CH2 + GP3*CH3 + GP4*CH4)/(CH1 + CH2 + CH3 + CH4)
	for(int i=0;i<Number_of_students;i++){
		float sum_grade_points=0;
		float credit_hours_sum=0;
		for(int j=0;j<Number_of_subjects;j++){
			sum_grade_points+=Credit_hours[j]*Grade_points[i][j];
			credit_hours_sum+=Credit_hours[j];
		}
		GPA[i]=sum_grade_points/credit_hours_sum;
	}
}




int main(){
	//Arrays in main function
	//1.  A two dimensional array Grades[Number_of_students][Number_of_subjects] that stores the grades (0 ~ 100) of 6 students for 4 subjects.
	int Grades[Number_of_students][Number_of_subjects];
	//2.  A one dimensional array Credit_hours[Number_subjects]
	int Credit_hours[Number_of_subjects];
	//3.  A two dimensional array Grade_points.
	//Grade_points [Number_of_students][Number_of_subjects] that will stores 
	//the grade points of each subject for 6 students.
	int Grade_points[Number_of_students][Number_of_subjects];
	//4.  A one dimensional array GPA[Number_of_students] that stores the GPA of each student
	float GPA[Number_of_students];


	


	Enter_Grades(Grades);
	Enter_credit_hours(Credit_hours);
	cout<<"\nAll grades:\n";
	Display_grades(Grades);
	Calculate_Grade_points(Grades,Grade_points);
	cout<<fixed<<right;
	cout<<"\nAll grades points:\n";
	Display_grades(Grade_points);
	Calculate_GPA(Credit_hours,Grade_points,GPA);


	for(int i=0;i<Number_of_students;i++){
		cout<<"Student "<<(i+1)<<" has GPA: "<<setprecision(2)<<GPA[i]<<"\n";
	}


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS