Search This Blog

Sunday, 1 May 2016

Write a C++ Program that raised object exception. Create student class with enrollment no, CPI, namedata members. Throw exception of typestudent objectfor CPI less than 4. Catch exception and print details of corresponding Student.

Practical - 41


#include<iostream>

using namespace std;

class student{

    int eno,cpi;
    char name[10];

public:
    void getdata()
    {
        cout<<"\nEnter enrollment no:";
        cin>>eno;

        cout<<"\nEnter name:";
        cin>>name;

        c:
        try{
        cout<<"\nEnter Cpi:";
        cin>>cpi;
        if(cpi<4)
        {
            throw cpi;

        }
        }catch(int i)
        {
            cout<<"\nCpi "<<i<<" not valid";
            goto c;
        }
    }
    void display()
    {
        cout<<"\n"<<eno<<"\t"<<name<<"\t"<<cpi<<endl;
    }
};

int main()
{
    student s[10];
    int n;
    cout<<"\nEnter no of student:";
    cin>>n;
    for(int i=0;i<n;i++)
    {
        s[i].getdata();
    }
    cout<<"\nEno\tName\tCpi";
    for(int i=0;i<n;i++)
    {
        s[i].display();
    }
return 0;
}

No comments:

Post a Comment