Thursday 25 February 2016

By using function overloading write a complete C++ program that can compute the GPA of a student’s registering with different number of courses.


#include <iostream>

using namespace std;

void cal(char a,char b, char c,char d)
{
    char ab[]={a,b,c,d};
    int gp=0;
for(int i=0;i<4;i++)
{

    if(ab[i]=='A')
    {
        gp=gp+4;
    }
        if(ab[i]=='B')
    {
        gp=gp+3;
    }
        if(ab[i]=='C')
    {
        gp=gp+2;
    }
        if(ab[i]=='D')
    {
        gp=gp+1;
    }
            if(ab[i]=='F')
    {
        gp=gp+0;
    }
}
    cout<<"GPA IS "<<gp;

}
void cal(char a,char b, char c,char d, char e)
{
    char ab[]={a,b,c,d,e};
    int gp=0;
for(int i=0;i<5;i++)
{

    if(ab[i]=='A')
    {
        gp=gp+4;
    }
        if(ab[i]=='B')
    {
        gp=gp+3;
    }
        if(ab[i]=='C')
    {
        gp=gp+2;
    }
        if(ab[i]=='D')
    {
        gp=gp+1;
    }
            if(ab[i]=='F')
    {
        gp=gp+0;
    }
}
    cout<<"GPA IS "<<gp;

}
}

int main() {

    int choice,temp=0;
    char a[5];

    for (int i=0;i<5;i++)
        {
    cout<<"enter course no "<< i+1 << "grade from A to D";
    cin>>a[i];
    temp++;
    if(i>2)
    {
    cout<<"enter 1 if you do not want to enter marks anymore";
    cin>>choice;
    }

    if(choice==1)
    {
        i=10;
    }
    }

    switch(temp)
    {
    case 4:
    {
        cal(a[0],a[1],a[2],a[3]);
        break;
    }
    case 5:
    {
        cal(a[0],a[1],a[2],a[3],a[4]);
        break;
    }

    }


    return 0;
}


No comments:

Post a Comment