Implement and test the functions

Assignment Help C/C++ Programming
Reference no: EM131307429

Practice with pointers and dynamic memory allocation

Problem:

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

The Functions:

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

1. isReverse: takes two int arrays and the arrays' sizes as arguments (4 arguments). It should return true if the second array is equivalent to the first array in reverse order. Do not use square brackets anywhere in the function, not even the parameter list (use pointers instead).

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

double pizza (int people, int &pizzas, int &slices) { int totalSlices = people*3;
pizzas = totalSlices/8; slices = totalSlices%8;
return pizzas*11.95 + slices*1.75;
}

3. doubleArray: takes an int array and the array's size as arguments. It should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the first half of the new array, and again to the second half of the new array. The function should return a pointer to the new array.

4. subArray: takes an int array, a start index and a length as arguments. It creates a new array that is a copy of the elements from the original array starting at the start index, and has length equal to the length argument. For example, subArray(aa,5,4) would return a new array containing only the elements aa[5], aa[6], aa[7], and aa[8].

You must define subArray as follows:

Add the code for the duplicateArray function from the lecture slides for chapter 9 to your program. Add the code for the subArray function given below to your program. Fill in the blanks with expressions so that the function subArray behaves as described above.

int *subArray (int *array, int start, int length) {
int *result = duplicateArray( , ); return result;
}

DO NOT alter duplicateArray, DO NOT alter subArray as defined above.

Output:

Test these four 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 the following: a label indicating which function is being tested, the test data, the expected results, and the actual results. For the test data and Expected result, you should hard code the output values (use string literals containing the numeric values), for the Actual result, use the actual values returned/altered by the function.

testing isReverse:
test data array 1: 1 2 3 4 5 6 7 8
test data array 2: 8 7 6 5 4 3 2 1
Expected result: true
Actual result: true
test data array 1: 1 2 3 4 5 6 7 8
test data array 3: 8 7 6 6 4 3 2 1
Expected result: false Actual result: false

testing pizza for 25 people: Expected result: 112.80 p: 9 s: 3
Actual results : 112.80 p: 9 s: 3

testing doubleArray:
test data: 1 2 3 4 5 6 7 8 9
Expected result: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
Actual result: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9

testing subArray:
test data: 1 2 3 4 5 6 7 8 9 32767
start: 5 length: 4
Expected result: 6 7 8 9
Actual result: 6 7 8 9
RULES:

- DO NOT change the names of the functions!
- DO NOT do any output from the functions (only from main)!
- DO NOT get any input from the user!! Use constants for test values!!

NOTES:

- This program must be done in a Linux or Unix environment, using a command line compiler like g++. Do not use codeblocks, eclipse, or Xcode to compile.
- Your program must compile and run, otherwise you will receive a score of 0.
- There is NO Test Case 0 for this assignment.

- It is your responsibility to fully test your functions. They must work for ANY valid input. The main function must have at least one test case for each function.
- For pizza, compute the value of the call to pizza BEFORE you output it:

int z = pizza(.......); cout << z << .....;

- 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 comments.

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

- I recommend using a function that displays the values of an int array on one line, separated by spaces, for displaying test arrays and results.

Reference no: EM131307429

Questions Cloud

Significant mean difference between two treatment condition : Briefly explain what is meant when a researcher reports "a significant mean difference between two treatment conditions."
What is a market research manager : What is a Market Research Manager? Identify 1-2 strengths Target has in comparison to Walmart. For each strength, explain your rationale.
Identify the appropriate hypothesis test : Identify the appropriate hypothesis test for each of the given research situations.- Determine whether there is a significant difference in vocabulary skills between 8-year-old and 10-year-old children.
Identify the problem that the technique attempts to solve : Each of the following special statistical techniques was developed to deal with a particular problem. In each case, identify the problem that the technique attempts to solve.
Implement and test the functions : Programming Assignment - Write a C++ program that will implement and test the four functions described below that use pointers and dynamic memory allocation.
Calculate the mean and standard deviation for your scores : If you have access to SPSS or a similar data analysis program, calculate the mean and standard deviation for your scores.
Calculate the pearson correlation for your scores : Make up a set of 10 pairs of scores so that the Pearson correlation between X and Y is approximately r = 0.70.- If you have access to SPSS or a similar data analysis program, calculate the Pearson correlation for your scores.
Describe the risks associated with excess body fat : Describe the risks associated with excess body fat.Discuss at least five factors that influence the obesity epidemic.Assess the various techniques for measuring body fat.Explain the various strategies for weight loss.What are some health problems ass..
Define publication manual of the american : Define Publication Manual of the American, Psychological Association, plagiarism, author note, subjects subsection, participants subsection and procedure subsection.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Cashregister class that can be used with the retailitem clas

Write a CashRegister class that can be used with the RetailItem class that you wrote in Part 1. The CashRegister class should simulate the sale of a retail item. It should have a constructor that accepts a RetailItem object as an argument.

  How do cin and cout relate to ostream and istream

How are input and output accomplished in C++? How do cin and cout relate to ostream and istream? Write a program that asks the user to enter the name of a file. The program should display the number of characters in the file.

  Explain the use and benefits of object-oriented programming

Explain the use and benefits of object-oriented programming and event-driven programming

  Pixels down the right of the window

The blue and red values of the pixels across the top of the window are all the same, where the blue is at its maximum value while red is at its minimum value. The green values of the pixels down the right of the window are all the same, where gree..

  Define the term root-to-leaf path in detail

My goal, given a binary tree and a sum, is to return true if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. Returning false if no such path can be found.

  Create an app that will play an audio file backwards

Your group has been tasked with creating an app that will play an audio file backwards - Because this app is likely to be used on a mobile device, your group figures that this algorithm should use as little memory and space as possible.

  Write a c++ program to calculate the sum

The list of all natural numbers less than 10 that are multiples of 3 or 5 is 3,5,6,9. The sum of these multiples is 23. Write a C++ program to calculate the sum of all such multiples less than 1,000.

  You are to create a program

You are to create a program that will input a group of floating point values, storing them as double values in an array. This array will then be sent to three functions.

  Display a year-by-year depreciation schedule

Create GUI screen interface that accepts input and shows output and resize the GUI screen & the list box to best fit the output displayed

  Array of integers declared-initialized to number of tickets

Array of integers named parkingTickets has been declared and initialized to number of parking tickets given out by city police each day as beginning of current year.

  Write a program to manipulate strings using pointers

Write a program to manipulate strings using pointers. The program will start out by displaying a menu to ask user what to do as shown below

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