19.Write a program to find average marks of the subjects of a student. Throw multiple exceptions and define multiple catch statements to handle division by zero as well as array index out of bounds exceptions.

/* AVERAGE OF SUBJECTS USING MULTIPLE CATCH STATEMENTS*/

 


# include<iostream>
using namespace std;

int main() 
{
    int n,marks[10];
    float avg=0,tot=0;
    cout<<"\n enter the no of subjects";
    cin>>n;
    cout<<"\n enter the marks of a student\n"<<n<<"students\n";
    try
        {
            if(n>0&&n<=10)
            {
                for(int i=1;i<=n;i++)
                {
                    cout<<"enter marks of student"<<i<<":\t";
                    cin>>marks[i];
                    tot+=marks[i];
                }
            avg=tot/n;
            cout<<"\ntotal marks :\t"<<tot<<"\n average of marks:\t"<<avg;
        }
    else if(n==0)
        throw (0);
    else if  (n>10)
        throw(10);
    }
    catch(int i)
    {
        cout<<"\n divide bu zero error...";
    }
    catch(double i)
    { 
        cout<<"\n array index out of bound";
    }
}
Posted by Unknown On 04:56 No comments

0 comments:

Post a Comment

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *