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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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