Write a program to use function

Assignment Help Programming Languages
Reference no: EM131145262

First, write a function deleteFromArray which receives three arguments in its parameters: an array of integers; an offset indicating a position in the array; and an integer containing the size of the array.

The function then deletes the value at the position indicated by the offset (by shifting all values to the right of the deleted value one offset to the left), and finally returns the new size of the array.

Next, write a program to use this function. Particularly, the program first sets, declares, and initializes an array as follows: int myValues[10] = {0,1,1,2,3,5,8,13,21,34}; int arraySize = 10; Next, the program repeatedly displays the array to the user, asking whether they wish for a something to be deleted. If the user responds in affirmative, the program asks them for the offset in the array of the value to be deleted.

It then calls your deleteFromArray function to carry out the actual deletion, receiving the new size of the array from the function. If the user asks to delete from an offset that goes beyond the end of the array, an appropriate message is displayed stating that the deletion cannot be carried out.

The program ends the first time that the user chooses not to delete a value from the array. Your main function may also call other functions to carry out some of its work. Here is an example execution of the required program (input typed by the user is in green).

The formatting of your program's output should match this example. Array: {0,1,1,2,3,5,8,13,21,34} Want to delete something? (y/n) y Offset to delete? 3 Array: {0,1,1,3,5,8,13,21,34} Want to delete something? (y/n) y Offset to delete? 7 Array: {0,1,1,3,5,8,13,34} Want to delete something? (y/n) y Offset to delete? 9 Sorry, can't delete that.

Want to delete something? (y/n) n Goodbye!

Carefully note the following in the example output above: The user first asks for deletion at offset 3, which refers to the value 2 in the array. Every value to the right of the 2 in the original array must be consequently copied one position to the left.

For example, value 8 was at offset 6 before the first deletion (we deleted value 2, remember?), but appears at offset 5 (one left of its previous location) after the deletion. Also note that 10 elements were displayed before the first deletion, but 9 elements are displayed after it.

To get this right, you need to keep track of the number of elements in the array, as well as the array itself. Also note that when the user tries to delete the item at offset 9 after the two deletions, when there were only 8 valid elements remaining in the array, the program declines to carry out the deletion.

Reference no: EM131145262

Questions Cloud

Did the author provide references and supporting facts : Did the author provide references and supporting facts in this article, or were you expected to just accept the findings without support? When reading about science, how important do you feel sources and references are in accepting the findings tha..
Zamora has no depreciable assets : Prepare the operating activities section of the statement of cash flows using the indirect method.
What is the plaintext m : In a public-key system using RSA, you intercept the ciphertext C equal to 128, sent to a user whose public key is e 7, n 527. What is the plaintext M?
Focus on rigorous candidate assessment : Research an organization--searchable through the internet--and make an assessment of all ten of its key factors involved in successful talent planning and development listed below. Development must be forward looking, Focus on rigorous candidate asse..
Write a program to use function : The program ends the first time that the user chooses not to delete a value from the array. Your main function may also call other functions to carry out some of its work - Here is an example execution of the required program (input typed by the us..
Describe physical processes influencing climate and weather : Apply concepts in physical sciences to evaluate current trends and issues in the modern world. Describe the physical processes influencing climate and weather. Use technology and information resources to research issues in physical sciences.
Report at management meeting of ethical trading group : FNSACC501: Provide financial and business performance information Assessment. You are now to present a snapshot of your written report at the management meeting of Ethical Trading Group Pty Ltd using PowerPoint
During diversity management session : During a diversity management session, a manager suggests that stereotypes are a necessary part of working with others. “I have an assumption about what is in the other person’s head, and stereotypes help me do that,” she explains.
Changing nature of jobs : Write the answers of the question given below related to the topic "Changing Nature of Jobs".

Reviews

Write a Review

Programming Languages Questions & Answers

  Display the total price of the cup of coffee

Create a UseTVShow.java file that prompts the user to input up to 5 TV shows and stores the data in an array of objects first, then displays them as a list.

  Creating method to union the interface for adt bag

Add method union to  interface BagInterface for ADT bag which returns as new bag the union of bag receiving call to method and bag which is the method's one argument.

  Implement method to create thousand random integers

Implement a method named posNeg which creates 1000 random integers. Range of numbers must be from -5 to +5 inclusive.

  Implement an android application with the requirements

Design and implement an Android application with the requirements - Just one database that contains all data for the list, list items, widgets, text fields and activities mentioned in the above requirements.

  Write a program to assign the integer values

Write a program to assign the integer values 1 through 25 to a 25-element integer array. Then, print the array as five separate lines, each containing five elements separated by commas

  Prepare program that loads memory value of integer variable

Write a program that loads from memory the value of integer variable SCORE. Next set character variable GRADE to 'A', 'B', 'C', 'D', or 'F' depending on value SCORE.

  Picbasic program

Comment the function associated with every line of the following PICBASIC program

  User defined function to calculate average of three scores

A user defined function that will calculate and display the average of the 3 scores that remain after dropping the highest and lowest scores the performer received.

  Create math sorting game using visual basic studio

using visual basic studio 2010, Create math sorting game. Random number between 1 and 99 will be generated and displayed to the user.

  Create a "exit" button that exits the program

Develop a GUI program that will determine the pay for several employees.

  Enhance the web page the following elements

Ensure required fields First name, Last name are not blank.

  Give a pseudo-code description

Give a pseudo-code description of the o(n)- time algorithm for computing the power function P(x,n). Also draw the recursion trace of this algorithm for computation of p(2,5)

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