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

  Why you think additional personnel are generally required

Why you think additional personnel are generally required during the later stages of systems implementation? In addition, how do training activities differ between end users and system operators? Why?

  Clear description of the program

Program Description- A detailed, clear description of the program you are building. Analysis- Demonstrates your thought process and steps used to analyze the problem. Be sure to include the required input and output and how you will obtain the req..

  Creating code for method tostring

Fill in the code for method toString, which must return a string containing the name, account number, and balance for the account.

  Create a program that generates a random password

Create a program that generates a random password ***** user-defined length. For the purposes of this problem, we will assume that any character that corresponds to ASCII (decimal) values.

  Write a program that will find mean and standard deviation

Write a program, using C#, that will find the mean and standard deviation of a number of data points. The program should allow the user to either enter data.

  Matlab that will use the flipping of two-sided coins to sim

Write a program in matlab that will use the flipping of two-sided coins to simulate any event that has a probability of success(Ps) that ranges between 0 and 1. The simulation will most likely be approximate. It must be accurate to at least 0.01

  Convert teradata macro code in to teradata stored procedure

Attached the file in that file it is teradata macro code. Need to convert it to Teradata Stored Procedure

  Prompt input function

You have no guarantees about the accuracy of the input from the user. You have to check all input and give helpful error messages to assist the user.

  What causes an infinite loop and how do we break it

Write a loop to print all multiples of three from 0 to 100. What causes an infinite loop? How do we break it? Write a program to compute the impedance, Z, and inductance, L, of an electrical coil given voltage, V.

  Summary of the approach or methodology and innovation

What improvement has been achieved, what understanding has been gained from the preliminary study, what can be further improved

  Traditional versus object-oriented design

Compare the object-oriented approach to design to the traditional approach. Give your opinion on whether or not you believe there are certain projects where one design approach might be better that the other. If so, provide an example of one (1) s..

  Choose two different formats for audio and with each record

Choose two different formats for audio and with each record a short passage of speech and a short passage of music. Try to discern any difference in quality. What do you think?

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