Question
in C++ 1) Double any element's value that is less than minVal. Ex: IfminVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4,
in C++
1) Double any element's value that is less than minVal. Ex: IfminVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18,20} Ex: Testing minVal = 4 and dataPoints = {1,2, 3, 4, 5, -3} becomes {2 4 6 4 5 -6}
#include
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;
// student code here
for (i = 0; i < NUM_POINTS; ++i) {
cout << dataPoints[i] << " ";
}
cout << endl;
return 0;
}
2) Write a loop that subtracts 1 from each element inlowerScores. If the element was already 0 or negative, assign 0 tothe 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;
}
3)Add each element in origList with the corresponding value inoffsetAmount. Print each sum followed by a space. Ex: If origList ={40, 50, 60, 70} and offsetAmount = {5, 7, 3, 0}, print:
45 57 63 70
#include
using namespace std;
int main() {
const int NUM_VALS = 4;
int origList[NUM_VALS];
int offsetAmount[NUM_VALS];
int i = 0;
origList[0] = 40;
origList[1] = 50;
origList[2] = 60;
origList[3] = 70;
offsetAmount[0] = 5;
offsetAmount[1] = 7;
offsetAmount[2] = 3;
offsetAmount[3] = 0;
/* Your solution goes here */
cout << endl;
return 0;
}
Step by Step Solution
3.46 Rating (169 Votes )
There are 3 Steps involved in it
Step: 1
Question 1 Program Code Screenshot Program Code include using namespace std int main con...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started