1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ganezh [65]
3 years ago
12

Write a function that accepts an integer parameter and returns its integer square root (if it exists). The function should throw

an exception if it is passed an integer that is not a perfect square. Do not handle the exception in the function, but instead create the exception handler in main. Make the exception a new exception class which your program creates. Demonstrate the function with a driver program that passes the function the numbers 0 through 25, then prints whether or not the number is a perfect square. (A "perfect square" is a whole number whose square root is also a whole number.)
Computers and Technology
2 answers:
professor190 [17]3 years ago
8 0

Answer:

See explaination

Explanation:

// Include the necessary header files.

#include <iostream>

#include <exception>

#include <cmath>

using namespace std;

// Definition of the function.

int square_root(int n)

{

// Check whether n is less than 0.

if(n < 0)

// Throw exception.

throw domain_error("Supplied integer is negative!");

// check whether n is equal to 0;

else if(n == 0)

// Throw 0.

throw 0;

// Declare a variable and assign value.

double squ_root = sqrt(n);

// // Declare a variable and assign value.

int squ_root_int = (int)squ_root;

// compare values

// check whether the values are equal or not.

if(squ_root != squ_root_int)

// Throw exception.

throw invalid_argument("Supplied integer is not a perfect square !");

// return the value.

return squ_root_int;

}

// Declare the main function.

int main()

{

// declare variables.

int n;

int squ_root;

// Prompt the user to enter the number.

cout << "Enter a number: ";

cin >> n;

// start the try block.

try

{

// call to the function.

squ_root = square_root(n);

// Display the statement on console.

cout << "Square root is " << squ_root << endl;

}

// start the catch block.

catch(domain_error e)

{

// Display the statement on console.

cout << "Error: " << e.what() << endl;

return -1;

}

// Start the catch block

catch (int y)

{

// check whether y is equal to zero or not.

if(y == 0)

{

// Display the statement on console.

cout << "Error: Supplied integer is zero !" << endl;

return -2;

}

}

// Start the catch block

catch(invalid_argument e)

{

// Display the sstatement.

cout << "Error: " << e.what() << endl;

return -3;

}

// Return the value.

return 0;

}

kupik [55]3 years ago
4 0

Answer:

Check the explanation

Explanation:

#include <iostream>

#include <cmath>

#include <math.h> //Not sure about including math.h

using namespace std;

int sqrt4(const int m)

{

  int i=0;

const int q=0;

  while( (i*i) <= m )

{

if(i*i==m)

{

q++;

return i;

}

else

{

i++;

}

}

if(q==0)

{

throw "not a perfect square!";

}  

}

int M1 (int x){

  cout << "Number: " << x << endl;

  x = sqrt(x);

  cout << "Number's square root: " << x << endl;

 

  return x;

}

void main (){

  int y = 4; // Program currently uses 4 in calculations

  M1 (y);

}

You might be interested in
Given a string, an integer position, and an integer length, all on separate lines, output the substring from that position of th
lana [24]

quetma es elpx mjeghgieo

4 0
3 years ago
Are technical skills or people skills more important to the team manager in a software development project?
VladimirAG [237]

Answer:

A well-rounded team manager in a software development project is critical to its success. Having the best developers only gets you so far. Without proper leadership, the project will most likely fail. Developers won't know what direction to go, deadlines won't be met, and the end product will not be created to the specifications as set forth in the project. A software development team manager needs to possess both the proper technical skills to guide the developers when they get stuck, but more importantly have the proper people skills and business process skills to allow the team to work as a well-oiled machine. In this paper, we will look at two different types of team managers and how they affect the software development lifecycle.

5 0
3 years ago
Read 2 more answers
Microsoft Access:
klemol [59]

Answer:

C. Apply a sort

Explanation:

From the list if options A through D, only option C best answer what's been illustrated in the question.

For a query to be in a given order, it has to be sorted, in other words, you apply a sort.

It should also be noted that, when sorting a query, the result will be sorted based on the fields in the table.

Take for instance,

The fields of a table named table1 are;

SN

NAME

AGE

You will sort the records by SN or by NAME or by AGE or by combination of two of those fields.

Sorting a query will place the records in a defined logical order which could in ascending order or descending order.

4 0
3 years ago
During the morning of a website launch for a new government sponsored healthcare portal, an unknown political rival, individual,
Softa [21]

The likely reason for the attack is an act of hacktivism as a way for the hacker to spread messages for their own agenda.

From the complete information given, during the morning of a website launch for a government-sponsored program, an unknown political rival had access to the server and the content showed human rights campaigns.

This is quite different from the original intent of the message to be sent. In this case, the reason for the attack is that the hacker wants to pass their own message to the people.

Read related link on:

brainly.com/question/25682883

4 0
3 years ago
at&amp;t The type of shape that is not defined by a continuous boundary, but is suggested by dots or lines that do not connect—a
MaRussiya [10]

Answer: An Implied shape

Explanation:

An implied shape is not a traditionally defined shape. The at&t logo, although resembling a sphere does not have a continuous border. It instead uses lines to infer a spherical shape.

The designer, Saul Bass uses a viewer's existing knowledge of what a sphere looks like, gets the viewer to see the logo as a sphere.

This kind of implied shape can also be seen in Sauerkids pieces. In their works, lines are not continuous but shapes are clearly implied.

3 0
3 years ago
Other questions:
  • Climate is considered a(n) _______ limiting factor. (2 points)
    9·1 answer
  • Mary, Tim, John, and Jenn each sold three million dollars worth of product within six months. Each month one of them was awarded
    12·2 answers
  • In ssl/tls, a specific set of protocols that a particular cryptographic system will use to provide protection is called a ______
    5·1 answer
  • Which of the following Office Online apps is most effective for creating spreadsheets?
    14·2 answers
  • Many programmers today use a(n) _________, which is software that helps them build their computer programs. eula cad sdlc ide
    15·1 answer
  • What is the gauge manifold made of
    14·1 answer
  • Write a program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name wil
    13·1 answer
  • The right to make others do things is referred to as _________.
    14·2 answers
  • Write a program that gets three input characters which are user's initials and displays them in a welcoming message. Then gets i
    12·1 answer
  • What is the name and purpose of the star next to a slide in a PowerPoint presentation?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!