Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have 2 part homework about pointer, I'm a beginner about pointer PART 1: 1. Write a function, equal(), that returns true if the range

I have 2 part homework about pointer, I'm a beginner about pointer

PART 1:

1. Write a function, equal(), that returns true if the range [first1, last1) is equal to the range [first2, last2), and false otherwise

bool equal(const int* first1, const int* last1, const int* first2, const int* last2); // Example, assuming `data1` and `data2` are int arrays // and we want to know if the first 5 elements compare equal: bool result = equal(data1, data1 + 5, data2, data2 + 5);

2. Write a function, copy(), that copies the elements in the range, defined by [first, last) to another range beginning at d_first.

void copy(const int* first, const int* last, int* d_first); // Example: // copy the first five elements from data1 to data2 copy(data1, data1 + 5, data2);

3. Write a function, print(), that prints the elements in the range defined by [first, last) to the standard output stream. The elements should be separated by commas with curly braces surrounding them, terminated by a newline, e.g., "{0,1,2,3,4} "

void print(const int* first, const int* last); // Example: print(data, data + 5); // prints {0,1,2,3,4} " print(data + 1, data + 3); // prints {1,2} "

PART 2: write function main()

1. Generate a random number, n, in the range [10..100].

2. Compare the two arrays for equality. They should not be equal!

3. Copy the first 5 elements of data2 to the first 5 elements of data1, and Compare the two arrays for equality. They should not be equal!

4. Compare the first ten elements of data1 and data2 for equality. These ranges should be equal.

***Anyone can help me write those functions, I don't understand how to write it. I have more homework like that, I need to learn how to use and how to write.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions