Question

1. How would you go about setting the elements of an array to known values after...

1. How would you go about setting the elements of an array to known values after the array has been declared?

2. Suppose we want to write a function that will calculate the sum of the contents of a float-type array and make that value avaliable to the calling function?

a. What would the function prototype look like?

b. What would the function defenition look like?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

According to HomeworkLib guidelines i have to solve first question only.

1.

First of all declare the array as

int array[3];

Now setting the elements of an array to known values.

array[0] = 1;

array[1] = 2;

array[2] = 3;

In this we can do assignment.

Example program:

#include<iostream>

using namespace std;

int main()

{

int array[3]; // array declaration

// Now setting the elements of an array to known values.

array[0] = 1;

array[1] = 2;

array[2] = 3;

for(int i=0;i<3;i++) { // Loop to print the values

cout<<array[i]<<endl; // print array elements

}

return 0;

}

Output:

Add a comment
Know the answer?
Add Answer to:
1. How would you go about setting the elements of an array to known values after...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a...

    a) Declare and instantiate an array named scores of twenty-five elements of type int.   (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...

  • Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in...

    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...

  • I have to a C++ program I need help with. Can you break it into the...

    I have to a C++ program I need help with. Can you break it into the two steps provided below. Suppose MAX_SIZE is a global constant int variable that has been declared and initialized to an appropriate positive value. 1. int maxValue(const array<int, MAX_SIZE>&, int); is the prototype for a function that returns the value of the largest element in the array parameter. The array may be only partially filled. The int parameter indicates how many items are actually in...

  • Try to write two pseudo-codes for the tree-structural global sum, one for a shared-memory setting and...

    Try to write two pseudo-codes for the tree-structural global sum, one for a shared-memory setting and the other for a distributed-memory setting. First consider how this might be done in a shared-memory setting. Then consider how this might be done in a distributed-memory setting. In the shared-memory setting, which variables are shared and which are private? and Suppose we have a program that generates large quantities of random floating point data that it stores in an array. In order to...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    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...

  • Suppose you have a sorted array of positive and negative integers and would like to determine...

    Suppose you have a sorted array of positive and negative integers and would like to determine if there exist some value of x such that both x and -x are in the array. Consider the following three algorithms: Algorithm #1: For each element in the array, do a sequential search to see if its negative is also in the array. Algorithm #2:For each element in the array, do a binary search to see if its negative is also in the...

  • Suppose you have a sorted array of positive and negative integers and would like to determine...

    Suppose you have a sorted array of positive and negative integers and would like to determine if there exist some value of x such that both x and -x are in the array. Consider the following three algorithms: Algorithm #1: For each element in the array, do a sequential search to see if its negative is also in the array. Algorithm #2:For each element in the array, do a binary search to see if its negative is also in the...

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • The purpose of this lab is to manipulate an array of integers. The assignment is to...

    The purpose of this lab is to manipulate an array of integers. The assignment is to write a program that: 1. Declares an array of integers of some maximum size 20. 2. Implements the following functions: ü A function that prompts the user to initialize the array with up to 20 non-negative whole numbers and mark the end of the input with a negative number. The entire array does not need to be initialized. The user may enter only as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT