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
Assign a variable solveEquation with a function expression that has three parameters (x, y, and z) and returns the result of eva
Arada [10]

Answer:

def func1(x, y, z):

   return z*3*y - x

x= int(input("Enter x"))

y= int(input("Enter y"))

z= int(input("Enterz"))

solveEquation=func1(x, y, z)

print (solveEquation)

Explanation:

Please check the answer section.

6 0
3 years ago
Many businesses use robotic solutions. Which department of the food and beverage industry uses robotic solutions on a large scal
Alenkinab [10]

Answer:

Its packing you're welcome :)

Explanation:

7 0
3 years ago
Read 2 more answers
Which sentences in the passage correctly describe a function?
quester [9]

Option D is correct.

Explanation :

  1. In option A, it is not mandatory that a function will have arguments and it will return a value.
  2. In option B, no formula begins with =.
  3. In option C, it is not necessary to begin with /.
  4. In option D, MAX function should return maximum value in the set given.

Thus, option D is correct because arguments of a function are always enclosed within parentheses

Example:

SUM (30,70)

8 0
3 years ago
In the __________ Standard, chemical manufacturers, importers, and distributors are required to provide hazard information by wa
Bas_tet [7]
The correct answer is C
5 0
3 years ago
Life Decisions Cyber Cafe is a cafe with free Internet service and computers that are linked to various online career opportunit
djverab [1.8K]

Answer:

The correct answer is d) all of the above

Explanation:

The size of the info is necessary to give the users heads up about the amount of data needed to access it, the type of the video is also important so the user can know the environment appropriate for viewing it and also tips for viewing will help users know the requirements needed to view it.

4 0
3 years ago
Other questions:
  • What are some options available when using the Replace feature?
    13·1 answer
  • Peter has recently bought a media player and a digital camera he wants to buy a memory card and then use devices which memory do
    11·2 answers
  • Which of the following statements is true with regards to satellite Internet access?
    13·2 answers
  • Bran is writing a book on operation system errors. Help him complete the sentences.
    7·1 answer
  • A network slows down when a network card is locked in a perpetual mode
    12·2 answers
  • Which is the following should be selected in the paragraph dialogue box to prevent page break from occurring within a paragraph
    12·1 answer
  • Question<br> 1. Who was the first to use an abacus
    6·1 answer
  • What is a thoughtware​
    7·1 answer
  • Can someone reply me
    11·1 answer
  • What does Amara hope will<br> happen when Dad sits on the sofa?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!