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
What is motivation and state the two forms​
pav-90 [236]
It is extrinsic Motivation
3 0
3 years ago
Which type of development metrics does Instagram most improve when it releases an update in the App Store to fix errors its cust
Andrew [12]

Answer:

customization.

Explanation:

8 0
3 years ago
Which resource helps a user access a cloud service?
gregori [183]

Answer B (Data storage system)

5 0
3 years ago
Which code will allow Joe to print Coding is fun. on the screen? print("Coding is fun.") print(Coding is fun.) print = (Coding i
ludmilkaskok [199]

Answer:

print(“Coding is fun.”)

Explanation:

The proper format for a print statement is usually you have the print statement followed by the string in quotes in parentheses.

Hope this helped!

7 0
3 years ago
Read 2 more answers
Write a function called first_last that takes a single parameter, seq, a sequence. first_last should return a tuple of length 2,wh
motikmotik

Answer:

The Python code with the function is given below. Testing and output gives the results of certain chosen parameters for the program

Explanation:

def first_last(seq):

   if(len(seq) == 0):

       return ()

   elif(len(seq) == 1):

       return (seq[0],)

   else:

       return (seq[0], seq[len(seq)-1])

#Testing

print(first_last([]))

print(first_last([1]))

print(first_last([1,2,3,4,5]))

# Output

( )

( 1 , )

( 1 , 5 )

5 0
3 years ago
Other questions:
  • Opportunity cost is the least desirable alternative given up as a result of a decision.
    6·1 answer
  • Types of operating systems
    5·2 answers
  • Which is the correct process for attaching a file?
    12·1 answer
  • Implement a java program to find the smallest distance between two neighbouring numbers in an array.
    7·1 answer
  • You can count on everything online to be 100% accurate. <br> A. FALSE <br> B. TRUE
    11·2 answers
  • Kelly is a college sophomore majoring in computer science. She is interested in gaining exposure to the most useful and current
    14·1 answer
  • You dad has given you his old digital scanner for your new computer. you plug it into the usb drive on your windows 8 computer b
    8·1 answer
  • Technician A says that as volume decreases, pressure increases. Technician B says that as temperature increases, pressure decrea
    15·2 answers
  • Recently, Walmart offered a wireless data contract based on bandwidth used, with a minimum monthly charge of $42 for up to 5 gig
    15·1 answer
  • The sdlc phase in which functional data specifications and processing rules are created is the ______________ phase.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!