Question

In: Computer Science

C++ split_list(Lst,N): split lst into two parts with the first part having N elements, and return...

C++
split_list(Lst,N): split lst into two parts with the first part having N elements, and return a list that contains these two parts.

yes it is an array

Solutions

Expert Solution

In this C++ program, we create an integer array Lst of 10 elements from 1 to 10. Then an integer N for the split size.

Then we call the Split_lst() function passing Lst and N as parameters.

In the function, we create a static array arr and using a for loop till N elements, copy the elements from Lst to arr.

Note: arr is a static array so that it can be passed between functions.

CODE:

#include <iostream>

using namespace std;

int* Split_list(int Lst[], int N)
{
static int arr[50]; //create static int array
for(int i=0; i<N; i++)
arr[i] = Lst[i]; //copy the split array
  
return arr; //return the resultant array
}

int main()
{   
int Lst[10] = {1,2,3,4,5,6,7,8,9,10}; //initial array
int N = 4; //split size

cout<<"Original array: \n";
for(int i=0; i<10; i++)
cout<<Lst[i]<<" "; //display original

int* newLst = Split_list(Lst,N); //function call

cout<<"\n\nSplit array: \n";
for(int i=0; i<N; i++)
cout<<newLst[i]<<" "; //display split array
  
return 0;
}

OUTPUT:


Related Solutions

one homework question, split into two parts. part 1: A machine can be purchased for $253,000...
one homework question, split into two parts. part 1: A machine can be purchased for $253,000 and used for five years, yielding the following net incomes. In projecting net incomes, double-declining depreciation is applied using a five-year life and a zero salvage value. Year 1 Year 2 Year 3 Year 4 Year 5 Net income $ 17,000 $ 32,000 $ 78,000 $ 46,500 $ 129,000 Compute the machine’s payback period (ignore taxes). (Round payback period answer to 3 decimal places.)...
There are two parts to this question first part: Consider a production facility, where the present...
There are two parts to this question first part: Consider a production facility, where the present value of expected future cash inflows from production, V = 80, may fluctuate in line with the random fluctuation in demand (u = 1.4, d = 0.71 per period and the risk-free rate, r = 5%). Suppose management has the option in two years, to contract to half the scale and half the value of the project (c = 50%), and recover $40m (Rc...
This problem is about the java programming and contain two parts First part: a word that...
This problem is about the java programming and contain two parts First part: a word that reads the same forward and backward is called a palindrome, e.g., "mom", "dad", "racecar", "madam", and "Radar" (case-insensitive). Write a program called TestPalindrome, that asks the user for a word and prints whether the word is a palindrome or not. Hint: for a string called inStr, you can use inStr. toLowerCase() which returns a new string which is all in lower case letters. Use...
Split 69 into 3 parts in an arithmetic progression (A.P) such that the product of the two smaller parts is 483?
Split 69 into 3 parts in an arithmetic progression (A.P) such that the product of the two smaller parts is 483?
Please note that this assignment consists of two separate parts. The first part gives the cash...
Please note that this assignment consists of two separate parts. The first part gives the cash flows for two mutually exclusive projects and is not related to the second part. The second part is a capital budgeting scenario. Part 1 Please calculate the payback period, IRR, MIRR, NPV, and PI for the following two mutually exclusive projects. The required rate of return is 15% and the target payback is 4 years. Explain which project is preferable under each of the...
Write a C function to add the elements of two same-sized integer arrays and return ptr...
Write a C function to add the elements of two same-sized integer arrays and return ptr to a third array. int *addTwoArrays(int *a1, int *b1, int size); The function should follow the following rules: If the sum for any element is negative, make it zero. If a1 and b1 point to the same array, it returns a NULL If any input array is NULL, it returns a NULL. Please call this function with the following arrays and print the sums...
IN C++ ONLY... please do both parts of this task ..1 part- Menu driven program First...
IN C++ ONLY... please do both parts of this task ..1 part- Menu driven program First load an array(lists) with the values 3, 4, 84, 5, 2, 47, and 7 in this order by using a function. Then sort the array(list) Use a function to display the menu. Create a program with a menu, with choices 1 for factorial (single value, which everyone will use 20!), 2 for median value , 3 for average, 4 for maximum, 5 for minimum,...
This question has two parts. Please answer both, thank you! Part A.) On the first day...
This question has two parts. Please answer both, thank you! Part A.) On the first day of the fiscal year, a company issues a $8,200,000, 9%, 9-year bond that pays semiannual interest of $369,000 ($8,200,000 × 9% × ½), receiving cash of $6,868,206. Journalize the first interest payment and the amortization of the related bond discount. Round to the nearest dollar. If an amount box does not require an entry, leave it blank. Interest Expense Discount on Bonds Payable Cash...
Question 1 The binomial formula has two parts. The first part of the binomial formula calculates...
Question 1 The binomial formula has two parts. The first part of the binomial formula calculates the number of combinations of X successes. The second part of the binomial formula calculates the probability associated with the combination of success and failures. If N=4 and X=2, and p = .5, what is that probability from the second part of the formula? Group of answer choices .0625 .5 .3750 .1563 Question 2 Normal Distribution Problem. The birth weight is of newborn babies...
Write a C++ function which will search for TWO elements. The two elements must be right...
Write a C++ function which will search for TWO elements. The two elements must be right next to each other, contiguously. The prototype of the function should be: bool search_adjacent_elements(int const *x, size_t n, int target1, target2); It will return true if target1 and target2 exist in the array x somewhere, with target1 immediately to the left of target2. For example: int x[] = { 3, 5, 10, 14, 19, 25, 45, 60 }; cout << search_adjacent_elements(x, sizeof x /...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT