Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that will test five functions described below that use pointers and dynamic memory allocation. Functions: You will write the two functions

Write a C++ program that will test five functions described below that use pointers and dynamic memory allocation.

Functions:

You will write the two functions described below. Then you will call them from the main function, to demonstrate their correctness.

  1. maximum: takes an int array and the array's size as arguments. It should return the maximum value of the array elements. Do not use square brackets ANYWHERE in the function (use pointers instead).

  2. swap: The following function uses reference parameters. Rewrite the function so it uses pointers instead of reference variables. When you test this function from the main program, demonstrate that it changes the values of the variables passed into it.

    1.  int oddSwap (int &x, int &y) { int temp = x; x=y*5; y = temp * 5; return x + y; }

Output:

Test these two functions using the main function as a driver. The driver should pass (constant) test data as arguments to the functions. Select appropriate test data for each function and then call that function using the test data. For each function, you should output three lines: a label indicating which function is being tested, theexpected results (use one string with the values hard coded into it), and the actualresults (use the actual values returned/altered by the function in this line).

testing maximum: Expected maximum: 9 Actual maximum: 9 
testing oddSwap Expected result: 40 a: 25 b: 15 Actual results : 40 a: 25 b: 15

RULES:

  • DO NOT change the names of the functions!

  • DO NOT do any output from the functions (only from main)!

  • DO NOT do any input at all!

    NOTES:

  • This program DOES need to be done in a Linux or Unix environment.

  • It is your responsibility to fully test your functions. They must work for ANY valid input. The main function you submit must have at least one test case for each function. However, you should test the functions over several different test cases to convince yourself that they work.

  • You do not need to use named constants for your test data (or array sizes) in this assignment, but you DO need to follow the rest of the style guidelines including function definition and comments.

  • Your program should release any dynamically allocated memory when it is finished using it.

  • you may want to include a function that displays the values of an int array on one line, separated by spaces, for displaying test arrays and results.

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

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

What is Ethernet? How does it work?

Answered: 1 week ago

Question

Prepare and properly label figures and tables for written reports.

Answered: 1 week ago