Write a function named shift_right

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

Write a function named "shift_right" that takes as its arguments the following:

(1) an array of floating point values;
(2) an integer, call it "left", that tells the leftmost cell of the part of the array to be shifted;
(3) an integer, call it "right", that tells the rightmost cell of the part of the array to be shifted;
(4) a positive integer, call it "distance" that tells how many cells to shift by.

The function should make sure that left is less than or equal to right, and that distance is greater than zero. If either of these conditions fails, the function should return the value 1 to indicate an error.

Otherwise it should shift by distance cells the contents of the array cells with subscripts running from left to right . Thus, for example, if the array passed to the function looks like this:

0 1 2 3 4 5 6 7 8 9 10 ....
5.8 | 2.6 | 9.1 | 3.4 | 7.0 | 5.1 | 8.8 | 0.3 | -4.1 | 8.0 | 2.7 | etc.

and if left has the value 3 , right has the value 7 , and distance has the value 2 , then the function should shift the contents of cells 3 , 4 , 5 , 6 , and 7 to the right by 2 cells, so that when the function returns, the array will have been changed so that it looks like this:

0 1 2 3 4 5 6 7 8 9 10 ....
5.8 | 2.6 | 9.1 | ??? | ??? | 3.4 | 7.0 | 5.1 | 8.8 | 0.3 | 2.7 | etc.

The question marks in cells 3 and 4 indicate that we don"t care what numbers are in those cells when the function returns. Note that the contents of cells 8 and 9 have changed, but the contents of cell 10 is unchanged. The function need not take any precautions against the  possibility that the cells will be shifted beyond the end of the array (the calling function should be careful not to let that happen).

Reference no: EM13339001

Questions Cloud

Write a function named concatenate : If the function discovers that the number of cells in the large array is not large enough to hold all the numbers to be copied into it, then the function should return 0 to indicate failure.
Capacity of the trunk sewer : The maximum population that can be served from the new development without exceeding the capacity of the trunk sewer. Diameter, slope, and invert elevations of sewer XB.
Demonstrate the use of the pythagorean theorem : Demonstrate the use of the Pythagorean Theorem in the solution of this problem
Find the magnitude of the final angular velocity of spool : a fisherman is dozing when a fish takes the line and pulls it with a tension F the spool of the reel is at rest intialy, find the magnitude of the final angular velocity of the spool
Write a function named shift_right : The function should make sure that left is less than or equal to right, and that distance is greater than zero. If either of these conditions fails, the function should return the value 1 to indicate an error.
Determine the discharge in the gutter : Determine the discharge in the gutter if the spread is 2.0 m. Estimate the flow intercepted by the curb opening inlet placed in the composite gutter if the inlet length is 1.75m.
What is the projected house value in 20 years : Tabatha's parents bought a new house in Florida for $110,000. After 10 years, the value was $145,000. Using x as the number of years and y as the house value, graph the two points.
Design storage and water surface elevation : Determine the peak outflow rate when the inflow hydrograph is routed through this basin and what is the design storage and water surface elevation at the peak outflow rate.
How long does it take to fill the bucket completely : Elaine went to her outside faucet to fill a 0.0189-m3 bucket with water to wash her car. How long does it take to fill the bucket completely

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Design a simple atm service kiosk

Design a simple ATM service kiosk. This kiosk supports the following options for its menu: 1. Viewing your account balance2. Depositing cash3. Withdrawing cash

  Write a function sum3darray

Write a function sum3DArray. This function will take a three dimensional array of ints and add all the entries in the three dimensional array. Assume columns and rank are two constants already defined.

  Add a copy constructor

Take the code below and add a copy constructor, assignment operator definition and destructor to the class. These functions have already been started for you.

  Write a program that calculates net pay

Write a program that calculates Net Pay. It should do this by calling a function called CalNetPay that calculates and returns Net Pay when given the hours worked and the hourly pay rate. The main function should pass the hours worked and pay rate ..

  Submap that accepts two maps from strings

Write a method called subMap that accepts two maps from strings to strings as its parameters and returns true if every key in the first map is also contained in the second map and maps to the same

  Write a c program that reads in five numbers

Q1. (Bar Chart /Histogram printing) Write a C program that reads in five numbers (each between 1 and 30). For each number read, your program should print a line containing that number of adjacent asterisks. For example, if your program reads the numb..

  The process function will then need

The process function will then need to find the time the person waited by calling the time function and finding the difference between the start and end timestamps. Save this time to an accumulator so that in the end you can find the average wait tim..

  In competitive tournament

In competitive tournaments, it is common for all the players or teams to play in a series of matches in order to determine a single winner of the entire tournament. However, a number of different tournament formats exist. Here, we will concern our..

  A company hired 10 temporary workers

A company hired 10 temporary workers who are paid hourly and you are given a data file that contains the last name of the employees, the number of hours each employee worked in a week, and the hourly pay rate of each employee.

  Create class having constructor to recieve two ints

Create a class (in C++)named Card. The class should have two int data members named face and suit.The class should have a constructor that recieves the two ints and uses them to initialize the data members.

  Winning number combinations from the missouri lottery

The file input.txt contains all of the winning number combinations from the Missouri Lottery since it took its current form on January 3, 1998.  The data is in a file called "input.txt"  All of the data in the file is integer.

  Takes n number of element from user

Write a C program which takes n number of element from user (where, n is specified by user) and stores data in an array. Then, this program displays the largest element of that array.

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