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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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