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
How to bypass securly or fortiguard (fortinet)
ira [324]

Answer:

thanks for whatever you just said!! <3

Explanation:

3 0
2 years ago
The Internet enables people to make better economic decisions because they
sammy [17]

Answer:

C

Explanation:

C seems to be the most logical choice for a "good" choice.

It makes the most sense.

8 0
3 years ago
Read 2 more answers
What is an I-94?
Ilia_Sergeevich [38]

Answer:In my opinion I think its A

Explanation:

Sorry if wrong

8 0
3 years ago
Let A be the set represented by the bitstring 01011011100, let B be the set represented by the bitstring 10110111010. Find the b
Sedbober [7]

Answer:

Ac = 10100100011

A U B =  11111111110

A ∩ B =  00010011000

A - B = 00010010110

Explanation:

Given:

A = 01011011100

B = 10110111010

1)  Inverting the bits of A to calculate the complement, Ac = 10100100011

2) Bitwise union reference:

0 U 0 = 0

0 U 1 = 1

1 U 0 = 1

1 U 1 = 1

=> A U B = 01011011100 U 10110111010 = 11111111110

3) Bitwise interselection reference:

0 ∩ 0 = 0

0 ∩ 1 = 0

1 ∩ 0 = 0

1 ∩ 1 = 1

A ∩ B =  00010011000

4) Converting A and B to decimal and subtracting:

A - B = 732-582= 150

Converting 150 to binary, A - B = 00010010110

5 0
3 years ago
Data type for a Subject ID​
enot [183]

Answer:

An integer.

Explanation:

A subject ID is most commonly an integer.

8 0
3 years ago
Other questions:
  • Hard drives are usually self-contained, sealed devices. Why must the case for the hard drive remain sealed closed?
    8·1 answer
  • Which domain refers to the equipment and data an organization uses to support its IT infrastructure. It includes hardware, opera
    15·1 answer
  • The benefits for a cad proram is: (points : 2) 1 accuracy 2 repeatability 3 simplicity 4 all of the above
    9·1 answer
  • A benefit of flashcards is that they are
    7·2 answers
  • In the world of computing, _________ means acquiring or exchanging copies of protected digital creations without payment or perm
    12·1 answer
  • What happens in Word 2016 when the Home ribbon tab is clicked on?
    9·1 answer
  • List all the steps used to search for 25 in the sequence given below. Use both (a) linear search and (b) binary search. 2, 7, 13
    7·1 answer
  • Please help add header file
    12·1 answer
  • For 8.6 code practice: Question 1 It keeps says it's an infinite loop and it will not work can someone give me the code that wil
    9·1 answer
  • If you enter the search "genetically modified foods" in a database, the double quotes around the three words will:
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!