Engineering

Computer ScienceQ&A LibraryAdd 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

Asked Nov 3, 2019

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;

}

Please help me with this problem using c++.

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...

Tagged in

Find answers to questions asked by student like you

Show more Q&A

Q: Twin primes are two primes that differ by 2 (e.g., 3 and 5, 101 and 103). Write a c++ program that o...

A: Twin primes are two primes that differ by 2 (e.g., 3 and 5, 101 and 103).Comment are the not readabl...

Q: EXPLAIN ALL STEPS: Determine the output of the following Pep/9 machine language program if the input...

A: Address Instruction(in hex)0000 D1FC15Convert the instructions into binary form-D=11011=00...

Q: WHAT IS A DOUBLE SPEND PROBLEM OF DITIAL CASH TRANSACTION? HOW THE DOUBLE SPEND PROBLEM OF DIGITAL C...

A: Double spending: It means spending the same amount of money twice. Here's a good example to explain ...

Q: What are the mantissa and exponent values if 6.75 is represented in 8 bit binary floating point repr...

A: Calculating the mantissa and exponent of 6.75 with 8-bit binary floating-point representation.Firstl...

Q: I am having trouble writing a python program that opens a file that contains baby names. One file fo...

A: To run this code, make all the files Boys.txt, Girls.txt and .py files in same folder.input() is use...

Q: A network topology specifies how computers, printers, and other devices are connected over a network...

A: The adjacency matrix shows the neighbor it is connected to, so for ring topology is all nodes are co...

Q: I need help with Excel in my Intro to info systems. The thing i don't know how to do is this: It kee...

A: To solve this question user must know the definition of absolute reference:Absolute reference: An ab...

Q: Form boolean equations in POS and SOP forms from the truth table attached (PLEASE EXPLAIN ALL STEPS)...

A: The circuit diagrams that correspond to the following Boolean equations drawed using an online tool...

Q: Siobhan’s laptop has 8GB of RAM. Her operating system takes up 2GB, and her application programs use...

A: Random Access Memory (RAM):RAM is a memory device used for storage purposes.The data stored in the m...