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
Consider Parameters with Referencing Environment. One complication with parameters that are subprograms appears only with langua
solniwko [45]

In Consideration of Parameters with Referencing Environment, the option is All of the above are options.

<h3>What is referencing environment?</h3>

The referencing environment of any kind of statement is the composition of the full names that can be found or seen visible in that given statement.

Note that  in any kind of  static-scoped language, the local variables with the addition of all  seen variables can be placed in an enclosed scopes and as such, in the scenario above, all the options are correct.

See options below

A. Shallow binding with the environment of the call statement that enacts the passed subprogram.

B. Shallow binding which is most natural way for dynamic-scoped languages

C. Deep binding - with the environment of the definition of the passed subprogram.

D. Ad hoc binding with the environment of the call statement that passed the subprogram.

E. All of the above are options.

Learn more about Environment from

brainly.com/question/17413226

7 0
3 years ago
Can someone help me find all the solutions to the problem ​
zepelin [54]
Answer this with the dots connected. Why is it. You may ask? I bet it’s 40
7 0
3 years ago
Read 2 more answers
What is a spark line? how is a different a chart​
Neporo4naja [7]

Answer:

A sparkline is a tiny chart in a worksheet cell that provides a visual representation of data.

5 0
3 years ago
Where would you go to access frequently used icons?
trapecia [35]

Answer:

b

Explanation:

4 0
3 years ago
Read 2 more answers
What is output? c = 1 sum = 0 while (c &lt; 10): c = c + 3 sum = sum + c print (sum)
Valentin [98]

Answer:

21

Explanation:

The values of c that make it into the loop are 1, 4, 7.

The values that are added to sum are 3 higher, i.e., 4,7 and 10.

The sum of those is 21.

p.s. why did you not run the program yourself?

3 0
3 years ago
Other questions:
  • Some people are unable to arrange six matches to form four equilateral triangles because they fail to consider a three - dimensi
    6·1 answer
  • A résumé can be delivered through _____.a.
    9·2 answers
  • Which of the following Internet access methods involves connecting your phone to an Internet-ready laptop in order to gain acces
    14·2 answers
  • #include
    11·1 answer
  • Suppose that the domestic production of computer games creates enjoyment for those who play the games. Domestic production of co
    14·1 answer
  • The term "exception propagation" means:
    5·1 answer
  • If you used a peach as a model of an animal cell, what would the peach's skin represent? A.nucleus B.cell wall C.cytoplasm D.cel
    10·2 answers
  • The long-run average cost curve is typically _______________________. a) downward-sloping at first but then b) upward-sloping up
    14·1 answer
  • How does one award the brainliest???? will give brainliest.
    8·2 answers
  • Compare the freedom available to the American media with the freedom available to media in other parts of the world. How does a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!