Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are 2 programs that need to be done but on question 2 , it just needs to h

ID: 3625951 • Letter: T

Question

There are 2 programs that need to be done but on question 2 , it just needs to handle exceptions and invalid input.

1.Write a program the prompts the user to enter a length in feet and inches and outputs the equivalent length in centimeters.If the user enters a negative number or a nondigit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers.

2.Redo the above program(question 1) so that the program handles exceptions such as division by zero and invalid input

Explanation / Answer

#include<iostream>

using namespace std;

class divbyzero { };

const double centi=2.54;

const int inch=12;

void main()

{

int feet,inches;

int totalinches;

double centimeters;

cout<<"Enter the value of feet"<<endl;

cin>>feet;

cout<<"enter the values of inches"<<endl;

cin>>inches;

cout<<endl;

cout<<"you have entered "<<feet<<" feet and " <<inches<<" inches"<<endl;

try

{

if(feet<=0||inches<=0)

{

throw divbyzero();

}

else if(isalpha(feet)!=0||isalpha(inches)!=0)

{

throw divbyzero();

}

else

{

totalinches=inch*feet+inches;

centimeters=centi*totalinches;

cout<<"equivalent in centimeter is" <<centimeters<<endl;

}

}

catch(divbyzero)

{

cout<<"INVALID INPUT!! ENTER FEET AND INCHES HAS TO BE DIGITS GREATER THAN ZERO"<<endl;

}

system("pause");

}