Answer to Question #193912 in C++ for ram@2002

Question #193912
The Insurance Company has to find the minimum and maximum incentive given for their LIC Agents. Develop a C++ program to implement this using templates with exception handling.

* If the input value is 0 thrown an exception, print "An exception occurred!"
1
Expert's answer
2021-05-17T06:31:55-0400
#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**********




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS