Homework Help Question & Answers

please answer this c++ question if you know all the questions not just some of them ... thanks Problem 4: Rewrite the f...

please answer this c++ question if you know all the questions not just some of them ... thanks

Problem 4: Rewrite the following function so that it can operate on arrays of any data type, not just integers. You may assum

Problem 4: Rewrite the following function so that it can operate on arrays of any data type, not just integers. You may assume that all operations and comparisons are defined for all data types that we would pass into this function: int cloneArrayReturnMax(int* arr1, int size1, int* arr2, int size2) { size1 int end size2 if (end > size2) end for (int i = 0; i = 0; i--) if (max
0 0
Next > < Previous
ReportAnswer #1

We can use templates in C++ if we want to use for many data types.

1. Replace the line

int cloneArrayReturnMax(int* arr1, int size1, int* arr2, int size2) {

with

template <typename T>
T cloneArrayReturnMax(T* arr1, int size1, T* arr2, int size2) {

2. Replace the line

int max = arr1[ size1 - 1 ]

with

T max = arr1[ size1 - 1 ]

Know the answer?
Add Answer of:
please answer this c++ question if you know all the questions not just some of them ... thanks Problem 4: Rewrite the f...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I keep on getting 1.#INF in C++ program .. whats that all about

    x.øi5his might be a long message. So brace yourselves .. Sorry The complete question is posted here >> << http://sleepy.cs.surrey.sfu.ca/cmpt/courses/cmpt128/cmpt-128-assignments/assignment-3-statisticsI am almost done with the program .. it compiles and runs.But in Part 5 .. where we have to calculate the "t value" .. my denominator always comes as zero.I dont know why :SCan you help me out ..here is the code for my function .. (read the bolded red part ... thats where i m getting the denominator as...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • Please finish all the questions,Thanks Following is Appendix assume the definition of Java class Heap given in the App...

    Please finish all the questions,Thanks Following is Appendix assume the definition of Java class Heap given in the Appendix For this question, a. (2 marks Consider the following heap 30 12 20 19 6 10 18 Given the array representation of a heap discussed in class, what is the array that corre sponds to this heap? b. (5 marks) Successively insert into the heap of part (a.) 22, 35 and 11, in that order. Use the standard heap insertion algorithm....

  • C programing question. Can someone answer this please. Please comment in detail Thanks

    //Create a program that will ask the user to enter two 3X3 Matrices//Use Arrays at every stage of your work//Request the user to enter all values one line, each row separated by commas//Choose how you want to word the request to the user (bound your request)//request only float datatype from the user for your matrices, ignore the int datatype//for each set of input, you program would ask the user what operation h/shee wants to do.//Perform only one operation at a...

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

  • C++ program

    I need help getting a c++ program. Details for this program is listed below.Objective: The code in this walk through will provide you with a program that illustrates the core concepts of creating classes, object, properties, methods and usingthose items in a program.In this walkthrough, I'll build a simple class that will be used to represent a box. At each step in the process I'll discuss the design options and explain thechoices I have made.The first step in the process...

  • C++ using c-style string

    x.øi5Write a complete C++ program to process league statistics for the Western Collegiate Hockey Association. ( by using user-defined c-style string, no singlecharacter identifiers, no global variables)• maximum of 12 teams per season.use an array ofstructure variables to store the collection of individual team statistics.• read the team statistics from a text file whose file name is entered at the command line.if no file name isspecified then prompt the user for the file name.• Each line in the file contains...

  • I only need help with question 5! Thank you! Question 4 4 pts Consider this variant...

    I only need help with question 5! Thank you! Question 4 4 pts Consider this variant of the linear search algorithm which attempts to speed up the search by reducing the number of iterations of the for loop by approximately one-half. During each pass of the loop, the algorithm performs two comparisons rather than one comparison as in linear Search(). The two comparisons compare the elements at indices i and pList size() - 1-i to pKey for equality. If a...

  • C program help - bitmask operations

    I am not looking for someone to write the whole program!Just need help with getting set input from the user represented as unsigned int.Thanks!I need help understanding how to accept a set of values from a user and treat them as bit positions in an unsigned integer.I do not think Iwill need help getting the functions to work, I know I need to make use of the bit operators.I have tried to get this to work and simplified it to...

  • C++ Questions Please answer quickly! 1. Please use this info to answer next questions -> 2. Please give reasoning 4. Explain why, I think it is 4 but i also think it might be 0. You need to wri...

    C++ Questions Please answer quickly! 1. Please use this info to answer next questions -> 2. Please give reasoning 4. Explain why, I think it is 4 but i also think it might be 0. You need to write a program that uses the speed of light in a vacuum (299792458 meters per second) Realizing that this is a very large value, you run this code to see how large a value you can store as an int, a long...

Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
Share Your Knowledge

Post an Article
Post an Answer
Post a Question with Answer

Self-promotion: Authors have the chance of a link back to their own personal blogs or social media profile pages.