#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class agent{
public:
static int count;
string name;
int incentive;
void input()
{
count++;
cout<<"Enter name of agent : ";
cin>>name;
cout<<"Enter Incentive : ";
cin>>incentive;
if(incentive == 0 )
{
throw "**********An Exception occurred***********";
}
}
};
bool compare(agent ob1, agent ob2)
{
return ob1.incentive < ob2.incentive;
}
int agent::count =0;
int main()
{
int n;
cout<<"Enter number of LIC Agents : ";
cin>>n;
cout<<endl;
agent a[n];
for(int i=0; i<n; i++)
{
try
{
cout<<"Enter details of agent"<<i+1<<endl;
a[i].input();
cout<<endl;
}
catch(const char* msg) {
cerr << msg << endl<<endl;
}
}
sort(a, a+n, compare);
cout<<endl<<"Agent with Minimum Incentive"<<endl;
cout<<"---------------------------------"<<endl;
cout<<a[0].name<<" : "<<a[0].incentive<<endl;
cout<<endl<<"Agent with Maximum Incentive"<<endl;
cout<<"---------------------------------"<<endl;
cout<<a[n-1].name<<" : "<<a[n-1].incentive;
}
Enter the name of agent1
Enter name of agent : Divya
Enter Incentive : 0
********** A n Exception occurred**********
Comments
Leave a comment