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

  Area of the brain that is affected by compulsive gambling

Identify and discuss one area of the brain that is affected by compulsive gambling.

  Choose 2 of the 3 dry-heat cooking methodssauteing

1500 word double spaced library assignment.- select 2 of the 3 dry-heat cooking methodssauteing pan-frying and

  Describe a key role of governance in this process

Focusing in particular on radiology, behavioral health, or intensive care, what considerations would you be most concerned about addressing and why? Who would you involve in the planning process and why? Describe a key role of governance in this pr..

  Explain theory plays an important role in science

What is the main difference between descriptive and experimental research approaches?

  Write paragraphs that examine the meaning of the poem

Write paragraphs that examine the meaning of the poem and how the elements of sound, structure, and figurative language contribute to the meaning.

  How are the bills or laws similar

How is the state's approach different from the federal, and vice versa?Who introduced or sponsored each piece of legislation?

  Describe race and ethnicity

Be sure to incorporate a few terms and some theories about why we have so much suffering amidst such riches and wealth.

  Traditional and non-traditional music of navajo

Contrast, using specific examples, traditional and non-traditional music of the Navajo. Compare the education in drumming of Abubakari Lunna, a drummer of Dagbon, with Agbekor drumming education.

  Concept regarding corpus callosum

Cerebral hemispheres are joined by a large band of fibers termed as the corpus callosum and several small connections termed commissures.

  Should airline pilots be required to go through the same

In your opinion, is it reasonable to require all airline passengers to submit to full-body imaging and pat-down pre-boarding searches? Explain.

  World war ii-korean conflict-vietnam conflict and cold war

Analyze two to three (2-3) major consequences the conflict had on United States' society.  How did this war affect American sensibilities, including the way Americans viewed the war and themselves?

  Why ed tech is not transforming how teachers teach

Why Ed Tech is not transforming how teachers teach. Insightful and true. An update for the KWL. Something to consider, especially in the intermediate and beyond grades.

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