Question

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

Expert Solution

Want to see the full answer?

Check out a sample Q&A here
Blurred answer
Students who’ve seen this question also like:
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
Not helpful? See similar books
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Advanced Array Concepts. 19RQ
marketing sidebar icon
Want to see this answer and more?
Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*
*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Language: JavaScript (Node.js) Autocomplete Ready O 1 > 'use strict'; 1. Lowercase strings using…

A: There isn't a built-in specific main function in Node.js to mark a program's entry point. However,…

Q: Vectors Write a for loop to print all NUM_VALS elements of vector courseGrades, following each with…

A: Note: As the user given index value is constant and so the value of index could not be changed…

Q: When defining a 2-dimensional array, you MUST: A Indicate the size of all of its dimensions Leave…

A: Answer is D

Q: Please add comments in my code: int maxSubArray(vector& nums) {         int csum=0,maxsum=INT_MIN;…

A: Hi there. Let's move on to the solution in the next step.

Q: After the program completes the array "newValue" should be the reverse of "oldValue". E.g. if the…

A: In this question, we will be given an array, and when the program runs and complete its execution…

Q: Consider the 2D array “list". Each row represent a class say Bangla or English or Math, and the…

A: Step 1:- Program Approach:- 1.Include the header file  2.Declare and initialize the 2D array…

Q: C++ I need to create a 2D array map that can be displayed in the output like a 2D array visually.

A: Click to see the answer

Q: Please add proper comments in the code given below. int maxSubArray(vector& nums) {         int…

A: Add comments in the given functional program in which a C++ function named maxSubArray is given.

Q: When defining a 2-dimensional array, you MUST: A Assign all of its elements in the declaration…

A: A two dimension array is a collection of elements arranged in rows and columns   Note: As per our…

Q: #include using namespace std; int main() { vector v = {1,1,2,3,3,3,4,5,6,6,7}; int 1 = 0; v[1] =…

A: 1st error: 'r' is not declared in the code and it is being used. 2nd error: there is more closing…

Q: int[] array = { 2, 6, 4, 12, 7, 8, 9, 13, 2 }; var orderedFilteredArray = from element in array…

A: Syntax of using a lambda expression to filter even number for integer array is:-…

Q: const cats = ['Leopard', 'Serval', 'Jaguar', 'Tiger', 'Caracal', 'Lion']; use map() and filter()…

A: The program is written using HTML and Javascript. Please check the source code and propper comments…

Q: 1. Loads a vector with at least 60 randomly generated integers in the range of 0 - 49.  2. Create…

A: Answer is given below .

Q: Using only these simpler vector methods Create a vector of at least 10 integers. Cout the vector…

A: Below i have answered:

Q: write the code that Declares a 2 dimensional array to hold a 4x2 matrix of String values.

A: I have given an answer in step 2.

Q: Language: JavaScript (Node.js) • Autocomplete Ready & 1 > 'use strict';... 5. Use array.map to…

A: The map() method creates a new array with the results of calling a function for every array element.…

Q: 2. Creates an array of Triangle type of size 10. Prompts the user to enter the index of the array,…

A: Note: Below is the required program in the java language. Program Approach: Importing necessary…

Q: 1. Declare a reference variable to an array of integer elements. The name of the variable is listl.…

A: Answer: Java Source Code: import java.util.Arrays; public class Main {    public static void…

Q: 11.9 (Largest rows and columns) Write a program that randomly fills in Os and 1s into an n-by-n…

A: Actually, java is a object oriented programming language. It is a platform independent.

Q: A three-dimensional array called watermelon is declared as based on the row-wise manner as below:…

A: The given array is  int watermelon [3][2][2] This means the total number of rows is 3 and number of…

Q: A struct employeeType has been declared with two elements: name and salary. a. Declare an…

A: struct is a data structure used to store the elements of different data types as a collection. These…

Q: def rotate_map (m: list[list[int]], direction: str) -> list[list[int]]: Given a 2D representation of…

A: def rotateRight(matrix):     temp_matrix = []     for column in range(len(matrix)):         temp =…

Q: Create a template class for a Matrix(2d array) and write the following functions in it. 1. Print…

A: Lets see the solution.

Q: C++ You have an array with non-repeating elements. You need the change locations between minumum and…

A: Required:   C++ You have an array with non-repeating elements. You need the change locations between…

Q: map()   Without using the native “Array.prototype.map” method of JavaScript, compose a function…

A: Here, I have to provide solution for the above question.

Q: Band matrices. Write a program BandMatrix.java that takes two integer command-line arguments n and…

A: Program approach: Created class BandMatrix. Create the main method. use command-line argument…

Q: Name initItems Given Modifies A partial array of item structures Returns This function initializes a…

A: Name initItems Given Modifies A partial array of item structures Returns This function initializes a…

Q: Name initItems Given Modifies A partial array of item structures Returns This function initializes a…

A: Given: Name initItems Given Modifies A partial array of item structures Returns This function…

Q: Name initItems Given Modifies A partial array of item structures Returns This function initializes a…

A: Here is the explanation.

Q: Write a JavaSeript function that performs the following: 1. Define Color Array contains any five…

A: - With our restricted guidelines, we are allowed to answer the first question only.

Q: espace std; // The puzzle will always have exactly 20 columns const int numCols = 20; // Searches…

A: Click to see the answer

Q: Write JAVASOCRIPT code to declare an array containing numbers given below and remove the last…

A: Given array of elements  1,8,12,17,19,2,89  Take the array of elements. Find the last element. And…

Q: Arrays Write a for loop to print all elements in courseGrades, following each element with a space…

A: Syntax: for (statement 1; statement 2; statement 3) {  // code block to be executed}

Q: struct remove_from_front_of_vector { // Function takes no parameters, removes the book at the front…

A: Complete Code C++ struct remove_from_front_of_vector{    void operator()(const Book&amp; unused )…

Q: The ArrayList is created using the following syntax: String[] array = {"red", "green", "blue"};…

A: syntax for lambda:- listObject.forEach((tempVariable) -&gt; {       System.out.print(tempVariable+ "…

Q: function getPalindromes(words) { /* This function takes an array of words and returns an array…

A: The solution to some of the functions are given below:

Q: Parameters array - Any JavaScript Array size - A positive integer Number indicating the desired…

A: We are given a Javascript code. As per the requirement, we have to group the array elements into…

Q: struct remove_from_back_of_vector { // Function takes no parameters, removes the book at the back of…

A: EXPLANANTION:  we use empty() function to check vector is empty or not and pop_back() function to…

Q: float **xtable; // pointer to pointer[s] xtable - new float*[yRes]; // a ("column") array to hold…

A: Here is the simplified C++ code for the above given problem statement:

Q: Arrays Write a for loop to print all elements in courseGrades, following each element with a space…

A: ALGORITHM:- 1. Traverse the complete array from front side and print the elements using loop 1. 2.…

Q: In a loop, fill an array for up to 50 even numbers and a set for up to 50 odd numbers. Use the…

A: Since you have asked multiple questions in a single request, as per the policy, we will be answering…

Q: T/F Suffix array can be created in O(nlogn) time.

A: T/F Question. Suffix array can be created in O(nlogn) time.

Q: Store data of car in a array. Car contains model(int), company (String), price(int) and…

A: Program: Program is used to interact with the computer system and solve problems. The main objective…

Q: CLARRAY example shown here is a complete program that shows one way to create your own array class:…

A: The required C++ code is given below: // creates array class#include &lt;iostream&gt;using namespace…

Q: Using only these simpler vector methods Create a vector of at least 10 integers. Cout the vector…

A: 1. create vector with 10 elements  2. run loop from 0 to  size of vector        i. print the element…

Q: rite a program that examines each element of a vector using a for loop. If the element is positive…

A: Here since programming language not mentioned using C++

Q: ncreasing the value of the length property adds more items to an array, but the items have null…

A: Array in JavaScript An array in JavaScript is defined as an object that represents the same type of…

Q: Creates an array of Triangle type of size 10. Prompts the user to enter the index of the array, then…

A: The below given Java program will obey the following rubrics: In the Triangle class, defining the…

Q: Create an associative array that has at least 10 key/element pairs. а. b. Print out the array,…

A: NOTE: Answering only the first 3 subparts as per the guidelines. First, we will create an…

Q: s a one-dimensional array of 10 integers in the static area of the data segment, asks the user to…

A: Below the MIPS program that defines a one-dimensional array of 10 integers in the static area of the…

Knowledge Booster
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • #ifndef lab5ExF_h #define lab5ExF_h typedef struct point { char label[10]; double x ; // x coordinate for point in a Cartesian coordinate system double y; // y coordinate for point in a Cartesian coordinate system double z; // z coordinate for point in a Cartesian coordinate system }Point;   void reverse (Point *a, int n); /* REQUIRES: Elements a[0] ... a[n-2], a[n-1] exists. * PROMISES: places the existing Point objects in array a, in reverse order. * The new a[0] value is the old a[n-1] value, the new a[1] is the * old a[n-2], etc. */   int search(const Point* struct_array, const char* target, int n); /* REQUIRES: Elements struct-array[0] ... struct_array[n-2], struct_array[n-1] * exists. target points to string to be searched for. * PROMISES: returns the index of the element in the array that contains an * instance of point with a matching label. Otherwise, if there is * no point in the array that its label matches the target-label, * it should return -1. * If there are more than…
    Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by a comma (no spaces). Ex: If origList = {4, 5, 10, 12} and offsetAmount = {2, 4, 7, 3}, print: 6,9,17,15, #include <iostream>#include <string.h>using namespace std; int main() {   const int NUM_VALS = 4;   int origList[NUM_VALS];   int offsetAmount[NUM_VALS];   int i;    cin >> origList[0];   cin >> origList[1];   cin >> origList[2];   cin >> origList[3];    cin >> offsetAmount[0];   cin >> offsetAmount[1];   cin >> offsetAmount[2];   cin >> offsetAmount[3];    /* Your code goes here */    cout << endl;    return 0;}
    Vectors Write a for loop to print all NUM_VALS elements of vector courseGrades, following each with a space (including the last). Print forwards, then backwards. End with newline. Ex: If courseGrades = {7, 9, 11, 10}, print:7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.size() - 1 (Notes)Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element vector (vector<int> courseGrades(4)). See "How to Use zyBooks".Also note: If the submitted code tries to access an invalid vector element, such as courseGrades.at(9) for a 4-element vector, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. #include <iostream>#include <vector>using namespace std; int main() {const int NUM_VALS = 4;vector<int> courseGrades(NUM_VALS);int i; for (i = 0;…
  • Parameters array - Any JavaScript Array size - A positive integer Number indicating the desired "chunk" size. Return Value A new Array of Arrays. Each sub-Array has a length equal to size. Remaining elements are gathered into a final sub-Array. Do not mutate the input array Do not use Array.prototype.slice in your implementation.Do not use Array.prototype.shift in your implementation.Do not use Array.prototype.pop in your implementation.Do not use Array.prototype.splice in your implementation. Please fix this JavaScript function so that the when calling the function with the parameters chunk([false, true, false, true], 3); the output is [[false, true, false], [true]] (subarrays)and when the parameters are chunk([undefined, null, 0, false, NaN, ""], 3); the output is [[undefined, null, 0], [false, NaN, ""]] thank you very much!   function chunk(ar, sz) {  var res = [];  var ind = 0;   // itterating through the new length of resulting array  for (var i = 0; i < ar.length / sz; i++)…
    Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1. Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int courseGrades[4]). Also note: If the submitted code tries to access an invalid array element, such as courseGrades[9] for a 4-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. #include <iostream>using namespace std; int main() {   const int NUM_VALS = 4;   int courseGrades[NUM_VALS];   int i;    for (i = 0; i < NUM_VALS; ++i) {      cin >> courseGrades[i];   }    /* Your solution goes…
    Write a function that converts an object into an array, where each element represents a key-value pair in the form of an array. Examples toArray({ a: 1, b: 2 }) ➞ [["a", 1], ["b", 2]] toArray({ shrimp: 15, tots: 12 }) ➞ [["shrimp", 15], ["tots", 12]] toArray({}) ➞ []
  • Correct the following code so that it correctly sets the value of each element of myList to the index of the element. int myList[10];for (int i = 1; i > 10; i++)myList[i] = i;
    c++ student instruction1. SimpleVector Generic Template2. SearchableVector Generic Template3. SimpleVectorInterface Generic Template4. Soccer Class implemented with MyString 5. Implementation of operators.6. Use three files in your implementation.Description of the problem:1. Use the Soccer class described in Gaddis chapter 11 number 6 page 6522. Implement the operators in your code, and make the code modifications discussed in class, to create a one-dimensional array composed of instances of type Soccer and show your results in solving the following problems:to. (Gaddis) Programming Challenger 9. SearchableVectorModification page 1023 Chapter 16b. (Gaddis) Programming Challenger 10. SortableVector ClassTemplate Modification page 1023 Chap16. order with himSelection Sort algorithm p. 474 Chap. 8=============================================================== Soccer Scores class infoWrite a program that stores the following data about a soccer player in a structure: Player’s Name…
    ****************************Instructions***************************** Add a "copy constructor" to your dynamic-array student. Remember, the prototype looks like: Classname(const classname& otherObject); Update your test program to use the copy constructor. e.g., CourseTypeList list2(list1); ********************************************************************* Submit: Updated test program, implementation and header files (.cpp and .h) for CourseListType and CourseType zipped into a single file. //courseTypeList.h #ifndef COURSELISTTYPE_H_INCLUDED#define COURSELISTTYPE_H_INCLUDED #include <string>#include "courseType.h" class courseTypeList { public:void print() const;void addCourse(std::string);courseTypeList(int n);~courseTypeList(); private:int NUM_COURSES;int courseCount;courseType *courses;}; #endif // COURSELISTTYPE_H_INCLUDED =============================================== //courseTypeList.cpp #include <iostream>#include <string>#include…
    • SEE MORE QUESTIONS
    Recommended textbooks for you
  • EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
  • EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT