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
Flauer [41]
3 years ago
9

Add Try/Catch error checking To make sure that the user enters valid values in your program. To catch negative values passed to

constructor. To catch if not enough memory is available for list. (Hint: bad_alloc)
Computers and Technology
1 answer:
ryzh [129]3 years ago
4 0

Answer:

int main()

{

 cout<<"Enter the size of array\n";

 int n;

 try{

 cin>>n;//get size of array

 if (n > 0){

 List list;//make object of list class

 try{

     list.init(n);//initialize the list

     list.fillData();//fill the data

     list.print();//print the data

     list.sortData();//sort the  data

     cout<<"\n--- After sorting the data---\n";

     list.print();//print the data

     cout<<"Enter the element to search\n";

     int x;

     cin>>x;//get element to search

     list.searchElement(x);//call the search function

 }

 catch (std::bad_alloc){

   cout<<"Sorry, could not allocate memory for list object.";

 }

 }else{

   throw('Negative Number detected');

 }

 }

 catch (int n){

   cout<<"The number should be a positive integer.";

 }

   return 0;

}

Explanation:

The try and catch keywords come in pairs, as they are used to control exceptions in the C++ source code. The try keyword checks for error in the source code given the condition (if the n integer variable is greater than 0). If the condition is met, the code in the try code block runs otherwise the catch keyword catches the error of a negative number (if the n variable in less than 0).

You might be interested in
To add text to a blank slide layout, _____.
Basile [38]
B, draw the text box
3 0
3 years ago
A friend emails a presentation to isabella to view. what kind of change can she make?​
fiasKO [112]

Answer:

She can enable editing. She can change the view.

Explanation:

6 0
3 years ago
The term for an operator that may not evaluate one of its subexpressions is
Xelga [282]

Answer:

short-circuit

Explanation:

3 0
2 years ago
What type of microscope requires a nonmetal sample to be prepared for viewing by coating it with a thin layer of a conductive ma
zheka24 [161]

The answer is a Scanning Electron Microscope

It is important to obtain and prepare proper samples when using SEM. The sample’s size, state, and shape are things that should be considered before the sample preparation. Some samples need to be coated. Most metals require no preparation since they can easily conduct electricity. Non-metals, however, needs to be coated with a thin layer of gold. Gold is the ideal non-metal and works most of the times.

5 0
3 years ago
Read 2 more answers
Dell Computer uses recycled and recyclable materials in its product and packaging design in an effort to minimize damage to the
RoseWind [281]

Answer:

sustainability

Explanation:

Sustainability -

It refers to the method to meet the needs of the present generation without hampering the needs of the future generation as well , is referred to as sustainability .

The process of sustainability require to follow the concept of reuse and recycle to be safe for the environment .

The process is very safe for the planet , as it environmental friendly .

Hence , from the given scenario of the question ,

The correct answer is sustainability .

6 0
3 years ago
Other questions:
  • William has an internet connection that does not allow him to make calls when connected to the internet. what internet service c
    7·2 answers
  • Who is the person responsible for creating the original website content?
    14·1 answer
  • Which of the following is true of how packets are sent through the Internet?
    11·2 answers
  • sqrt is being defined as a variable name, how do I get its math function to... well... function? (Python)
    11·1 answer
  • When you open as many links as you want, and still stay in the same browser window instead of cluttering your screen with multip
    5·1 answer
  • A computer record is used to store all the information about one transaction, but several such records must be used to store the
    12·1 answer
  • If you want to present slides to fellow students your coworkers which productivity software should you use to create them
    15·2 answers
  • Steps in the systems development life cycle​
    15·2 answers
  • The total number of possible keys for des is _________, which a modern computer system can break in a reasonable amount of time.
    10·1 answer
  • On a leading-trailing system technician A says that both shoes do equal work when stopping while going in reverse. Technician B
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!