Question

In: Computer Science

C++ problem 1) Describe briefly what exceptions are and what their purpose is. What is the...

C++ problem

1) Describe briefly what exceptions are and what their purpose is. What is the try block? What is the catch block? What happens with the flow of control if the catch block does not catch a thrown exception? Give a simple example.

2) Describe briefly what templates are and what their purpose is.

Solutions

Expert Solution

Answer:

1)Exceptions provide a way to transfer control from one part of a program to another. C++ exception handling is built upon three keywords: try, catch, and throw.

A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks.

catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.

If it does not catch clause that matches a supertype for the exception, then the exception is propagated down the call stack

2)

Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.

A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept.

There is a single definition of each container, such as vector, but we can define many different kinds of vectors for example, vector <int> or vector <string>.

The general form of a template function definition is shown here:

template <class type> ret-type func-name(parameter list) {

   // body of function

}

Here, type is a placeholder name for a data type used by the function. This name can be used within the function definition.


Related Solutions

1) Describe briefly what exceptions are and what their purpose is. What is the try block?...
1) Describe briefly what exceptions are and what their purpose is. What is the try block? What is the catch block? What happens with the flow of control if the catch block does not catch a thrown exception? Give a simple example. 2) Describe briefly what templates are and what their purpose is. 3) Write one line of code for each line below. What is the template type in each case? - Create a vector to store student IDs -...
What are the six exceptions to the basic requirements of FASB ASC 740? Briefly describe each...
What are the six exceptions to the basic requirements of FASB ASC 740? Briefly describe each of the exceptions.
Describe why overly broad exceptions are a problem. In particular, what should you do if you...
Describe why overly broad exceptions are a problem. In particular, what should you do if you are worried you might catch an exception you cannot directly deal with?
1. Briefly describe the purpose/role of): Transformation of bacteria with ligation reactions. What specifically did this...
1. Briefly describe the purpose/role of): Transformation of bacteria with ligation reactions. What specifically did this step allow for and how is the step important to the overall sequencing analysis? 2. Does a 15 nucleotide deletion alter the protein sequence?
Briefly describe what is meant by ABC analysis. What is the purpose of this inventory technique?...
Briefly describe what is meant by ABC analysis. What is the purpose of this inventory technique? Discuss the major inventory costs that are used in determining the EOQ.
What is the purpose of the income statement? Briefly identify and describe the major types of...
What is the purpose of the income statement? Briefly identify and describe the major types of expenses that are shown on the typical income statement. Please don't hand write. Thank you.
What exceptions to the "hearsay rule" have courts recognized? Describe the reasoning behind these exceptions. 300+...
What exceptions to the "hearsay rule" have courts recognized? Describe the reasoning behind these exceptions. 300+ words
Discuss what proteins would be found in the cSMAC, pSMAC, and dSMAC. Briefly describe the purpose...
Discuss what proteins would be found in the cSMAC, pSMAC, and dSMAC. Briefly describe the purpose of each of these SMAC components. Typed only, thanks
Briefly describe the following steps of the forecasting process. 1. determine the purpose of forecast 2....
Briefly describe the following steps of the forecasting process. 1. determine the purpose of forecast 2. Establish time horizon 3.Gather &analyze relevant historical data 4. Select a forecasting technique 5. Prepare forecast 6. Monitor the forecast
(c) What is a blending problem? Briefly discuss the objective function and constraint requirements in a...
(c) What is a blending problem? Briefly discuss the objective function and constraint requirements in a blending problem. Give a real world example of a blending problem. (d) Explain how the simulation process is used in business analytics models. What are the advantages of using simulation? What are its limitations? How can a simulation model be verified? Give a real world example where using simulation is appropriate.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT