Question: Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex:

Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}.

#include using namespace std;

int main() { const int SCORES_SIZE = 4; int lowerScores[SCORES_SIZE]; int i = 0;

lowerScores[0] = 5; lowerScores[1] = 0; lowerScores[2] = 2; lowerScores[3] = -3;

/* Your solution goes here */

for (i = 0; i < SCORES_SIZE; ++i) { cout << lowerScores[i] << " "; } cout << endl;

return 0; }

Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}. Note: These activities may test code with different test values. This activity will perform two tests, the first with a 4-element array (newScores = {10, 20, 30, 40}), the second with a 1-element array (newScores = {199}). See How to Use zyBooks. Also note: If the submitted code tries to access an invalid array element, such as newScores[9] for a 4-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message.

#include using namespace std;

int main() { const int SCORES_SIZE = 4; int oldScores[SCORES_SIZE]; int newScores[SCORES_SIZE]; int i = 0;

oldScores[0] = 10; oldScores[1] = 20; oldScores[2] = 30; oldScores[3] = 40;

/* Your solution goes here */

for (i = 0; i < SCORES_SIZE; ++i) { cout << newScores[i] << " "; } cout << endl;

return 0; }

Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex:

Initial scores: 10, 20, 30, 40 Scores after the loop: 30, 50, 70, 40 

The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.

#include using namespace std;

int main() { const int SCORES_SIZE = 4; int bonusScores[SCORES_SIZE]; int i = 0;

bonusScores[0] = 10; bonusScores[1] = 20; bonusScores[2] = 30; bonusScores[3] = 40;

/* Your solution goes here */

for (i = 0; i < SCORES_SIZE; ++i) { cout << bonusScores[i] << " "; } cout << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!