Step 4: Implement/call a function to change the value of the third component in
ID: 3556222 • Letter: S
Question
Step 4: Implement/call a function to change the value of the third component in the array to 15.9
Step 5: Implement/call a function to print out all of the elements in the array on screen.
Step 6: Implement/call a function to calculate the sum of all the components and print the sum on screen.
Step 7: Implement/call a function to change all values under 5.3 to 8.8 using a loop and an if statement.
Step 8: Call the function to print out all of the elements in the array on screen.
Step 9: Implement/call a function that allows the user to change each of the values in the array. The function must prompt the user to "Enter a value:" each time.
Step 10: Call the function to print out all of the elements in the array on screen.
#include<iostream>
using namespace std;
int main()
{
int rows;
double qArray[10] = {3.7, 12.3, 4.5, 10.6, 2.3, 5.4, 9.8, 15.2, 7.7, 19.8};
double sum = 0;
qArray[2] = 15.9;
for (int rows = 0; rows < 10; rows++)
{
cout << qArray[10] << endl;
}
cout << endl;
cout << endl;
for (int rows = 0; rows < 10; rows++)
{
sum = sum + qArray[10];
}
system("pause");
return 0;
}
Explanation / Answer
I have copied your code and made changes wherever necessary and marked each step..
#include<iostream>
using namespace std;
void printArray(double q[])
{
for (int rows = 0; rows < 10; rows++)
{
cout << q[rows] << endl;
}
cout << endl;
cout << endl;
}
int main()
{
int rows;
double qArray[10] = {3.7, 12.3, 4.5, 10.6, 2.3, 5.4, 9.8, 15.2, 7.7, 19.8};
double sum = 0;
//Step 4
qArray[2] = 15.9;
//step 5
for (int rows = 0; rows < 10; rows++)
{
cout << qArray[rows] << endl;
}
cout << endl;
cout << endl;
//step 6
for (int rows = 0; rows < 10; rows++)
{
sum = sum + qArray[rows];
}
cout<<sum<<endl<<endl<<endl;
//step 7
for (int rows = 0; rows < 10; rows++)
{
if(qArray[rows]<5.3)
{
qArray[rows]=8.8;
}
}
//step 8
printArray(qArray);
//step 9
for (int rows = 0; rows < 10; rows++)
{
cout <<"Enter a value at row "<<rows<<": ";
cin>>qArray[rows];
}
//step 10
printArray(qArray);
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.