Search Your Query

Custom Search

Tuesday, 24 May 2011

GPA Calculator Pragramme


#include <iostream.h>

void main()
{
    int s,g;
    cout << "\t\t-:GPA Calculator:-" << endl << endl;

    cout << "Enter your grades in capital letter like B, B+, B-." << endl << endl;
    cout << "You can calculate CGPA of at the most 20 subjects." << endl;
    cout << "CGPA of how many subjects do you want to calculate: ";    cin >> s;
    cout << endl;
       
    int crdt[20];
    char grad[2];
    double gpa[10];

    for ( int i=0 ; i < s ; i++ )
    {
        cout << "Enter Credit Hours of subject # " << (i+1) << ": ";
        cin >> crdt[i];
                   
        cout << "Enter your grade: ";
        cin >> grad;
        cout << endl;
       
        if ( ( grad[0]=='A' || grad[0]=='a') && grad[1]==0 )
        {
            gpa[i] = crdt[i] * 4.0;
        }
        else if ( ( grad[0]=='A' || grad[0]=='a') && grad[1]=='-' )
        {
            gpa[i] = crdt[i] * 3.7;
        }
        else if ( ( grad[0]=='B' || grad[0]=='b') && grad[1]=='+' )
        {
            gpa[i] = crdt[i] * 3.3;
        }
        else if ( ( grad[0]=='B' || grad[0]=='b') && grad[1]==0 )
        {
            gpa[i] = crdt[i] * 3.0;
        }
        else if ( ( grad[0]=='B' || grad[0]=='b') && grad[1]=='-' )
        {
            gpa[i] = crdt[i] * 2.7;
        }
        else if ( ( grad[0]=='C' || grad[0]=='c') && grad[1]=='+' )
        {
            gpa[i] = crdt[i] * 2.3;
        }
        else if ( ( grad[0]=='C' || grad[0]=='c')  && grad[1]==0 )
        {
            gpa[i] = crdt[i] * 2.0;
        }
        else if ( ( grad[0]=='C' || grad[0]=='c')  && grad[1]=='-' )
        {
            gpa[i] = crdt[i] * 1.7;
        }
        else if ( ( grad[0]=='D' || grad[0]=='d')  && grad[1]==0 )
        {
            gpa[i] = crdt[i] * 1.0;
        }
        else if ( ( grad[0]=='F' || grad[0]=='f')  && grad[1]==0 )
        {
            gpa[i] = crdt[i] * 0;
        }
        else
        {
            cout << "\aError! Invalid Grade.\nEnter your grade in capital letters like B, B+, B-. etc." << endl;
            g=0;
            break;
        }
    }
   
    double tcrdt=0, cgpa=0;
    if ( g!= 0 )
    {
        for ( i=0 ; i < s ; i++ )
        {
            tcrdt = tcrdt + crdt[i];
            cgpa = cgpa + gpa[i];
        }
    }

    cout << "Your CGPA = " << cgpa/tcrdt;
    cout << endl << endl;
   
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...