The question is, write a program to find cgpa for a student, the student need to enter their name, matrix num, subjects name and grades for each subject. Then the program will display the cgpa for the semester, the program required student to enter data for minimum two semester and lastly, the program will display the average cgpa for the semesters. The program should used struct for student and array for the subjects. Here is my half code, i stuck when it comes to use an array to get the grades and convert it to grades value. Is any solution for my problems?
/* Assignment 2
To find GPA is computed by dividing the total number of grade points earned by
the total number of credit hours of work completed during the semester.
To find the cgpa is computed by dividing the total number of grade points
earned by the total number of credit hours cmpleted by the student
*/
#include<iostream>
#include<string>
usingnamespace std;
struct student
{
string name;
string id_num;
string sub_name;
int c_hour;
string gred;
}info,subject;
void get_subject();
void calculate();
int main()
{
int sub_num;
int sem;
cout<<"*******Program To Calculate Student PNGS *********"<<endl;
cout<<endl<<"Enter student name:";
cin.ignore();
getline(cin,info.name);
cout<<"Enter Matrix N.o:";
getline(cin,info.id_num);
do
{
cout<<endl<<"Enter semester, otherwise enter 0 to exit:";
cin>>sem;
if(sem>0)
get_subject();
else
cout<<endl<<"Program closed!! Bye2";
}while(sem!=0);
}
void get_subject()
{
int sub_num;
cout<<"How many subjects:";
cin>>sub_num;
for(int x=0;x<sub_num;x++)
{
cout<<endl<<"Name of Subject:";
cin.ignore();
getline(cin,subject.sub_name);
cout<<"Credit Hour:";
cin>>subject.c_hour;
cout<<"Gred:";
cin.ignore();
getline(cin,subject.gred);
}
}
void calculate() //dont know how to implement this
{
int grade;
if(subject.gred=="A"||subject.gred=="a")
grade=4.00;
elseif(subject.gred=="A-"||subject.gred=="a-")
grade=3.75;
elseif(subject.gred=="B+"||subject.gred=="b+")
grade=3.50;
elseif(subject.gred=="B"||subject.gred=="b")
grade=3.00;
elseif(subject.gred=="B-"||subject.gred=="b-")
grade=2.75;
elseif(subject.gred=="C+"||subject.gred=="c+")
grade=2.5;
elseif(subject.gred=="C"||subject.gred=="c")
grade=2.00;
elseif(subject.gred=="C-"||subject.gred=="c")
grade=1.75;
elseif(subject.gred=="D+"||subject.gred=="d+")
grade=1.5;
elseif(subject.gred=="D"||subject.gred=="d")
grade=1.00;
else
grade=0;
}