105k views
3 votes
Perform the following tasks for an array called fractions:

Declare a constant Array_Size that initialized to 10

Declare an array with Array_Size element of type double and initialize the elements to 0

Assign the value 45 to element 5, value 33.56 to element 6, value of 75.9 to element 5. Then sum all the elements

1 Answer

2 votes

Final answer:

A constant Array_Size is defined as 10, and an array of type double is declared and initialized with Array_Size elements. Values are then assigned to specific elements, and a sum of all elements is calculated using a loop.

Step-by-step explanation:

To perform the tasks for an array called fractions, you would start by declaring a constant Array_Size which is initialized to 10. Then, you declare an array with Array_Size elements of type double and initialize all the elements to 0.

Here's how you could write the code in C++:

const int Array_Size = 10;
double fractions[Array_Size] = {};

After declaring the array, you can assign values to the specified elements.

fractions[5] = 45;
fractions[6] = 33.56;
// Assigning the value 75.9 to element 5 will overwrite the previous value 45
fractions[5] = 75.9;

To sum all the elements, you would typically use a loop:

double sum = 0;
for(int i = 0; i < Array_Size; i++) {
sum += fractions[i];
}

The variable sum will hold the total of all the elements in the array after the loop completes.

User Nick Zadrozny
by
8.3k points