Write a comment for the function declaration

Assignment Help C/C++ Programming
Reference no: EM131708494

Assignment

QUESTION 1

Write a function template name maximum. The function takes two values of the same type as its arguments and returns the larger of the two arguments (or either value if they are equal). Give both the function declaration (prototype) and the function definition for the template. You will use the operator < in your definition. Therefore, this function template will apply only to types for which < is defined. Write a comment for the function declaration (prototype) that explains this restriction. Use Preconditions and Postconditions for the comment, similar to the example for the sort function declaration (prototype) on page 711, Display 16.2. Preconditions explains the input (parameters) for the function and the rules for what makes valid parameters. Postconditions explains the output of the function.

QUESTION 2

Write a function template name square. The function takes one values that value * itself. Give both the function declaration (prototype) and the function definition for the template. You will use the operator < in your definition. Therefore, this function template will apply only to types for which * is defined. Write a comment for the function declaration (prototype) that explains this restriction. Use Preconditions and Postconditions for the comment, similar to the example for the sort function declaration (prototype) on page 711, Display 16.2. Preconditions explains the input (parameters) for the function and the rules for what makes valid parameters. Postconditions explains the output of the function.

QUESTION 3

Would your function template for question 1 work if you gave it the arguments 3 and 4.5? Test it for yourself. If it works, just say yes it works. If it doesn't work, explain why not.

QUESTION 4

Did you know that you can actually write the solution for question 1 in such a way that it would work for more than one type? The book didn't get into this, but for example you could write a function like this:

template<class T, class V>
void compare(T testval1, V testval2);

Just thought I would point this out since I didn't see it in the book. It is often a good practice to *not* allow for two different types unless you have specific reasons to allow for it. Writing this:

template<class T>
void compare(T testval1, T testval2);

Write a class template variation of the following class definition.
classbasicObject{
public:
basicObject();
basicObject(float newData);
floatgetData();
voidsetData(float newData);
private:
float data;
};

Replace all instances of float with the variable class T. You do not need to write implementations for the functions.

QUESTION 8

Is it legal for a derived template class to start as shown in the following code? The template class TwoDimPFArrayBak is designed to be a two-dimensional partially filled array with backup.

template< class T >
classTwoDimPFArrayBak : public PFArray< PFArray< T > >
{
public:
TwoDimPFArrayBak();
Note that the space in < PFArray< T > > is important, or at least the last space is. If the space between the next-to-last > is omitted, then the compiler may interpret >> to be the extraction operator used for input expressions such as cin >> n; rather than interpreting it as a nested < >.
What would need to be added

QUESTION 9

Consider the following toString function which converts an integer into a string using the ostringstream object type. (For more details on this technique see Chapter 12)
std::stringtoString(intval){
std::ostringstream outs; //create a string output stream object
outs<<val; //insert val onto the string output stream
returnouts.str(); //return the string stored on the string output stream
}

Re-write this function as a function template which will convert any data type to a string. Should work for any data type which will work as the right-hand-1side of the << operator (as the integer val is doing here).

QUESTION 10

As a bit of outside reading, please browse some of the class templates available in the Standard Template Library (STL).

Read through a few of these, in particular the Algorithms and Containers.

All of these and more are made possible by class templates.

Describe the things you're most excited to see here and what you might want to use them for. Of course vector is great, but what are some other useful tools and how might you want to use them?

[Name at least 2 that were interesting to you, give some real-life application ideas. Feel free to gush.]

QUESTION 11

Considering the examples from the textbook and the examples from the STL, typical uses of class templates can be fairly abstract.

Put your mind to it and think of one other example of a good class template to make other than the ones listed in STL and the textbook. Perhaps it could be related to program 2 (I've got at least one idea there, I'll tell you about it next week). Provide a description of it and the types of member functions it would have / the purpose it would serve.

If you can't think of a class template to make, instead tell me an idea you had and what was wrong with it [Why you didn't feel like it would make a good class template afterall.]

Reference no: EM131708494

Questions Cloud

Differenciate a management fee and technical assistance fee : What is the difference between a "management fee," a "technical assistance fee," and a "license fee for patent usage?" Should they be treated differently.
Construct a simple decision tree diagram : 23787 HEALTH TECHNOLOGY ASSESSMENT. Construct a simple decision tree diagram to assess the cost-effectiveness of a new cervical screening test
Difference between a license fee and a royalty fee : Allocated Fees-1. What is the difference between a "license fee" and a "royalty fee?" Do you think license and royalty fees should be covered by the tax rules.
Define the optimal solution for case of sister subsidiaries : Sister Subsidiaries. Subsidiary Alpha in Country Able faces a 40% income tax rate. Subsidiary Beta in Country Baker faces only a 20% income tax rate.
Write a comment for the function declaration : Write a comment for the function declaration (prototype) that explains this restriction. Postconditions explains the output of the function.
What is symbolic about the fence : In what ways has Troy's character been shaped by his contact with the white world? Is Troy a tragic hero? If so, what is his flaw?
Discuss the constraints on positioning funds : Constraints on Positioning Funds. Each of the following factors is sometimes a constraint on the free movement of funds internationally.
Review revenue growth and sales price scenario : Hermosa Components: Revenue Growth and Sales Price Scenario. In addition to the assumptions employed in problem II, Hermosa now wishes to evaluate the prospect.
Evaluate scenario for the project and parent viewpoints : Hermosa Components: Revenue Growth Scenario. As a result of their analysis in problem, Hermosa wishes to explore the implications of being able to grow sales.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Complete the leadership in action case study

Complete the Leadership in Action case study for Lehman Brothers on page 276-277 in your textbook.

  Problem related to stroing of text file values into vector

I have to store the text file values into a vector and do the sum, here the text file sample: Expenses: Equipment:$300 Food: $50  Consumable expenses: $100

  Write a program that declares three one dimensional

Write a program that declares three one dimensional arrays named miles, gallons, and mpg . Each array should be declared in main( ) and should be capable of holding ten double

  Prepare a program for sorting the numbers

Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is void sort3(double *x, double *y, double *z);

  Calculate the average of three exams for five students

This program will calculate the average of 3 exams for 5 students. The program will ask the user to enter 5 student names.

  Write function to accept character array

Write down the C++ function which will accept the character array of at most 30 cells. Your function must return true if string and its reverse are identical;

  Use a switch statement

Use a switch statement to write a program that prompts user to enter an character.

  A program that takes into account a pre given array

Problem: A program that takes into account a pregiven array and prompts the user to enter a return per minute value.

  Calculate the total expences

Trying to fugure out how to enter a formula in a cell(d10) that multiplies 30 by the value in another cell (c27), then make the other cell (c27) an absolute cell reference in the formula. Copy the formula to cells d11:d13, and then calculate the t..

  Define a derived class of the class j panel

You are used to defining derived classes of the Swing class J Frame. You can also define derived classes of other Swing classes.

  Determines and prints the smallest and largest integer

Write a program that accepts 10 integers and determines and prints the smallest and largest integer input by the user.

  The funtion should take as parameters

Write a function in c ++ that multiplies two functions. the funtion should take as parameters two fraction structures. Then, the function should multiply the two fractions and return the solution as a fraction structure.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd