Skip to main content

OOP

14.Problem statement

Crete User defined exception to check the following conditions and throw the exception if the criterion does not meet. a. User has age between 18 and 55 b. User stays has income between Rs. 50,000 – Rs. 1,00,000 per month c.  User stays in Pune/ Mumbai/ Bangalore / Chennai d. User has 4-wheeler  Accept age, Income, City, Vehicle from the user and check for the conditions mentioned above. If any of the condition not met then throw the exception.

Program

#include<iostream>
#include<string.h>
using namespace std;

class user
{ public:
char vehicle;
int salary,age;
string city;
user()
{
age=0;
vehicle=0;
salary=0;
}

void getdata();
};

void user::getdata()
{
cout<<"Enter Age Of Person:- ";
cin>>age;
if(age<18 || age>55)
{
throw 1;
}
cout<<"Enter Salary For Permonth:- ";
cin>>salary;
if(salary<50000 || salary>100000)
{
throw 2;
}



cout<<"Do u have four wheeler(y/n):-  ";
cin>>vehicle;
if(vehicle=='n')
{
throw 3;
}
cout<<"Enter the City name User stay:-  :- ";
cin>>city;
if(city=="pune" || city=="mumbai" || city=="bangalore" || city=="chennai")
{}
else
{
throw 4;
}
}

int main()
{
user u;
try
{
u.getdata();
}

catch(int i)
{
switch(i)
{
case 1:
cout<<"\nInvalid....Please enter age between(18-55)";
break;

case 2:
cout<<"\n Invalid...Please enter salary between(50000-100000)";
break;

case 3:
cout<<"\nUser Donot have four vehicle";
break;
case 4:
cout<<"\nInvalid city";
break;



}
}
return 0;
}

Comments

Popular posts from this blog

DSL

9: Program Setatement A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation, capitalization, and spaces are ignored. For example, ‖Poor Dan is in a droop‖ is a palindrome, as can be seen by examining the characters ―poor danisina droop‖ and observing that they are the same forward and backward. One way to check for a palindrome is to reverse the characters in the string and then compare with them the original-in a palindrome, the sequence will be identical. Write C++ program with functions- 1. to check whether given string is palindrome or not that uses a stack to determine whether a string is a palindrome. 2. to remove spaces and punctuation in string, convert all the Characters to lowercase, and then call above Palindrome checking function to check for a palindrome 3. to print string in reverse order using stack Program: #include<iostream> #include<string.h> #define MAX 100 using namespace std;  struct stack ...

DSL

13: Problem Statement: Pizza parlor accepting maximum M orders. Orders are served in first come first served basis. Order once placed cannot be cancelled. Write C++ program to simulate the system using circular queue using array. Program Code: #include <iostream> using namespace std; #define size 5 class pizza {     int porder[size];     int front,rear; public:     pizza()     {      front=rear=-1;     }     int qfull()     {      if((front==0)&&(rear==(size-1))||(front==(rear+1)%size))          return 1;      else          return 0;     }     int qempty()     {         if(front==-1)             return 1;         else             return 0;    ...

DSL

14.Problem statement Write C++ program to store roll numbers of student in array who attended training program in random order. Write function for-  a) Searching whether particular student attended training program or not using linear search and sentinel search.  b) Searching whether particular student attended training program or not using binary search and Fibonacci search.    program #include<iostream> using namespace std; class search {  public:         int n,i,data[50],son[50],sortdata[50],s;  void intake() {     cout<<"Enter No. of Elements=";   cin>>n;   cout<<"\nEnter Elements=\n";   for(i=1;i<=n;i++)   {   cin>>data[i];       son[i]=data[i];   } } void search_lini(int item) {   s=0;   for(i=1;i<=n;i++)   {  if(data[i]==item) ...