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

  Simmac language programs

Write three programs in the machine language of the SIMMAC that will total the numbers stored in 20 different locations and place the result in a single location.

  Write a function that accepts an array a as input and

write a function that accepts an array a as input and searches the contents of the array for elements in three

  Write a program which manipulates fractions

Write a program which manipulates fractions. It should get two fractions from the user by inputing two numerators and two denumerators (integers) from 0 to 999 and then have the user select an operation from addition, subtraction, multiplication, ..

  Create structure chart-flowchart to store taxpayer-s name

Create the structure chart, also a flowchart and pseudocode, for following problem. Suppose that each input record contains taxpayer's name.

  C++ program for bus reservation system

C++ program for bus reservation System that show the number of seat availability , arrival & depart time , bus number etc

  Write function is pseudocode to calculate area of triangle

Write down the function is pseudocode called calculate area which calculates the area of a triangle. Algorithm for area computation is this: area=1/2*base*height.

  Write a program sequence that places the value in address

Write a program sequence that places the value in Address $1000 into Accumulator A and places the value in Address $1001 in Accumulator B. Then, add these values together and store the result in Location $1002.

  Program that creates a customised children''s story

Imagine you are writing a computer program that creates a customised children's story using names provided by the user of the program.

  Program read data from input file and select specified items

Program should be able to read data from input file and select the specified items. Write data for school-age males to file male.out and data for school-age females to female.out.

  A brief descriptionof the given project

A brief description, this is basically for my school final year project. So it need not to be very professional. I just need the outcome to be something like the ppt slides will do.

  Recursive double function

each of these returns the list consisting of each element of list y in a list has been replaced by two copies of the elements and

  Write a script named lab6s2 that writes the current time

Write a script named lab6s2 that writes the current time and date, lists logged-in users, and prints the system's uptime to a log file. The time should be printed with the format of "03:55 am" as opposed to military time.

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