Friday, 19 July 2013

Find Grade of Student using Switch Case

#include<iostream.h>
#include<conio.h>
class grade
{
    int r,P,t,i,total,m[5];
    char a[15];
    float per;
    public:
        void Mahi();
};
void grade::Mahi()
{
    total=0;
    cout<<"\n Enter the name of the student: ";
    cin>>a;
    cout<<"\n Enter the roll number of the student: ";
    cin>>r;
    cout<<"\n Enter marks obtained in five subjects: \n\n";
    for(i=0;i<5;i++)
    {
        cout<<" Enter marks in "<<i+1<<" subject: ";
        cin>>t;
        if(t<=100)
            m[i]=t;
        else
        {
            cout<<"Marks should not exceed 100\n";
            i=i-1;
        }
    }
    for(i=0;i<5;i++)
    total=total+m[i];
    per=(total/500.0)*100;
    cout<<"\nNAME\tROLLNO\tTOTAL\tPERCENTAGE\tGRADE\n\n" ;
    cout<<a<<"\t"<<r<<"\t"<<total<<"\t"<<per<<"\t";
    P=per/10;

    switch(P)
    {
        case 10:
        case 9:
        case 8:
        case 7:
            cout<<"Grade A";
            break;
        case 6:
            cout<<"Grade B";
            break;
        case 5:
            cout<<"Grade C";
            break;
        case 4:
            cout<<"Grade D";
            break;
        default:
            cout<<"Grade Fail";
    }
}
void main()
{
    clrscr();
    grade d1;
    d1.Mahi();
    getch();
}

Here is the output :)

 

1 comment:

  1. simple sa program ap ny buht lengthy kar dya h......

    ReplyDelete