Implement functions that perform operations on ranges

Assignment Help Programming Languages
Reference no: EM132240435

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: EM132240435

Questions Cloud

What is operating income under variable costing : Fixed overhead is $4,000 per month; it is applied to production based on normal activity of 2,000 units. What is operating income under variable costing
Experience part of the firms culture : What made it that way and were you satisfied in the end. Was your experience part of the firms culture or did you get them on a bad day?
Record all necessary journal entries in the general ledger : The city of Salem issued purchase orders totaling $600,000. Record all necessary journal entries in the general ledger
Describe 3 pieces of legislation that may affect : Describe 3 pieces of legislation that may affect you with your personal work priorities
Implement functions that perform operations on ranges : CS 170 – High-level Programming - understand the purpose of using pointers (a range) with these arrays instead of relying on the size
How much of the cost must don include in his income : Don Driller, who is 56 years old, is provided with $120,000 of group-term life insurance by his employer. How much of the cost must Don include in his income
What are benefits of business networking : What are benefits of business networking? provide sample of networks you could join.
Describe 3 pieces of legislation : Describe 3 pieces of legislation that may affect you with your personal work priorities.
Discussion on strategic benefits planning : Compare and contrast the two approaches to strategic benefits planning referred to as "Top-Down" and "Backing-In". Based on your current organization's strategy

Reviews

len2240435

2/22/2019 9:16:36 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

Programming Languages Questions & Answers

  Formulate a nonlinear-programming model that will have

Formulate a nonlinear-programming model that will have an expected number T of enrolling needy admit tees, and minimize the scholarship budget.

  Develop the interactive calculator in bash shell script

Develop the interactive calculator completely in bash shell script (Linux programming). This calculator program must have the following features: Entry of expression acceptable to expr

  Write the function header of the default copy constructor

Write the function header of the default copy constructor for a class called A. Write one default constructor prototype of a class called A

  Write a perl subroutine that reads in a file containing two

write a perl subroutine that reads in a file containing two strings on each line and creates a hash with the first

  Design a program that asks for the price of each item

Please provide a pseudocode and flowchart for the program that follows the guidelines of good program design, like meaningful variable names and thoroughly commented code.

  Do comments explain processing that is not obvious

When reviewing a program, these are the four criteria for style: Do identifiers logically describe use? Is indentation used correctly to illustrate the structure of the program?

  Write a program which reads a string as an input

Write a program which reads a string as an input then it counts number of occurrences for each letter, and then displays the letters which occurred 3 times or more.

  Write a program to display the duplicate values in an array

Write a program to display the duplicate values in an array.

  Create an html5 application using the guidelines

Produce an HTML5 page divided vertically into two divs (left and right).

  Define prolog relations for the following

Provide some facts for the father, mother, male, and female predicates and then test the entire thing using Prolog.

  Write the program using the ide functions

Write the program using the IDE functions. Rewrite the program using C and not the IDE functions. Again, submission are in txt only files.

  Write spark program that load data and analyze data quality

Write a Spark program that loads the data, analyzes data quality, provides a summary report, and reports your findings, abc is an eCommerce company

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