1.Explain how arrays allow you to easily work with multiple values.
2 Explain how for loops can be used to work effectively with elements in an array.
3 Provide an example of using a for loop without an array.
4 What is the main difference between standard array and a dynamic array?
5 How are elements added to a vector in C++?
6 How can you remove an element from a vector in C++?
7 Why pass a vector by reference?
Answer 1: Array is single variable where we can store the multiple values. using that single variable we can access all the elements in the array
Answer 2: using loop we can access the values in the array. we can iterate the elements in array using the loop
Answer 3: adding sum of 1st 10 numbers. here we can use the loop to achieve this
int sum=0;
for(int i=0;i<10;i++)
sum=sum+i;
Answer 4: in standard array we can create the size with constant. dynamic array we can create the size using variable using functions like malloc,new,callco
Answer 5: in vector we have push_back() function to add elements to the vector
Answer 6: we have erase function to delete the element
Answer 7:if you want the changes to effect to the actual parameters than we will pass by reference
Note : If you like my answer please rate and help me it is very Imp for me
1.Explain how arrays allow you to easily work with multiple values. 2 Explain how for loops...
Arrays in Functions
2. Arrays in Functions You can use both the array index variables and the entire array itself as arguments to functions. The following program updates the elements of the array grades, one-by-one. Thus, we have used a call-by-reference-ish mechanism to update the values (although no & was used). Note that there is a major difference between the grade in the function call and the one in the function definition. In the statement get_grade (grades[i]); "grades" is the...
1. Typically, arrays are passed by reference in programming
languages since they can be arbitrarily long and copying each
element may take time and space. How are arrays passed to functions
in C++? If by reference, is there a way to pass them by value? If
so, how? Show coded examples and output.
2. Can separate blocks be specified in C++, and if so, how is
variable scoping handled? Show coded examples and output. For
example:
3. Can the goto...
Program Overview This brief exercise is designed for you to consider how reference variables behave when you are passing them as arguments by-value. Instructions Name your class References.java. 1. Implement the following methods. 1.1 Method name: readStudentNames Purpose: This method accepts an array of strings as a parameter. It loops through the array and asks the user to input names. It populates the array of strings with the names. Parameters: an array of Strings, stringArray Return type: void In the...
please explain. Thanks in advance
Dynamic Arrays Revisited (40 points) A dynamically re-sizing array is an array that is initially allocated at size 1. and every time you need to insert past the end of the array you double its size and copy elements from the old array to the new array. In class, we showed that n inserts into a dynamic array can be accomplished in O(n) using an accounting argument where we pre-paid $3 for each insert, thus...
Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...
When using a content management system (CMS), how can you allow multiple individuals to work on a website at the same time without worrying they will override or duplicate work? a.A CMS does not allow multiple contributors to use it at the same time. b.A CMS is just another name for a drag-and-drop procedure that anyone can perform without any restrictions. c.A CMS allows you to grant access to capabilities such as adding or removing content based on a contributor's...
please explain this Java problem with source code if possible
Project: Strictly identical arrays Problem Deseription: Two arrays are strictly identical if their correspondimg elements are equal Write a program with class name StrictlyIdentical that prompts the user to enter two lists ed integers of size 5 and displays whether the two are strictly identical. Usc following method header to pass two arrays and retum a Boolcan public static boolean cualsint[] array 1, int[] array2) Method will return true if...
PART 1 Modify the class ArrayList given in Exercise 1 by using expandable arrays. That is, if the list is full when an item is being added to this list, the elements will be moved to a larger array. The new array should have twice the size of the original array. Using the new class ArrayList, write a program to store 1,000 random numbers, each in the interval [0, 500]. The initial size of the array in the class should...
l ask Write a C++ program that accomplishes the following tasks 1. Write a function that finds the average of current element and the next element in given array named as "elements" and stores the new found averages into another array called "averageArray". Note: For the last element you can just divide the value of last element by 2 Write a function that takes both the given array and average array you just created along with a variable "productofArrays" using...