Explanation of Solution
Copying one array to another array:
An array is the variable which stores the same types of data. To copy the data from one array to another, first initialize the two arrays with their respective element sizes.
- Consider one of the arrays is filled with a set of values and the filled array is required to be copied to another array.
- To copy the content of one array to another, assign each element of the array to another by using the equal to (“=”) operator.
- Each element of the array can be referred to by using index numbers of the array.
Example:
Consider the following code which performs the copying of array elements.
// Header file section
#include<iostream>
using namespace std;
// Main function definition
int main()
{
// Declaring the arrays
int list1[];
int list2[];
//Declare the variables
int n, i;
/* Prompt the user to enter the number of elements
need to be copied */
cout << "Enter the number of elements need to be copied" << endl;
// Read “n” value from the user
cin >> n;
/* Execute the for loop to include the elements in the list1[]*/...
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
- (Statistics) Write a program that includes two functions named calcavg() and variance(). The calcavg() function should calculate and return the average of values stored in an array named testvals. The array should be declared in main() and include the values 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, and 73. The variance() function should calculate and return the variance of the data. The variance is obtained by subtracting the average from each value in testvals, squaring the values obtained, adding them, and dividing by the number of elements in testvals. The values returned from calcavg() and variance() should be displayed by using cout statements in main().arrow_forward(Electrical eng.) Write a program that specifies three one-dimensional arrays named current, resistance, and volts. Each array should be capable of holding 10 elements. Using a for loop, input values for the current and resistance arrays. The entries in the volts array should be the product of the corresponding values in the current and resistance arrays (sovolts[i]=current[i]resistance[i]). After all the data has been entered, display the following output, with the appropriate value under each column heading: CurrentResistance Voltsarrow_forward(Electrical eng.) Write a program that declares three one-dimensional arrays named volts, current, and resistance. Each array should be declared in main() and be capable of holding 10 double-precision numbers. The numbers to store in current are 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, and 3.98. The numbers to store in resistance are 4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, and 4.8. Your program should pass these three arrays to a function named calc_volts(), which should calculate elements in the volts array as the product of the corresponding elements in the current and resistance arrays (for example ,volts[1]=current[1]resistance[1]). After calc_volts() has passed values to the volts array, the values in the array should be displayed from inside main().arrow_forward
- Lab 5 : Arrays Please the attachment which is been given to Develop a C code that asks for a class size (maximum can be 20). Then it asks the user to enter all the marks and saves them in an array. Then it generates a report about the class status that includes the following 1- Class average 2- Best mark and worst mark 3- number of failed students 4- Number of students with a grade of A and higher (80 or above) 5- number of students who got a mark above averagearrow_forwardFYI: Please write the code in Pseudocode (no programming language please) 1. Write pseudocode to load a single array with data. Then search that array for a match. Here are the specifics. You do NOT have to write the entire program. Load the array with data from a file named customerNumbers Ask the user to enter their customer number Search the array for the customer number If you find a match output FOUND If there is no match output NOT FOUNDarrow_forwardComplete in Pseudocode Declare an array called ‘numbers’ that will contain the following values: 16, 5, 3, 24.• Ask a user whether they would like to search for a particular value. If their answer is “Yes”, the application should allow them to enter a search value and the array must be searched for that value.• Display a message indicating if the value was found in the array or not.arrow_forward
- C#/Csharp program Tyarrow_forwardPython: Numpy def shopping_spree(spending_limit, store_nums):"""QUESTION 1- You and your friends decide to go on a shopping spree! You each have a spendinglimit listed in a 1D array called spending_limit.- You each know you will be going to a specific number of stores, store_nums, which is alsoa 1D array.- Sales tax is 7% at every store.- Calculate the average amount that you and each of your friends can spend at astore- Excluding sales tax from this calculation.- Return an array of how much you can each spend at a store, excluding sales tax.- THIS MUST BE DONE IN ONE LINEArgs:spending_limit (np.array)store_nums (np.array)Returns:np.array>> store_nums = np.array([15, 12, 8, 3, 4, 3, 6, 5, 7, 4])spending_limit = np.array([200, 500, 330, 120, 85, 60, 220, 190, 490, 300])>> print(shopping_spree(spending_limit, store_nums))[12.46105919 38.94080997 38.55140187 37.38317757 19.85981308 18.6915887934.26791277 35.51401869 65.42056075 70.09345794]"""# store_nums = np.array([15, 12,…arrow_forwardFYI: Please write the code in Pseudocode (no programming language please) 1. Write a pseudocode that outputs the contents of parallel arrays. You do NOT have to write the entire program. The first array will hold phone numbers The second array will hold company names You do NOT need to load the arrays. Your code can assume they are already loaded with data. arrays are named phone[] and company[]arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr