Program Calculates Cumulative GPA

I created a C++ program that calculates the average of a class based on the number of home works, the grades of those home works, the number of tests, the grades of those tests, and the final exam grade. I did this for each class. How could I make another C++ program that runs those programs so I can calculate a cumulative GPA for the semester based on the given criteria for each class.

code for one of the classes is:

#include<iostream>
#include<cmath>
#include<string>

using namespace std;
using std::string;

int main()
{
int hwnum, hwsum, testnum, testsum, fexam;
float semavg, hwavg, testavg;
cout <<"How many homeworks have you done?\n";
cin >> hwnum;
int hwarray[hwnum];
hwsum = 0;
cout <<"Enter homework grades\n";
for(int i=0; i<hwnum; i++)
{
cin >> hwarray[i];
}
for(int j=0; j<hwnum; j++)
{
hwsum = hwsum + hwarray[j];
}
hwavg = hwsum/hwnum;
cout <<"Your Homework Average is " << hwavg <<".\n";
cout <<"How many Tests have you taken?\n";
cin >> testnum;
int testarray[testnum];
testsum = 0;
cout <<"Enter your Test Grades\n";
for(int k=0; k<testnum; k++)
{
cin >> testarray[k];
}
for(int l=0; l<testnum; l++)
{
testsum = testsum + testarray[l];
}
testavg = testsum/testnum;
cout <<"Your Test Average is" << testavg << ".\n";
int x;
cout <<"Have you taken the final exam (yes=0/no=1)?\n";
cin >> x;
if(x < 1)
{
cout <<"what is your Final Exam Grade?\n";
cin >> fexam;
semavg = ((.1*hwavg)+(.4*testavg)+(.5*fexam));
} else
{
semavg = ((.2*hwavg)+(.8*testavg));
}
if(semavg >= 90)
{cout <<"You have an A this semester!\n";} else if((semavg >= 80) && semavg < 90)
{cout <<"You have a B this semester!\n";} else if((semavg >= 70) && semavg <80)
{cout <<"You have a C this semester.\n";} else if((semavg >= 60) && semavg <70)
{cout <<"you have a D this semester.\n";} else
{cout <<"You're Failing this semester.\n";}
cout <<"Your Semester Average is " << semavg << ".\n\n";
return 0;
}
Topic archived. No new replies allowed.