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

Given an array A of N integers, write a function addc(A, N, c) that adds c to ev

ID: 3723582 • Letter: G

Question

Given an array A of N integers, write a function addc(A, N, c) that adds c to every element of A. This is a void function, i.e. the function does not return a value but instead simply ends in return. The main function is written for you; your job is to write the addc function. Start by reviewing the code for main.cpp which is visible in the editor pane note that this code is read-only (you cannot modify it). Notice that the main0 program inputs a sequence of integers from the keyboard, stores those values into an array, inputs another value c, and then calls the function addc to update the array. Above the editor pane you'll see the text Current file: main.cpp", with a little drop-down arrow to the right. Click the drop-down and select functions.cpp. Then, to avoid a bug in some web browsers, please immediately click the link "Load default template... You only need to do this once, the first time you view the file. Implement the function. To test your work in Develop mode, supply a sequence of integers ending in 0, followed by an additional integer c. For example, the following input denotes the sequence 88, 92,6, to which the value 12 will be added: 92 The output from the program is the original sequence of integers, followed by the updated sequence: 88,92,6 100,104,18 When you are ready to submit for testing, switch to Submit mode and submit for grading. You have unlimited submissions. LAB ACTIVITY 6.22.1: HW11-02: adding a constant to every array element 0/100 File is marked as read only Current file.main.cpp 1 main.cpp 3 #include «iostream» 4 #include 5 #include 7 using namespace std; 9 void addc int A int N, int c); 10 void output(int AL, int N); 12 int main) 13 14 int value; 15 t A1000] / at most 1,000 integers: 16 int N=8 17 nt c 18

Explanation / Answer

#include <iostream>

using namespace std;

void addc(int A[], int N, int c);
void output(int A[], int N);
int main() {
int value;
int A[1000];
int N = 0;
int c;
cout<<"Enter a value (0 to quit): "<<endl;
cin >> value;
while (value!=0) {
A[N++]=value;
cout<<"Enter a value (0 to quit): "<<endl;
cin >> value;
}
cout<<"Enter the value to be added: "<<endl;
cin >> c;
addc(A, N, c);
output(A, N);
return 0;
}
void addc(int A[], int N, int c) {
int i;
for(i=0;i<N;i++) {
if(i+1==N) {
cout<<A[i];
} else {
cout<<A[i]<<",";
}
A[i]=A[i]+c;
}
cout<<endl;
}
void output(int A[], int N) {
int i;
for(i=0;i<N;i++) {
if(i+1==N) {
cout<<A[i];
} else {
cout<<A[i]<<",";
}
}
cout<<endl;
}

Output:

Enter a value (0 to quit): 88
Enter a value (0 to quit): 92
Enter a value (0 to quit): 6
Enter a value (0 to quit): 0
Enter the value to be added: 12
88,92,6
100,104,18

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