# Add each element in origList with the corresponding value in offsetAmount. 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 <iostream>#include <vector>using namespace std;int main() {const int NUM_VALS = 4;vector<int> origList(NUM_VALS);vector<int> offsetAmount(NUM_VALS);unsigned int i;for (i = 0; i < origList.size(); ++i) {cin >> origList.at(i);}for (i = 0; i < offsetAmount.size(); ++i) {cin >> offsetAmount.at(i);}cout << endl;return 0;}Please help me with this problem using c++.

Question
191 views

Add each element in origList with the corresponding value in offsetAmount. 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 <iostream>
#include <vector>
using namespace std;

int main() {
const int NUM_VALS = 4;
vector<int> origList(NUM_VALS);
vector<int> offsetAmount(NUM_VALS);
unsigned int i;

for (i = 0; i < origList.size(); ++i) {
cin >> origList.at(i);
}

for (i = 0; i < offsetAmount.size(); ++i) {
cin >> offsetAmount.at(i);
}

cout << endl;

return 0;
}

check_circle

Step 1

Completing the given C++ program so, that it can follow the given rubrics:

• Two vector, origList and offsetAmount declaration are already given in the program:

vector<int> origList(NUM_VALS);
vector<int> offsetAmount(NUM_VALS);

• Creating the third vector for storing the sum of both these vectors:

vector<int> sum(NUM_VALS);

• Displaying message to user to enter the elements of origList.
• Taking input of first vector element.
• Displaying message to user to enter the elements of offsetAmount.
• Taking input of second vector element.
• Using a for loop to calculate the sum of both the given vector and storing their sum in the new vector:

sum[i]=origList.at(i)+offsetAmount.at(i);

• Displaying both the origList and offsetAmount elements to user.
• And displaying the sum of both the vectors, origList and offsetAmount stored in sum[i];
Step 2

Program code:

#include <iostream>

#include <vector>

using namespace std;

//main method

int main() {

const int NUM_VALS = 4;

//declaring vector

vector<int> origList(NUM_VALS);

vector<int> offsetAmount(NUM_VALS);

//defining a vector with name sum

vector<int> sum(NUM_VALS);

unsigned int i;

//displaying message to user to enter elements of origList

cout<<"enter origList elements: ";

for (i = 0; i < origList.size(); ++i) {

//taking input of origList from user

cin >> origList.at(i);

}

//displaying message to user to enter elements of offsetAmount

cout<<"enter offsetAmount elements: ";

//for loop

for (i = 0; i < offsetAmount.size(); ++i) {

//taking input of offsetAmount from user

cin >> offsetAmount.at(i);

}

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

//calculating the sum of both the vectors

sum[i]=origList.at(i)+offsetAmount.at(i);

}

//displaying the entered...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Computer Science 