Question: Write an interactive program to compute square root of a number. The input value must be tested for validity. If it is negative, the user

  1. Write an interactive program to compute square root of a number. The input value must be tested for validity. If it is negative, the user defined function my_sqrt() should raise an exception.

Pseudo code:

my_sqrt( a)

begin

try

begin

if (a<0)

throw a

else

print sqrt(a)

end try

catch(x)

begin

print number must not be negative for finding square root

end catch

end

Output:

enter a number:25

square root =5

enter a number: -4

number must not be negative for finding square root

  1. Write a program in C++ that illustrate the mechanism of validating array element references.

Pseudo code:

Array

a[max]

max=10

Operator [](int i)

A[0];

A[0-9]

A[-1]

A[11]

operator []( i)

begin

if (i<0 || i>=max)

throw i

else

return a[i]

end

Output:

trying to refer a[1]

Calling to overload []

3

trying to refer a[13]

Calling to overload []

out of range in array references

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!