Write a program to calculate the grade point average (CGPA) of the student. Students are required to enter the course and the grade of the subjects taken and the next program will calculate CGPA received by students. Make sure students include data for at least two semesters for the purpose of this calculation of CGPA. For each semester, show the calculation of the overall grade obtained.
Your program should use a structure concepts to students and using the concept of arrays for the subjects taken.
if (gred=='A')
cout<<"4.00";
else if (gred=='A-')
cout<<"3.75";
else if (gred=='B+')
cout<<"3.50";
else if (gred=='B')
cout<<"3.00";
else if (gred=='B-')
cout<<"2.75";
else if (gred=='C+')
cout<<"2.50";
else if (gred=='C')
cout<<"2.00";
else if (gred=='C-')
cout<<"1.75";
else if (gred=='D+')
cout<<"1.50";
else if (gred=='D')
cout<<"1.00";
else (gred=='F')
cout<<"0.00";
{
char mark[2];
char A = 4, A- = 3.75, B+ = 3.50, B = 3.00, B- = 2.75, C+ = 2.50, C = 2.00, C- = 1.75, D+ = 1.50, D = 1.00, F = 1.0;
float pngk;
cout<<"This Program Will Calculate Your CGPA for MTS3013 structure"
<<" programming MTK3013 structure disckrit MTN3013 computer organization"
<<" and architecture"<<endl;
cout<<"You should enter your grade only."<<endl<<endl;
First please use code tags when posting your code in the forums (Hint the <> under format off to the right when replying). Also I would move this to the beginners forum since this does not have to do with windows programming.
So I'm not sure where your stuck at ITstudent... Could you post the code you have so far and where you need help?
if (gred=='A')
cout<<"4.00";
else if (gred=='A-')
cout<<"3.75";
else if (gred=='B+')
cout<<"3.50";
else if (gred=='B')
cout<<"3.00";
else if (gred=='B-')
cout<<"2.75";
else if (gred=='C+')
cout<<"2.50";
else if (gred=='C')
cout<<"2.00";
else if (gred=='C-')
cout<<"1.75";
else if (gred=='D+')
cout<<"1.50";
else if (gred=='D')
cout<<"1.00";
else (gred=='F')
cout<<"0.00";
}
void display()
{
Well again please use code tags when you post code to the forums (Hint the <> under Format: off to the right when replying)
Just scanned through it since you didn't say what you were having problems with and somethings I noticed was these.
1) #include <iostream.h> You aren't suppose to have .h at the end of this header it should be this instead #include <iostream> the same goes for the string header.
2) Line 28 Your for loop for (i=1; i<4; i++) has no braces! When you have multiple statements in a loop you need to enclose them in braces {}.
3) line 39 getline (cin, subject[i].course); Not sure why you have .course after subject[i] but this is not the correct way to do things. Are you trying to read in course and subject?
4) Line 65 should be elseif(gred=='F') not just else.
5) Your function void display() has acouple things wrong with it.
A) You never call the function or use it so there is no point to having it. Unless your going to use it later.
B) Why are you declaring variables in your function and storing inputs in them, but not returning anything? Basically anything that you store in a variable you declared in your function will be deleted right away after the function calls since you don't return anything. Not the best description Im sorry but its 7am and have been up all night ;p. Check below for more info on functions and how they work.
C) Again in the function you have this getline (cin, subject[i]. course) << gred << endl; which I don't understand what your trying to do here... In subject[i] i has no value so subject[i] would be invalid. And im still not sure what your trying to do with the .course.
Then are some things I noticed with the code. And I would recommend you check out these tutorials to help with learning some material you might need more info on.
1) Functions I think you don't understand how they work exactly here is a link to the website tutorial on them http://www.cplusplus.com/doc/tutorial/functions/
2) Control structures, you might have jsut missed the braces by accident but I feel you might need some help with control structure's here is the link http://www.cplusplus.com/doc/tutorial/control/
3) Input and Output along with how getline() works. Just a refresher here are the linkss. Input & Output http://www.cplusplus.com/doc/tutorial/basic_io/, and for getline http://www.cplusplus.com/reference/string/getline/
Them are just some things to checkup on and if you need any help with any of them or have questions just post here and we will try and help to our best of our abilities
ITstudent, you separate the code into a 2 .cpp files, one called main.cpp and function.cpp. separate code into functions, place it in function.cpp then use the functions in main.cpp (They must share a header file).
#include<iostream.h> // for inpit and output
#include<string.h> // for string nama...
usingnamespace std; // for name space..
struct student // declare struct
{
string name,no_matric;
string sub_code[10],sub_name[10],sub_grade[10];
float credit_hour[10];
}student1;
main()
{
int credit_hours[10];
int sem,total_subject; //'b', 'a',total_credit_hours and total_point
//are removed
float value[10],gpa[10],get_point[10];
float cgpa;
float total_point_sem = 0; //Initialise value
int total_credit_hours_sem = 0; //Initialise value
cin.ignore();
cout << "\t\ ================ ";
cout << "\n\t\ STUDENT'S REKOD " << endl;
cout << "\t\ ================ " << endl;
cout << "\n ENTER STUDENT'S NAME : "; //Enter student's name
getline(cin,student1.name);
cout << " ENTER STUDENT'S MATRIC NUMBER : "; //Enter student's matric number
getline(cin,student1.no_matric);
cout << " ENTER TOTAL SEM TAKEN :"; //Total semester taken by the student
cin >> sem;
for(int a = 0; a< sem ; a++) //'a' declared as int in for()[newly added]
{
int b; //newly added line,'b' choose to add it here because, if not, error will be occured : 'b' for gpa[b] will become undefined...
int total_credit_hours = 0; //newly added
float total_point = 0; //newly added
cout << "\n ENTER SUBJECT TAKEN FOR SEM : " << a+1 << ":"; //Enter total number of subject taken for each sem
cin >> total_subject;
for(int b = 0; b< total_subject; b++) //loop for the courses
{
cin.ignore();
cout << " ENTER SUBJECT CODE : "; //Enter subject code
getline(cin,student1.sub_code[b]);
cout << " ENTER SUBJECT NAME : "; //Enter subject name
getline(cin,student1.sub_name[b]);
cout << " ENTER SUBJECT'S CREDIT HOUR : "; //Enter credit hours of the subject
cin >> student1.credit_hour[b];
cin.ignore();
cout << " ENTER SUBJECT GRED : "; //Enter grade gained by student for every subject
getline(cin,student1.sub_grade[b]);
if(student1.sub_grade[b]=="A")
value[b]=4;
elseif(student1.sub_grade[b]=="A-")
value[b]=3.75;
elseif(student1.sub_grade[b]=="B+")
value[b]=3.5;
elseif(student1.sub_grade[b]=="B")
value[b]=3;
elseif(student1.sub_grade[b]=="B-")
value[b]=2.75;
elseif(student1.sub_grade[b]=="C+")
value[b]=2.5;
elseif(student1.sub_grade[b]=="C")
value[b]=2;
elseif(student1.sub_grade[b]=="C-")
value[b]=1.75;
elseif(student1.sub_grade[b]== "D+")
value[b]=1.5;
elseif(student1.sub_grade[b]=="D")
value[b]=1;
else
value[b]=0;
get_point[b] = student1.credit_hour[b] * value[b]; //multiply of credit hours and grade get for each subject
total_credit_hours +=student1.credit_hour[b]; //total cerdit hours for a sem
total_point += get_point[b]; //total points(multiple of credits hours and grade)get for a sem
}
gpa[b] = total_point / total_credit_hours; //calculate GPA for each sem
total_point_sem += total_point; //Total points(multiple of grade and credit hours) get for all semester
total_credit_hours_sem += total_credit_hours; //credits hour get for all semester
}
cgpa = total_point_sem / total_credit_hours_sem; //calculate CGPA
cout << "\n =================================================== ";
cout <<"\n NAME : " << student1.name << endl; //display name of student
cout <<" NO MATRIC : "<< student1.no_matric << endl;
for(int a = 0; a< sem ; a++) //Declaration of 'a' as int in for()
{
cout <<" SUBJECT CODE \t" << " SUBJECT NAME \t" << " SUBJECT CREDIT HOURS " <<endl;
for(int b=0; b<total_subject; b++) //Declaration of 'b' as int in for()
{
cout << " " << student1.sub_code[b] << " : " << student1.sub_name[b]<< " : " << student1.credit_hour[b] << endl;
}
cout << " GPA" <<a+1<< " : " <<gpa[a] << endl;
}
cout << " CGPA : "<<cgpa<<endl;
cout << "\n =================================================== ";
}