Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ nothing beyond arrays Double any element\'s value that is less than minVal.

ID: 3576495 • Letter: C

Question

c++ nothing beyond arrays

Double any element's value that is less than minVal. Ex: If minVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

int main() {

const int NUM_POINTS = 4;

int dataPoints[NUM_POINTS];

int minVal = 0;

int i = 0;

dataPoints[0] = 2;

dataPoints[1] = 12;

dataPoints[2] = 9;

dataPoints[3] = 20;

minVal = 10;

/* Your solution goes here */

for (i = 0; i < NUM_POINTS; ++i) {

cout << dataPoints[i] << " " ;

}

cout << endl;

return 0;

}

Explanation / Answer

#include <iostream>
using namespace std;
int main() {
const int NUM_POINTS = 4;
int dataPoints[NUM_POINTS];
int minVal = 0;
int i = 0;
dataPoints[0] = 2;
dataPoints[1] = 12;
dataPoints[2] = 9;
dataPoints[3] = 20;
minVal = 10;
/* Your solution goes here */
for (i = 0; i < NUM_POINTS; ++i) {
   if(dataPoints[i]<minVal)
{
   dataPoints[i]*=2;
}
}

for (i = 0; i < NUM_POINTS; ++i) {
cout << dataPoints[i] << " " ;
}
cout << endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote