Implement and test the functions

Assignment Help Programming Languages
Reference no: EM131245860

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.

Logistics:

Name your file assign3_xxxxx.cpp where xxxxx is your TX State NetID (your txstate.edu email id). The file name should look something like this: assign3_js236.cpp

There are two steps to the turn-in process:

1. Submit an electronic copy using the Assignments tool on the TRACS website for this class.

2. Submit a printout of the source file at the beginning of class, the day the assignment is due. Please print your name on top of the front page, and staple if there is more than one page.

See the assignment turn-in policy on the course website (cs.txstate.edu/~js236/cs2308) for more details.

Reference no: EM131245860

Questions Cloud

Why is a postproject review valuable to future projects : Consider why it would be important to withhold a significant amount for the final payment. If you are familiar with a situation where a contractor had to spend extra to fix or finish items to complete a job, describe why they might need a financia..
Why does your hr function exist : Why does your HR function exist? What do you want for your customers and how can HR provide that? What image of your function do you want to convey internally and externally?
How a postproject review would meet that standard : Describe a procurement task. Rate it for the amount of uncertainty of the scope, cost, schedule, and risk. Choose a contract type and explain why that contract type would be an appropriate choice for that set of uncertainties.
Does this comparison hold up throughout the story : Oroonoko is sometimes referred to as a Christ figure with his dismemberment resembling the crucifixion. Does this comparison hold up throughout the story? Explore this topic using proof from the text to back up your argument.
Implement and test the functions : Programming Assignment - implement and test the four functions described below that use pointers and dynamic memory allocation and Rewrite the function so it uses pointers instead of reference parameters. When you test this function from the main pr..
Describe the steps of the masque in shakespearian drama : Use events, themes, and important secondary characters to compare the respective psychological journeys that Gilgamesh and Prospero take. Be sure to include a discussion of the outcomes of each character's journey and what that outcome implies fo..
Describe and interpret d&b financial reports : Describe and interpret D&B financial reports using definitions from the D&B website.
Discuss the consequences of your gender on current status : Identify your gender and discuss the consequences of your gender on current and potential occupational status, wealth, and income.
How would you describe the overall tone of their work : How does Langston Hughes treat the idea of racism in America in his poetry? How does Wright treat the idea of racism in his short story? How would you describe the overall tone of their work? Do you see hope, despair, anger, or something else? Wha..

Reviews

Write a Review

Programming Languages Questions & Answers

  Function to convert a decimal input into roman numerals

Write a function that converts a decimal input into Roman Numerals. Your function will take in a number and output a string.

  How many number of users currently logged into the system

How do you know how many number of users currently logged into the system? (Not considering if any user is logged more than one time

  Write logic for application for company which wants reports

Write logic for the application for company which wants report containing breakdown of payroll by department. Input includes each employee?s last name, first name, department number.

  Demonstrate that you can read and understand code

What will the code output when run - What are individualScores, bonusScore, baseScore, and teamScore? What do you think the difference is between the keywords let and var?

  Design pseudocode to enter names of two primary colors

Design a pseudocode program that prompts the user to enter the names of two primary colors to mix. If the user enters anything other than "red", "blue", or "yellow".

  Write a vhdl code for soda vending machine

Write a VHDL code that implements the above soda machine. You have to turn in the following: A state diagram showing the implementation of your design. Clearly show all the states and the conditions on which transitions occur.

  Write the function array_dup

Write the function array_dup(n, obj) that returns an array containing n copies of obj - Write a function count_occurrences(a, obj) that counts the number of items in array a that are equal to obj.

  Create database tables in sql

List the SQL commands you will use to create your database tables

  Template that computes and displays the absolute value

Create a program that uses this function template, passing in two arguments of type int, float, and double variable.

  Create a document that displays a sports related image

Create a document (with any required style sheets and java .js files) that displays a sports related image of your choice and three buttons. The buttons should be labeled simply 1,2, and 3. When pressed, each button should change the content of th..

  Perform some analysis of the age and weight relationships

In this project you will combine the use of arrays and objects to perform some analysis of the age and weight relationships among a group of people. You have been contracted to write a program into which data about people, including their ages and..

  Program to display only unique values which user entered

Program to display only the unique values which the user entered. Give for the "worst case" in which all 20 numbers are different. use smallest possible array to solve this problem.

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