Implement functions that perform replacing elements

Assignment Help Programming Languages
Reference no: EM132240464

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

Questions Cloud

Discuss about the scientific study of the development : After consulting one of the articles given above, describe how the scientific study of the development of these particular individuals can further our knowledge
What the project manager can do to understand : Resource constraints can be a huge burden on a project, sometimes causing project issues and/or project failures.
Calculate the current price : Calculate the current price of the following $1000 FV bonds with 7 years to maturity: Market yield 6.5%, semi-annual coupon payments
What factors likely contribute to common : What factors likely contribute to common, erroneous beliefs about affirmative action, even among intended beneficiaries.
Implement functions that perform replacing elements : Perform operations on ranges such as removing elements within the range, replacing elements within the range, searching for elements, copying one range
What are the five steps of the scientific method : What are the five steps of the scientific method? Describe the difference between inductive and deductive reasoning,andgive an example of each.
High-low goals instead of using single number goals : What are advantages and disadvantages of using high-low goals instead of using single number goals?
Prepare the adjusting entries at july : Prepare the adjusting entries at July 31 assuming that adjusting entries are made monthly. Use additional accounts as needed
Reach for a result or action from the company : Is there a better way for stakeholders to reach for a result or action from the company?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a program that demonstrates hoe the classescollaborate

Write a program that demonstrates hoe the classescollaborate. To issue a parking ticket (generate a ParkingTicket object) if the car's time has expired.

  Create a program to store assignment grades for student

The elementary school for which you are doing development work has asked you to create a program to store assignment grades for one student.

  Numbers that can be calculated and have meaningful results

Numbers that can be calculated and have meaningful results

  Modify the startup code so that the program calls a function

Modify the startup code so that the program calls a function that reads the player's data from the text file into the list of member objects.

  Write down a program which asks the user for an angle

write a program that asks the user for an angle entered in radians. the program should then display the sine cosine and

  Insert a text box after the paragraph and type your name

Create a two column table with a minimum of seven rows. You may add additional rows as needed to hold additional hyperlinks that you feel will be useful to you as you progress through your degree.

  Write script in fedora to automate complex system task

Write a script in fedora 10 that will automate a complex system task. The task I have chose is one that will determine the processes that are consuming system resources.

  Create modular program to enter monthly costs

Create modular program which ask user to enter monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance.

  Advantages of contemporary languages allow kinds of comments

Many contemporary languages allow two kinds of comments, one in which delimiters are used on both ends (for multiple line comments), and one in which a delimiter marks only the beginning of the comment.

  Create a class structure flow chartfor yourprogram

Create a class structure,algorithmsand flow chartfor yourprogram, and then do several iterations of tests. You'll turn that document in with the program.

  Write a program to evaluate the given arithmetic statement

Write a program to evaluate the arithmetic statement. X=A-B+C*(D*E-F)/G+H*k. Using a general register computer with one address instruction.

  Program to calculate cost of purchase-requests from user

Program calculates cost of purchase, requests another item selection from user, and so on. User enters 0 from item menu to quit.

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