Implement template functions that work on ranges

Assignment Help Other Subject
Reference no: EM132240374 , Length: word count:1200

Lab: Function Templates

This assignment gives you practice with function templates, overloaded functions, pointers, and ranges. The goal is to implement several template functions that work on ranges. You will implement functions that perform operations on ranges such as removing elements within the range, replacing elements within the range, searching for elements, copying one range to another range, etc. You will have a header file that looks like this:

//-------------------------------------------------------------------------------------
#ifndef FUNCTIONS_H #define FUNCTIONS_H
//-------------------------------------------------------------------------------------
namespace CS170 {
/*
* Other template function declarations for count, remove, replace, etc.
* go there.
*/
template <typename T> void swap(T &left, T &right);

#include "Functions.cpp"
}
#endif
//-------------------------------------------------------------------------------------

Your .cpp file will contain several functions. The sample driver shows many of them. You will need to figure out what others are required. Many of the functions are going to be very similar in their implementation. However, for this assignment, do not be tempted to try and factor out the minimal common code into a separate function, because it will only complicate matters. Once you understand the concept of a range, you will see that the amount of code is not that great. It never is. The most complex function is the remove function, so you should work on that one last.

As you implement the functions, you should begin to see a pattern emerging in your code. This should help you understand the purpose of using pointers (a range) with these arrays instead of relying on the size. A range is much more flexible than an array with a size.

Other Criteria

1. With the exception of the remove function, the other functions are trivial.

2. Do not use the subscript operator anywhere in your code. Not even in a comment. You are given a range, not an array.

3. You are not to use for loops anywhere in your code. Use while loops. Why? Because many students still do not understand the while loop.

4. You must make sure that your functions can deal with the appropriate calls. This means you need to decide how and when to use const in your code. The sample driver may not test all cases so you may need to add more tests. You have been warned.

5. Remember: template functions are only generated if you call the function. Do not end up getting a 0 due to your code failing to compile because you did not add the necessary test cases. Your code will fail to compile if you forgot a case.

6. Templated functions can take many different types - even large user-defined types. Use references wherever possible.

7. Do not include any header files other than iostream in your .cpp file. Why? Because you do not need any others.

8. You are not creating any classes for this assignment - just a bunch of functions. In your files, make sure that you arrange the functions alphabetically. This includes the header file as well as the implementation file. This will make it easier to find the functions when we grade your assignment. If you are lexicographically- challenged, please ask one of the tutors or myself for help in ordering your functions or see the web page and FAQ for this assignment.

9. Your template parameter must be named T. If you have two template parameters, they must be named T1 and T2.

10. You will need to use std::cout to print out the elements in the display function. Make sure you format the output exactly as shown in the output-sample.txt file as I am not providing the output function for this assignment. Not using a diff tool can potentially cause all your output to be incorrect leading to substantial deductions of points. Again, you have been warned.

11. You must include the .cpp file at the end of the .h file exactly as shown above.

12. The remove function is the only non-trivial function and should be implemented last. You must understand the algorithm that was discussed in class in order to implement this. Before attempting to write code for this function, you must write pseudocode. If you cannot write pseudocode - meaning that you do not understand what you are trying to do - then you cannot write C++ code. Make sure that your function only makes one pass over the array. Failure to do so will lead to deduction of points.

13. Finally, NO OVERLOADED FUNCTIONS ARE ALLOWED. This means that some functions will need multiple template parameters to work correctly.

Range Notes
When we are talking about a range of objects in a container (a container "contains" objects or data using either arrays, linked lists, trees, etc.), we are actually describing a half-open range. This means that the left end "points" to the first element in the range and the right hand "points" to the one after the last element to include. left and right may not be pointers - but you can think of them that way. This is also called a left-inclusive range and is noted like this:

[first, last)

So, if you wanted to print the middle 3 integers of this array, this is how you might do it:

int array[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
print_range(&a[3], &a[6]);// some function that will print a range of ints

Deliverables
You must upload your header file (Functions.h), implementation file (Functions.cpp), Doxygen-generated index.chm, and the signed programming checklist in a .zip file to the assignment web page. Note that you are not submitting any other file.

Attachment:- Function Templates.rar

Reference no: EM132240374

Questions Cloud

Unilateral right of the government : True or False? An option is the unilateral right of the government to extend or buy more than the amounts bought at the time of award.
Analyze applications of change management principles : Analyze applications of change management principles. Describe an effective team from a real-world experience, including the tasks of the team.
Actionly invades customer privacy by taking data : Actionly invades customer privacy by taking data from different websites such as Twitter and Flickr without the consent of the customer who posted
What you think of this lack of rigor in federal control : Federal agencies issue numerous regulations and guidelines, and state and local officials complain about their proliferation.
Implement template functions that work on ranges : CS 170 – High-level Programming - understand the purpose of using pointers (a range) with these arrays instead of relying on the size
Fundamental attribution error and self-serving bias : The fundamental attribution error and self-serving bias are. and how has this contributed to mistakes you have made in judging other people.
How can team conflict affect performance : Provide a brief response to each of the following questions. 1. How can team conflict affect performance? Is conflict always bad?
Diagnose the reasons for resistance to change : HRM560 Diagnose the reasons for resistance to change. Interpret the potential causes of resistance in the organization (WALMART).
Identify the four functions of the kidneys : Discuss how the processes of excretion and reabsorption occur and the substances involved.

Reviews

len2240374

2/22/2019 8:54:28 PM

You must upload your header file (Functions.h), implementation file (Functions.cpp), Doxygen-generated index.chm, and the signed programming checklist in a .zip file to the assignment web page. Note that you are not submitting any other file. Source files Description Functions.cpp The implementation file. All function definitions go here. You must document the file (file header comments) and all functions (function header comments) using the appropriate Doxygen tags. Failure to do so will result in a very poor grade. Functions.h The header file. You will need to modify the one I posted. You must document the file with a file header comment. Absolutely NO implementation is permitted in this file. However, you must #include the .cpp file exactly as instructed. Usual stuff Your code must compile (using the specified compilers) to receive credit. Make sure your name and other information is on all submitted files.

Write a Review

Other Subject Questions & Answers

  Discuss mechanical solidarity and organic solidarity

David Émile Durkheim: "The Division of Labour in Society". Discuss mechanical solidarity and organic solidarity.

  Human behavior and characteristics

Read the paper. In one or two paragraphs, describe what is meant when the writer says "Most entities prefer outsourcing professionally qualified consultants in threat assessment process

  How does the case of puerto rico and puerto ricans affect

How does the case of Puerto Rico and Puerto Ricans affect the notion of race and ethnicity as a social constructs?

  Write a movie analysis paper

Your task will be to identify concepts/theories that are discussed in the text and indicate the extent to which the movie has accurately portrayed.

  Drew on dendrochronology

The Jamestown Island tree ring study drew on dendrochronology not to date the site, but to study what? (a short phrase will suffice)

  How improving the efficiency of the investigation

Suggest one (1) strategy geared toward to improving the efficiency of the investigation. Provide a rationale to support your response

  Response regarding the appointment

The mother of a 6-month-old infant calls the office requesting an appointment for her child. She advises that she thinks the child's head appears swollen and that there are areas that appear to be bulging. What is your response regarding the appointm..

  Which may be able to wait until you have more time for them

Discuss how you would plan your week to ensure that you get all of your important tasks accomplished.

  Characterize the informal economy

Characterize the informal economy. The proportion of the population engaged in the informal economy is larger in poor countries than in rich countries. Explain why it is larger in poor countries.

  Describe the responsibilities of judges

Describe the responsibilities of judges. Identify attributes of both effective and ineffective judges. Provide an example of an effective and an ineffective Supreme Court judge.

  How do experiments do a better job assessing causality

what components differentiate experiments from the non-experimental methods . how do experiments do a better job assessing causality?

  Q1 with particular reference to the experiences of olaudah

q1. with particular reference to the experiences of olaudah equiano discuss the impact of the slave trade on african

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