
Write a for loop to print all NUM_VALS elements of
7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.size() - 1 (Notes)
C++
without using std::
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 has errors, 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; i < courseGrades.size(); ++i) {
cin >> courseGrades.at(i);
}
if (courseGrades.size()
for (i = 0; i < courseGrades.size() -1; --i) {
cin >> courseGrades.at(i);
cout << NUM_VALS << " ";
}
cout << endl;
return 0;
}
It's a mess and it only produces 4 in the output

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images

this C++ code is pre-existing and cannot be changed or modified. for it to work, the program has to use this information.
#include <iostream>
#include <
using namespace std;
int main() {
const int NUM_VALS = 4;
vector<int> courseGrades(NUM_VALS);
int i;
for (i = 0; i < courseGrades.size(); ++i) {
cin >> courseGrades.at(i);
}
//enter code here//
return 0;
}
this C++ code is pre-existing and cannot be changed or modified. for it to work, the program has to use this information.
#include <iostream>
#include <
using namespace std;
int main() {
const int NUM_VALS = 4;
vector<int> courseGrades(NUM_VALS);
int i;
for (i = 0; i < courseGrades.size(); ++i) {
cin >> courseGrades.at(i);
}
//enter code here//
return 0;
}
- t. Given a string as a parameter to the function, return a square grid filled with all the characters of the string from left to right. Fill empty spaces in the grid with '_'. Sample Input: stringtogrid Output: {{s, t, r, i}, {n, g, t, o}, {g, r, i, d}, {_, _, _, _}} Complete the function: vector<vector<int> formGrid(string s){}arrow_forwardUsing C++ Using only these simpler vector methods Create a vector of at least 10 integers. Cout the vector with spaces in between the integers. Cout the vector backward. Using loops that traverse the elements, create a new vector with the elements arranged from high to low. Cout the new vector. Do not use iterators for this exercise, or any other advanced methods--only the ones listed below. Hint: Use multiple vectors, including the copying of vectors. vector<int> grades1 = {45, 67, 88, 45, 23}; vector<int> grades2 = grades1; May Only Use These Vector Methods: size() // Returns the number of elements empty() // Returns a boolean True if the vector is empty push_back(element) // Adds an element to the back of the vector pop_back() // Removes the element at the back of the vector front() // Returns the element at the front of the vector back()…arrow_forwardnumStudents is read from input as the number of input values in the vector that follow. Use two for loops to output all numStudents elements of vector walkingLogs that are: even integers • odd integers ● For both loops, follow each element with a space, including the last element, and end with a newline. Ex: If the input is 8 11 30 70 39 69 29 138 162, then the output is: 30 70 138 162 11 39 69 29 3 using namespace std; 4 5 int main() { 6 7 8 9 10 11 12 13 14 15 16 17 18 19} int numStudents; int i; cin >> numStudents; vector walkingLogs (numStudents); for (i = 0; i > walkingLogs.at(i); } * Your code goes here */ return 0; ►arrow_forward
- C++arrow_forwardComplete the following function that counts the even numbers in a 2D vector of integers. int count_evens(const std::vector<std::vector<int>>& v) { // Add your code... } Please add output screenshot!arrow_forwardUse iterators to print each element of v separted by spaces. #include <iostream>#include <vector> using namespace std; int main(){vector<int> v = {1, 3, 5}; (.....) }arrow_forward
- Integers are read from input and stored into a vector until 0 is read. If the vector's last element is odd, output the odd elements in the vector. Otherwise, output the even elements in the vector. End each number with a newline. Ex: If the input is -9 12 -6 1 0, the vector's last element is 1. Thus, the output is: -9 1 Note: (x % 2 != 0) returns true if x is odd. int value; int i; bool isodd; 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 } cin >> value; while (value != 0) { } for (i = 0; i > value; Check return 0; 1 Next level 2 X 1: Compare output 3 4 For input -9 12 -6 1 0, the vector elements are -9, 12, -6, and 1. The last element, 1, is odd. The odd elements in the vector, -9 and 1, are output, each on a new line. Not all tests passed. 2 V 3arrow_forwardIntegers are read from input and stored into a vector until 0 is read. If the vector's last element is odd, output the odd elements in the vector. Otherwise, output the even elements in the vector. End each number with a newline. Ex: If the input is -9 12 -6 1 0, the vector's last element is 1. Thus, the output is: -9 1 Note: (x % 2!= 0) returns true if x is odd. 4 5 int main() { 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} vector vect1; int value; int i; bool isodd; cin >> value; while (value != 0) { vect1.push_back(value); cin >> value; } V* Your code goes here */ return 0; 2 3arrow_forwardC++arrow_forward
- import numpy as np import torch import matplotlib.pyplot as plt Quiz Preparation Question 1. Write a function that generates a random tensor of n x n (n is the input). The output is the mean of the tensor. = 2, 4, 8, 16, ... 1024 and generate a vector 2. Write a code (for loop) that call that calls the function above with n = M(n). Plot the vector as a function of the log of n. 3. Given an n x m array write a code that replaces every element that is larger than 0.5 with 0.5. 4. The second derivative of a function can be approximated by the finite difference 1 ƒ"(x₂) = 73 (ƒ(£;+1) — 2ƒ(x;) + f(x;-1)) Given a vector f with values f = [f(xo),..., f(n) write a code that computes the approximation to f"(x) 5. The power method is a method to compute the largest eigenvalue of a matrix. Your google search is using this method every time you perform a google search. The method consists of the iteration Vj+1 = Av; || Avi|| where v; is a vector with chosen as a random vector, and A is the matrix…arrow_forwardTradng SelCLOon Write the state of the elements of the vector below after each of the first 3 passes of the outermost loop of the selection sort algorithrm // index 0 1 2 3 4 5 6 7 Vector numbers = {29, 17, 3, 94, 46, 8, -4, 12}; selectionSort(numbers); For example, if the vector was {(43125), you would write: {4 3 1 2 5} {1 3 4 2 5} (1 2 4 3 5} {1 2 3 4 5} Thought: How many vectors would I need here if I were to implement this in code? Write your answer here. hparrow_forwardProduce the following program.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





