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
How do big organizations take back their data to be reviewed after a disaster?
Jet001 [13]
Here a 5 step recovery plan, I have been in IT for 8 years

1. Create a disaster recovery team.

The team will be responsible for developing, implementing, and maintaining the DRP. A DRP should identify the team members, define each member’s responsibilities, and provide their contact information. The DRP should also identify who should be contacted in the event of a disaster or emergency. All employees should be informed of and understand the DRP and their responsibility if a disaster occurs.

2. Identify and assess disaster risks.

Your disaster recovery team should identify and assess the risks to your organization. This step should include items related to natural disasters, man-made emergencies, and technology related incidents. This will assist the team in identifying the recovery strategies and resources required to recover from disasters within a predetermined and acceptable timeframe.

3. Determine critical applications, documents, and resources.

The organization must evaluate its business processes to determine which are critical to the operations of the organization. The plan should focus on short-term survivability, such as generating cash flows and revenues, rather than on a long term solution of restoring the organization’s full functioning capacity. However, the organization must recognize that there are some processes that should not be delayed if possible. One example of a critical process is the processing of payroll.

4. Specify backup and off-site storage procedures.

These procedures should identify what to back up, by whom, how to perform the backup, location of backup and how frequently backups should occur. All critical applications, equipment, and documents should be backed up. Documents that you should consider backing up are the latest financial statements, tax returns, a current list of employees and their contact information, inventory records, customer and vendor listings. Critical supplies required for daily operations, such as checks and purchase orders, as well as a copy of the DRP, should be stored at an off-site location.

5. Test and maintain the DRP.

Disaster recovery planning is a continual process as risks of disasters and emergencies are always changing. It is recommended that the organization routinely test the DRP to evaluate the procedures documented in the plan for effectiveness and appropriateness. The recovery team should regularly update the DRP to accommodate for changes in business processes, technology, and evolving disaster risks.



summary :an organization must develop a recovery team to create a disaster recovery plan that includes identifying and assessing disaster risks, determining critical applications, and specifying backup procedures. Other procedures may be included in the plan based on the organization. The recovery team and organization must then implement the DRP and follow through on the plan procedures. The DRP should be continually tested and maintained to consistently prepare the organization for evolving disasters and emergencies.
4 0
2 years ago
Which of the following is a basic concept associated with Web 2.0? Select one: a. shift in user's role from the passive consumer
soldier1979 [14.2K]

Answer:

A: shift in user's role from the passive consumer of content to its creator

Explanation:

During the phase of Web 2.0, consumers evolved from just been highly informed and socially connected (in other words, they evolved from being just passive consumers) to a more engaged and empowered consumer. This implied that consumers could easily adapt to new technologies to meet individual needs and create an emotional bond with brands. They evolved from passive consumers to being the creators of what they wanted to meet their specific needs.

5 0
3 years ago
Review universal data models and discuss how these are being used more widely today. Does a data modeling project using a packag
adell [148]

Answer:

2. A data modelling project using a packaged data model REQUIRES A GREATER SKILL than a project not using a packaged data model.

Explanation:

1a. Review of universal models:

A data model is an abstract model that organizes elements of data and standardizes how they relate to one another and to the properties of real world entities. It has become the standard approach used towards designing databases.

A universal data model is a template data model that can be reused as a starting point or a building block to jump-start development of a data modelling project, industry specific model, logical data models.

1b. Discuss how these are being used more widely today.

*Universal data models helps professional reduce development time, improve consistency and standardization while achieving high quality models.

*Higher quality: just as architects consider blue prints before constructing a building, one should also consider data before building an app. A data model helps define the problem, enabling one to consider different approaches and choose best ones.

*By properly modelling and organization's data, the database designer can eliminate data redundancies (needless repetitions) which are a key source for inaccurate information and ineffective systems.

2. Greater and advanced skills are adequate and required when data modelling project is done using packaged data model while fewer skills are required when data modelling is done without packaged data model.

7 0
2 years ago
Read 2 more answers
The user will input a three digit number
zlopas [31]

import java.util.Scanner;

public class U1_L5_Activity_One {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Please enter a two digit number: ");

int x = scan.nextInt();

System.out.println("Here are the digits:");

System.out.println(x/100);

System.out.println((x/10)%10); <em>//Just divide the result by 10 and find the remainder</em>

System.out.println(x%10);  

}

}

<em>//Or, you can do that way:</em>

<em />

import java.util.Scanner;

 

public class U1_L5_Activity_One {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Please enter a two digit number: ");

String[] x = scan.nextLine().split(""); <em>//We need it to be a string array, to split the values after "", that is, after each symbol(number)</em>

System.out.println("Here are the digits:");

for(int i = 0; i<x.length; i++) {

          System.out.println(Integer.parseInt(x[i])); <em>//Converting the string into int, as you want</em>

      }  

}

}

5 0
2 years ago
Which storage device would you most likely use to share a file with a classmate?
valina [46]
You’d probably use a USB Flash Drive.
6 0
3 years ago
Read 2 more answers
Other questions:
  • A laptop computer has two internal signals: An unplugged signal, which is '1' if the laptop's power supply is connected, and '0'
    5·1 answer
  • Which type of object is used to organize and store data in Microsoft access 2013
    5·2 answers
  • Which of these automotive repair areas helps the vehicle change speeds to operate efficiently under all conditions?
    5·1 answer
  • A virtual private network (VPN) is used to securely connect to another network over a insecure network.
    9·2 answers
  • Why is it important to minimize cable clutter in a rack?
    11·1 answer
  • 2.
    5·1 answer
  • What is the correct order of headers, from left to right, in a completed frame?
    8·1 answer
  • How does the Problem-solving Process help us to solve everyday Problems?
    13·1 answer
  • Can anyone please help me out
    10·1 answer
  • Which statement is true about encoding in Python?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!